Example #1
0
 /**
  * Creates a complete OWLSTree for a composite process instance
  *
  * @param inst
  * @return
  */
 private OWLSTree createTree(OWLIndividual inst, GraphUpdateManager mgr) {
   OWLSTreeNode root = new RootNode(inst, okb);
   OWLSTreeNode children = getCompositionTreeNodes(inst);
   if (children != null) root.add(children);
   DefaultTreeModel treemodel = new DefaultTreeModel(root, true);
   OWLSTree tree = new OWLSTree(okb, treemodel, mgr);
   // tree.setModel(treemodel);
   return tree;
 }
Example #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * com.sri.owlseditor.cmp.tree.OWLSTreeNode#updateKBAfterInsert(com.sri.
   * owlseditor.cmp.tree.OWLSTreeNode)
   */
  public void updateKBAfterInsert(OWLSTreeNode newnode) {
    int index = getIndex(newnode);

    if (index == 0) {
      // need to update composedOf property
      updateCompositeProcess(newnode.getInstance());
      if (getChildCount() > 1) {
        // previous index 0 node must be put as an "extra construct"
        addMapping(((OWLSTreeNode) getChildAt(1)).getInstance());
      }
    } else {
      // this is not the index 0 node, so put it as an "extra construct"
      addMapping(newnode.getInstance());
    }
  }
Example #3
0
 /*
  * (non-Javadoc)
  *
  * @see
  * com.sri.owlseditor.cmp.tree.OWLSTreeNode#updateKBAfterMove(com.sri.owlseditor
  * .cmp.tree.OWLSTreeNode)
  */
 public void updateKBAfterMove(OWLSTreeNode node) {
   int index = getIndex(node);
   if (index == 0) {
     if (getChildCount() > 1) {
       // need to put index 1 node as index 0 node
       OWLSTreeNode newfirst = (OWLSTreeNode) getChildAt(1);
       removeMapping(newfirst.getInstance());
       updateCompositeProcess(newfirst.getInstance());
     } else {
       // remove the composedOf property since we're deleting the last
       // construct
       updateCompositeProcess(null);
     }
   } else {
     removeMapping(node.getInstance());
   }
 }
Example #4
0
  /**
   * Returns the OWLSTree associated with a given composite process. If there is no tree, one will
   * be created (that is the whole beauty of this class).
   *
   * @param process
   * @param listener
   * @return
   */
  public OWLSTree getTree(OWLIndividual process, GraphUpdateManager mgr) {
    OWLSTree tree = (OWLSTree) process2tree.get(process);
    if (tree == null) {
      /*
       * We have no model for this process, so we create one and add a
       * mapping for it
       */
      // System.out.println("OWLSTreeMapper.getTree, creating tree for " +
      // process.getName());

      tree = createTree(process, mgr);
      tree.expandAll(); // Newly created trees are always fully expanded.
      DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
      // model.addTreeModelListener(tree);
      addMapping(process, tree);
    } else {
      Vector extraConstructs = (Vector) okb.getClientInformation(generateKey(process));
      if (extraConstructs != null) {
        // There are extra constructs stored in the project file, so we
        // have
        // to add those to the model

        System.out.println("Process " + process + " has extra constructs.");

        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        OWLSTreeNode root = (OWLSTreeNode) model.getRoot();
        for (Enumeration e = extraConstructs.elements(); e.hasMoreElements(); ) {
          OWLIndividual construct = (OWLIndividual) e.nextElement();
          OWLSTreeNodeInfo ni = new OWLSTreeNodeInfo(construct, okb);
          OWLSTreeNode newnode = OWLSTreeNodeFactory.createTreeNode(ni);
          System.out.println("Looking at " + newnode);
          model.insertNodeInto(newnode, root, root.getChildCount());
        }
      }
    }
    tree.setSelectedCompositeProcess(process);
    return tree;
  }
Example #5
0
 /** Updates the KB after adding a node. */
 public void updateKBAfterInsert(OWLSTreeNode newnode) {
   /*
    * Now we need to put the Instance in the correct place in its
    * ControlConstructBag
    */
   // OWLIndividual list = getComponents();
   int newindex = getIndex(newnode);
   OWLSList olist = new OWLSList(getInstance(), getOWLModel());
   olist.insertAtIndex(newnode.getInstance(), newindex);
   // OWLSList olist = new OWLSList(list, type, getOWLModel());
   // OWLIndividual newcell = olist.insertAtIndex(newnode.getInstance(),
   // newindex);
   /*
    * If we are inserting at the beginning of the bag/list, we need to
    * update the control construct.
    */
   // if (newindex == 0){
   // getInstance().setPropertyValue(components, newcell);
   // }
 }
Example #6
0
  /*
   * (non-Javadoc)
   *
   * @see
   * com.sri.owlseditor.cmp.tree.OWLSTreeNode#updateKBAfterDelete(com.sri.
   * owlseditor.cmp.tree.OWLSTreeNode)
   */
  public void updateKBAfterDelete(OWLSTreeNode node) {
    int index = getIndex(node);
    if (index == 0) {
      if (getChildCount() > 1) {
        // need to put index 1 node as index 0 node
        OWLSTreeNode newfirst = (OWLSTreeNode) getChildAt(1);
        removeMapping(newfirst.getInstance());
        updateCompositeProcess(newfirst.getInstance());
      } else {
        // remove the composedOf property since we're deleting the last
        // construct
        updateCompositeProcess(null);
      }
    } else {
      removeMapping(node.getInstance());
    }
    // getOWLModel().deleteInstance(node.getInstance());

    System.out.println("RootNode.updateKBAfterDelete: deleting " + node.getInstance().getName());

    node.getInstance().delete();
  }
