示例#1
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;
  }
示例#2
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;
  }