Package org.apache.oodt.cas.workflow.gui.model

Examples of org.apache.oodt.cas.workflow.gui.model.ModelGraph


  public static ModelGraph removeNode(ModelGraph graph, ModelNode node) {
    Stack<ModelGraph> stack = new Stack<ModelGraph>();
    stack.add(graph);
    while (!stack.empty()) {
      ModelGraph curGraph = stack.pop();
      if (curGraph.getModel().equals(node)) {
        curGraph.setParent(null);
        return curGraph;
      } else {
        stack.addAll(curGraph.getChildren());
        if (curGraph.getPreConditions() != null)
          stack.add(curGraph.getPreConditions());
        if (curGraph.getPostConditions() != null)
          stack.add(curGraph.getPostConditions());
      }
    }
    return null;
  }
View Full Code Here


    Vector<Line> lines = new Vector<Line>();
    if (graph.getChildren().size() > 0) {
      Stack<ModelGraph> stack = new Stack<ModelGraph>();
      stack.add(graph);
      while (!stack.empty()) {
        ModelGraph curGraph = stack.pop();
        if (curGraph.getModel().getExecutionType().equals("sequential")) {
          for (int i = 0; i < curGraph.getChildren().size() - 1; i++)
            lines.add(new Line(curGraph.getChildren().get(i).getModel(),
                curGraph.getChildren().get(i + 1).getModel()));
        }
        stack.addAll(curGraph.getChildren());
      }
    }
    return lines;
  }
View Full Code Here

    Vector<Line> lines = new Vector<Line>();
    if (graph.getChildren().size() > 0) {
      Stack<ModelGraph> graphs = new Stack<ModelGraph>();
      graphs.add(graph);
      while (!graphs.empty()) {
        ModelGraph curGraph = graphs.pop();
        if (curGraph.getModel().isParentType()) {

          if (curGraph.getChildren().size() == 0)
            curGraph.addChild(new ModelGraph(createDummyNode()));

          List<Line> relaventLines = getRelaventLines(lines, curGraph
              .getModel().getId());
          for (Line relaventLine : relaventLines) {
            int index = lines.indexOf(relaventLine);
            if (curGraph.getModel().getExecutionType().toLowerCase()
                .equals("sequential")) {
              lines.remove(index);
              if (curGraph.getChildren().size() > 0) {
                if (relaventLine.getFromModel().equals(curGraph.getModel()))
                  lines.add(new Line(curGraph.getChildren()
                      .get(curGraph.getChildren().size() - 1).getModel(),
                      relaventLine.getToModel()));
                else
                  lines.add(new Line(relaventLine.getFromModel(), curGraph
                      .getChildren().get(0).getModel()));
              }
            } else if (curGraph.getModel().getExecutionType().toLowerCase()
                .equals("parallel")) {
              lines.remove(index);
              if (relaventLine.getFromModel().equals(curGraph.getModel()))
                for (ModelGraph child : curGraph.getChildren())
                  lines.add(new Line(child.getModel(), relaventLine
                      .getToModel()));
              else
                for (ModelGraph child : curGraph.getChildren())
                  lines.add(new Line(relaventLine.getFromModel(), child
                      .getModel()));
            }
          }

          if (curGraph.getModel().getExecutionType().toLowerCase()
              .equals("sequential")) {
            for (int i = 0; i < curGraph.getChildren().size(); i++) {
              if (i == curGraph.getChildren().size() - 1)
                lines.add(new Line(curGraph.getChildren().get(i).getModel(),
                    null));
              else
                lines.add(new Line(curGraph.getChildren().get(i).getModel(),
                    curGraph.getChildren().get(i + 1).getModel()));
            }
          } else if (curGraph.getModel().getExecutionType().toLowerCase()
              .equals("parallel")) {
            for (int i = 0; i < curGraph.getChildren().size(); i++)
              lines
                  .add(new Line(curGraph.getChildren().get(i).getModel(), null));
          }
          graphs.addAll(curGraph.getChildren());
        }
      }
    } else {
      lines.add(new Line(graph.getModel(), null));
    }