Example #7
0
  /**
   * Creates the tree from a ControlConstruct. It returns the root node created even though the
   * caller already has it, since the method is recursive, and this is needed internally. This
   * method is only called when the user switches to a different composite process, to recreate the
   * whole tree.
   *
   * <p>Note: This method is not used to create RootNode instances - those are created directly
   * (i.e. using new RootNode()).
   *
   * <p>We also generate Vectors of unconditional predecessor Performs, and associate those with the
   * Perform constructs using the PerformTreeMapper class. See that class for more info.
   */
  private OWLSTreeNode createTree(OWLSTreeNodeInfo ni, OWLIndividual cp, Set preds) {
    OWLIndividual inst = ni.getInstance();
    if (inst == null) {
      System.out.println("ERROR! OWLSTreeMapper.createTree(): inst is null!");
      return null;
    }

    OWLSTreeNode newnode = OWLSTreeNodeFactory.createTreeNode(ni);
    // System.out.println("Building tree for " + newnode.toString());

    if (newnode instanceof ProduceNode) {
      // Store the mapping from produce to composite process in the
      // PerformTreeMapper. This will allow us to generate the Produce's
      // parents, which we need for the ProducedBindingWidget.
      OWLIndividual produce = newnode.getInstance();
      PerformTreeMapper mapper = PerformTreeMapper.getInstance();
      mapper.put(produce, cp);
      mapper.addPredecessors(produce, preds);
    } else if (newnode instanceof PerformNode) {
      // Store the mapping from perform to composite process in the
      // PerformTreeMapper. This will allow us to generate the Performs's
      // parents, which we need for the HasDataFromWidget.
      OWLIndividual perform = newnode.getInstance();
      PerformTreeMapper mapper = PerformTreeMapper.getInstance();
      mapper.put(perform, cp);
      mapper.addPredecessors(perform, preds);
      preds.add(perform);
      // mapper.printAll();
    } else if (newnode instanceof SequenceNode) {
      OWLIndividual components = getComponents(inst);
      // OWLSList clist = new OWLSList(components, OWLSList.CC_LIST, okb);
      OWLSList clist = new OWLSList(inst, okb);
      while (clist.hasNext()) {
        OWLIndividual i = (OWLIndividual) clist.next();
        if (i == null) System.out.println("instance in list is null!");
        OWLSTreeNodeInfo newni = new OWLSTreeNodeInfo(i, okb);
        newnode.add(createTree(newni, cp, preds));
      }
    } else if (newnode instanceof SplitNode || newnode instanceof ChoiceNode) {
      OWLIndividual components = getComponents(inst);
      // OWLSList clist = new OWLSList(components, OWLSList.CC_BAG, okb);
      OWLSList clist = new OWLSList(inst, okb);
      while (clist.hasNext()) {
        HashSet mypreds = new HashSet(preds);
        OWLIndividual i = (OWLIndividual) clist.next();
        OWLSTreeNodeInfo newni = new OWLSTreeNodeInfo(i, okb);
        newnode.add(createTree(newni, cp, mypreds));
      }
    } else if (newnode instanceof SplitJoinNode || newnode instanceof AnyOrderNode) {
      OWLIndividual components = getComponents(inst);
      // OWLSList clist = new OWLSList(components, OWLSList.CC_BAG, okb);
      OWLSList clist = new OWLSList(inst, okb);
      HashSet predsIn = new HashSet(preds);
      while (clist.hasNext()) {
        OWLIndividual i = (OWLIndividual) clist.next();
        OWLSTreeNodeInfo newni = new OWLSTreeNodeInfo(i, okb);
        HashSet mypreds = new HashSet(predsIn);
        newnode.add(createTree(newni, cp, mypreds));
        preds.addAll(mypreds);
      }
    }
    // We put the then-node first and the else-node second as a convention
    // This may need to be handled better (marking the nodes somehow).
    else if (newnode instanceof IfThenElseNode) {
      OWLIndividual thenc = (OWLIndividual) OWLUtils.getNamedSlotValue(inst, "process:then", okb);
      OWLSTreeNodeInfo thenni = new OWLSTreeNodeInfo(thenc, okb);
      HashSet mypreds = new HashSet(preds);
      newnode.add(createTree(thenni, cp, mypreds));
      OWLIndividual elsec = (OWLIndividual) OWLUtils.getNamedSlotValue(inst, "process:else", okb);
      OWLSTreeNodeInfo elseni = new OWLSTreeNodeInfo(elsec, okb);
      if (elsec != null) {
        mypreds = new HashSet(preds);
        newnode.add(createTree(elseni, cp, mypreds));
      }
    } else if (newnode instanceof RepeatWhileNode) {
      OWLIndividual whileProcess =
          (OWLIndividual) OWLUtils.getNamedSlotValue(inst, "process:whileProcess", okb);
      OWLSTreeNodeInfo newni = new OWLSTreeNodeInfo(whileProcess, okb);
      HashSet mypreds = new HashSet(preds);
      newnode.add(createTree(newni, cp, mypreds));
    } else if (newnode instanceof RepeatUntilNode) {
      OWLIndividual untilProcess =
          (OWLIndividual) OWLUtils.getNamedSlotValue(inst, "process:untilProcess", okb);
      OWLSTreeNodeInfo newni = new OWLSTreeNodeInfo(untilProcess, okb);
      newnode.add(createTree(newni, cp, preds));
    } else {
      System.out.println("Unsupported control construct");
      return null;
    }
    return newnode;
  }