View Full Code Here

                      .getUserObject()).keySet().iterator().next()
                      + "/"
                      + group;
              }
            }
            ModelGraph graph = (ModelGraph) metNode.getUserObject();
            state.setSelected(graph);
            state.setCurrentMetGroup(group);
            DefaultTreeView.this.notifyListeners();
          } else {
            state.setSelected(null);
View Full Code Here

      public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals(VIEW_CONDITION_MAP)) {
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
              .getSelectionPath().getLastPathComponent();
          ModelGraph graphToFocus = null;
          if (Boolean.parseBoolean(state
              .getFirstPropertyValue(EXPAND_PRECONDITIONS))
              || Boolean.parseBoolean(state
                  .getFirstPropertyValue(EXPAND_POSTCONDITIONS))) {
            // if (node.getUserObject() instanceof String &&
            // (node.getUserObject().equals("pre-conditions") ||
            // node.getUserObject().equals("post-conditions"))) {
            ModelGraph graph = state.getSelected();
            if (Boolean.parseBoolean(state
                .getFirstPropertyValue(EXPAND_PRECONDITIONS)))
              graphToFocus = graph.getPreConditions();
            else
              graphToFocus = graph.getPostConditions();
          } else if (node.getUserObject() instanceof ModelGraph) {
            graphToFocus = (ModelGraph) node.getUserObject();
          }
          DefaultTreeView.this.notifyListeners(new ViewChange.NEW_VIEW(
              graphToFocus, DefaultTreeView.this));
        }
      }

    });

    final String ORDER_SUB_POP_MENU_NAME = "Order";
    final String TO_FRONT_ITEM_NAME = "Move To Front";
    final String TO_BACK_ITEM_NAME = "Move To Back";
    final String FORWARD_ITEM_NAME = "Move Forward";
    final String BACKWARDS_ITEM_NAME = "Move Backwards";
    actionsMenu.add(orderSubMenu = new PopupMenu(ORDER_SUB_POP_MENU_NAME));
    orderSubMenu.add(new MenuItem(TO_FRONT_ITEM_NAME));
    orderSubMenu.add(new MenuItem(TO_BACK_ITEM_NAME));
    orderSubMenu.add(new MenuItem(FORWARD_ITEM_NAME));
    orderSubMenu.add(new MenuItem(BACKWARDS_ITEM_NAME));
    orderSubMenu.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        ModelGraph graph = state.getSelected();
        ModelGraph parent = graph.getParent();
        if (e.getActionCommand().equals(TO_FRONT_ITEM_NAME)) {
          if (parent.getChildren().remove(graph))
            parent.getChildren().add(0, graph);
        } else if (e.getActionCommand().equals(TO_BACK_ITEM_NAME)) {
          if (parent.getChildren().remove(graph))
            parent.getChildren().add(graph);
        } else if (e.getActionCommand().equals(FORWARD_ITEM_NAME)) {
          int index = parent.getChildren().indexOf(graph);
          if (index != -1) {
            parent.getChildren().remove(index);
            parent.getChildren().add(Math.max(0, index + 1), graph);
          }
        } else if (e.getActionCommand().equals(BACKWARDS_ITEM_NAME)) {
          int index = parent.getChildren().indexOf(graph);
          if (index != -1) {
            parent.getChildren().remove(index);
            parent.getChildren().add(Math.max(0, index - 1), graph);
          }
        }
        DefaultTreeView.this.notifyListeners();
        DefaultTreeView.this.refreshView(state);
      }
View Full Code Here

                              - jgraph.getLocationOnScreen().x, dsde.getY()
                              - jgraph.getLocationOnScreen().y);
                          DefaultGraphCell endCell = (DefaultGraphCell) GraphView.this.jgraph
                              .getSelectionCell();
                          if (endCell != null) {
                            ModelGraph endGraph = GuiUtils.find(
                                state.getGraphs(),
                                ((ModelNode) endCell.getUserObject()).getId());
                            if (!endGraph.getModel().isParentType()
                                || GuiUtils.isSubGraph(moveGraph, endGraph))
                              return;
                            if (moveGraph.getParent() == null)
                              state.removeGraph(moveGraph);
                            else
                              GuiUtils.removeNode(state.getGraphs(),
                                  moveGraph.getModel());
                            GraphView.this.removeShift(state, moveGraph);
                            GuiUtils.addChild(state.getGraphs(), endGraph
                                .getModel().getId(), moveGraph);
                            GraphView.this.notifyListeners();
                          } else {
                            if (moveGraph.getParent() != null) {
                              GuiUtils.removeNode(state.getGraphs(),
                                  moveGraph.getModel());
                              state.addGraph(moveGraph);
                            }
                            Point shiftPoint = new Point(
                                (int) ((dropPoint.x - (dge.getDragOrigin().x - (bounds
                                    .getX() * scale))) / scale),
                                (int) ((dropPoint.y - (dge.getDragOrigin().y - (bounds
                                    .getY() * scale))) / scale));
                            GraphView.this.setShift(state, moveGraph,
                                shiftPoint);
                            GraphView.this.notifyListeners();
                          }
                        }

                        public void dragEnter(DragSourceDragEvent dsde) {
                          mouseOverCell = (DefaultGraphCell) GraphView.this.jgraph
                              .getFirstCellForLocation(
                                  dsde.getX() - jgraph.getLocationOnScreen().x,
                                  dsde.getY() - jgraph.getLocationOnScreen().y);
                          mouseOverGraph = GuiUtils.find(state.getGraphs(),
                              ((ModelNode) mouseOverCell.getUserObject())
                                  .getId());
                        }

                        public void dragExit(DragSourceEvent dse) {
                          System.out.println("DRAG EXIT!!!!");
                        }

                        public void dragOver(DragSourceDragEvent dsde) {
                          if (state.getMode().equals(Mode.EDIT)) {
                            if (mouseOverCell != null) {
                              Rectangle2D currentBounds = (Rectangle2D) mouseOverCell
                                  .getAttributes().get(GraphConstants.BOUNDS);
                              Point currentPoint = new Point(dsde.getX()
                                  - jgraph.getLocationOnScreen().x, dsde.getY()
                                  - jgraph.getLocationOnScreen().y);
                              if (currentBounds.contains(currentPoint)) {
                                for (ModelGraph child : mouseOverGraph
                                    .getChildren()) {
                                  DefaultGraphCell mouseOverCellLoc = GraphView.this.m_jgAdapter
                                      .getVertexCell(child.getModel());
                                  currentBounds = (Rectangle2D) mouseOverCellLoc
                                      .getAttributes().get(
                                          GraphConstants.BOUNDS);
                                  if (currentBounds.contains(currentPoint)) {
                                    mouseOverCell = mouseOverCellLoc;
                                    mouseOverGraph = child;
                                    break;
                                  }
                                }
                              } else {
                                if (mouseOverGraph.getParent() != null
                                    && (!mouseOverGraph.isCondition() || (mouseOverGraph
                                        .isCondition() && mouseOverGraph
                                        .getParent().isCondition()))) {
                                  mouseOverCell = GraphView.this.m_jgAdapter
                                      .getVertexCell((mouseOverGraph = mouseOverGraph
                                          .getParent()).getModel());
                                  currentBounds = (Rectangle2D) mouseOverCell
                                      .getAttributes().get(
                                          GraphConstants.BOUNDS);
                                } else {
                                  mouseOverCell = null;
                                  mouseOverGraph = null;
                                }
                              }
                            } else {
                              mouseOverCell = (DefaultGraphCell) GraphView.this.jgraph
                                  .getFirstCellForLocation(
                                      dsde.getX()
                                          - jgraph.getLocationOnScreen().x,
                                      dsde.getY()
                                          - jgraph.getLocationOnScreen().y);
                              if (mouseOverCell != null)
                                mouseOverGraph = GuiUtils.find(state
                                    .getGraphs(), ((ModelNode) mouseOverCell
                                    .getUserObject()).getId());
                              else
                                mouseOverGraph = null;
                            }
                            if (mouseOverGraph != null) {
                              if (GuiUtils.isDummyNode(mouseOverGraph
                                  .getModel())) {
                                mouseOverGraph = mouseOverGraph.getParent();
                              } else {
                                while (mouseOverGraph != null
                                    && mouseOverGraph.getModel().isRef())
                                  mouseOverGraph = mouseOverGraph.getParent();
                              }
                              if (mouseOverGraph != null)
                                mouseOverCell = GraphView.this.m_jgAdapter
                                    .getVertexCell(mouseOverGraph.getModel());
                              else
                                mouseOverCell = null;
                            }
                            GraphView.this.jgraph
                                .setSelectionCells(new Object[] { mouseOverCell });
                          }
                        }

                        public void dropActionChanged(DragSourceDragEvent dsde) {
                          System.out.println("DRAG CHANGE!!!!");
                        }

                      });
                }
              }
            }
          }

        });

    List<Line> lines = GuiUtils.findLines(state.getGraphs());
    for (Line line : lines) {
      if (!this.directedGraph.containsVertex(line.getFromModel()))
        this.directedGraph.addVertex(line.getFromModel());

      if (line.getToModel() != null) {
        if (!this.directedGraph.containsVertex(line.getToModel()))
          this.directedGraph.addVertex(line.getToModel());
        IdentifiableEdge edge = new IdentifiableEdge(line.getFromModel(), line.getToModel());
        directedGraph.addEdge(edge, line.getFromModel(), line.getToModel());
        this.edgeMap.put(edge.id, new Pair(line.getFromModel() != null ? line
            .getFromModel().getId() : null, line.getToModel().getId()));
      }
    }

    JGraphFacade facade = new JGraphFacade(jgraph);
    facade.setIgnoresUnconnectedCells(false);
    JGraphHierarchicalLayout layout = new JGraphHierarchicalLayout();
    layout.setOrientation(SwingConstants.WEST);
    layout.setIntraCellSpacing(70.0);
    layout.setLayoutFromSinks(false);
    layout.run(facade);
    Map nested = facade.createNestedMap(true, true);
    if (nested != null) {
      this.hideDummyNodes(nested);
      this.addGroups(state.getGraphs(), nested, state);
      this.ensureNoOverlap(nested, state);
      nested = this.shiftMap(nested, state);
      jgraph.getGraphLayoutCache().edit(nested);
    }

    String edgeDisplayMode = state.getFirstPropertyValue(EDGE_DISPLAY_MODE);
    if (edgeDisplayMode == null)
      state.setProperty(EDGE_DISPLAY_MODE, edgeDisplayMode = WORKFLOW_MODE);
    if (edgeDisplayMode.equals(WORKFLOW_MODE)) {
      this.edgeMap = new HashMap<String, Pair>();
      removeAllEdges(this.directedGraph);
      lines = GuiUtils.findSequentialLines(state.getGraphs());
      for (Line line : lines) {
        IdentifiableEdge edge = new IdentifiableEdge(line.getFromModel(), line.getToModel());
        directedGraph.addEdge(edge, line.getFromModel(), line.getToModel());
        this.edgeMap.put(edge.id, new Pair(line.getFromModel() != null ? line
            .getFromModel().getId() : null, line.getToModel().getId()));
      }
    }

    if (state.getSelected() != null) {
      ModelGraph graph = GuiUtils.find(state.getGraphs(), state.getSelected()
          .getModel().getId());
      if (graph != null) {
        DefaultGraphCell cell = this.m_jgAdapter
            .getVertexCell(graph.getModel());
        if (cell != null)
          this.jgraph.setSelectionCells(new Object[] { cell });
        else
          this.jgraph.setSelectionCells(new Object[] {});
      } else
View Full Code Here

  private void ensureNoOverlap(Map nested, ViewState state) {
    boolean changed;
    do {
      changed = false;
      for (int i = 0; i < state.getGraphs().size(); i++) {
        ModelGraph currentGraph = state.getGraphs().get(i);
        if (this.ensureNoInternalOverlap(currentGraph, nested))
          changed = true;
        DefaultGraphCell currentCell = this.m_jgAdapter
            .getVertexCell(currentGraph.getModel());
        Rectangle2D currentBounds = (Rectangle2D) ((Map) nested
            .get(currentCell)).get(GraphConstants.BOUNDS);
        Point currentShift = this.getShift(state, currentCell, nested);
        Rectangle currentShiftBounds = new Rectangle(
            (int) (currentBounds.getX() + currentShift.getX()),
            (int) (currentBounds.getY() + currentShift.getY()),
            (int) currentBounds.getWidth(), (int) currentBounds.getHeight());
        for (int j = 0; j < state.getGraphs().size(); j++) {
          if (i == j)
            continue;
          ModelGraph graph = state.getGraphs().get(j);
          DefaultGraphCell cell = this.m_jgAdapter.getVertexCell(graph
              .getModel());
          Rectangle2D bounds = (Rectangle2D) ((Map) nested.get(cell))
              .get(GraphConstants.BOUNDS);
          Point shift = this.getShift(state, cell, nested);
          Rectangle shiftBounds = new Rectangle(
View Full Code Here

      changed = ensureNoInternalOverlap(sortedChildren.get(0), nested);
      Rectangle2D graphRectangle = (Rectangle2D) ((Map) nested
          .get(this.m_jgAdapter.getVertexCell(sortedChildren.get(0).getModel())))
          .get(GraphConstants.BOUNDS);
      for (int i = 1; i < sortedChildren.size(); i++) {
        ModelGraph child2 = sortedChildren.get(i);
        if (ensureNoInternalOverlap(child2, nested))
          changed = true;
        DefaultGraphCell child2Cell = this.m_jgAdapter.getVertexCell(child2
            .getModel());
        for (int j = i - 1; j >= 0; j--) {
          ModelGraph child1 = sortedChildren.get(j);
          DefaultGraphCell child1Cell = this.m_jgAdapter.getVertexCell(child1
              .getModel());
          Rectangle2D child1Bounds = (Rectangle2D) ((Map) nested
              .get(child1Cell)).get(GraphConstants.BOUNDS);
          Rectangle2D child2Bounds = (Rectangle2D) ((Map) nested
              .get(child2Cell)).get(GraphConstants.BOUNDS);
View Full Code Here

    return changed;
  }

  private void shift(List<ModelGraph> graphs, Map nested, double x, double y) {
    for (int i = 0; i < graphs.size(); i++) {
      ModelGraph graph = graphs.get(i);
      DefaultGraphCell cell = this.m_jgAdapter.getVertexCell(graph.getModel());
      Rectangle2D bounds = (Rectangle2D) ((Map) nested.get(cell))
          .get(GraphConstants.BOUNDS);
      ((Map) nested.get(cell)).put(
          GraphConstants.BOUNDS,
          new AttributeMap.SerializableRectangle2D(bounds.getX() + x, bounds
              .getY() + y, bounds.getWidth(), bounds.getHeight()));
      this.shift(graph.getChildren(), nested, x, y);
    }
  }
View Full Code Here

      Vector<DefaultGraphCell> group = new Vector<DefaultGraphCell>();
      group.add(modelCell);

      HashMap<Object, Object> map = new HashMap<Object, Object>();
      for (int i = 0; i < modelGraph.getChildren().size(); i++) {
        ModelGraph child = modelGraph.getChildren().get(i);
        DefaultGraphCell curCell = addGroups(child, nested, state);
        group.add(curCell);
        Rectangle2D bounds = (Rectangle2D) ((Map<Object, Object>) nested
            .get(curCell)).get("bounds");
        if (bounds.getX() < top_x)
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.workflow.gui.model.ModelGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.