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

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


  public void removeShift(ViewState state, ModelGraph modelGraph) {
    state.removeProperty(modelGraph.getModel().getId() + "/Shift");
  }

  public Point getShift(ViewState state, DefaultGraphCell cell, Map nested) {
    ModelGraph graph = null;
    if (cell instanceof DefaultEdge) {
      IdentifiableEdge edge = (IdentifiableEdge) cell.getUserObject();
      Pair pair = GraphView.this.edgeMap.get(edge.id);
      graph = GuiUtils.find(state.getGraphs(), pair.getFirst());
    } else {
      graph = GuiUtils.find(state.getGraphs(),
          ((ModelNode) cell.getUserObject()).getId());
    }
    ModelGraph parent = GuiUtils.findRoot(state.getGraphs(), graph);
    Point shiftPoint = null;
    if (state.containsProperty(parent.getModel().getId() + "/Shift"))
      shiftPoint = new Point(Integer.parseInt(state
          .getFirstPropertyValue(parent.getModel().getId() + "/Shift/x")),
          Integer.parseInt(state.getFirstPropertyValue(parent.getModel()
              .getId() + "/Shift/y")));
    if (shiftPoint == null) {
      shiftPoint = new Point(100, 100);
      this.setShift(state, parent, shiftPoint);
      return shiftPoint;
    } else {
      Rectangle2D bounds = (Rectangle2D) ((Map<Object, Object>) nested
          .get(GraphView.this.m_jgAdapter.getVertexCell(parent.getModel())))
          .get(GraphConstants.BOUNDS);
      return new Point(shiftPoint.x - (int) bounds.getX(), shiftPoint.y
          - (int) bounds.getY());
    }
  }
View Full Code Here


    MenuItem formatItem = new MenuItem(FORMAT_ITEM_NAME);
    actionsMenu.add(formatItem);

    PopupMenu orderSubMenu = new PopupMenu(ORDER_SUB_POP_MENU_NAME);

    ModelGraph modelGraph = state.getSelected();
    newSubMenu.setEnabled(modelGraph == null
        || modelGraph.getModel().isParentType());
    deleteItem.setEnabled(modelGraph != null);
    formatItem.setEnabled(true);
    if (modelGraph != null) {
      viewReferrencedWorkflow.setEnabled(modelGraph.getModel().isRef());
      taskItem.setEnabled(!modelGraph.isCondition());
      condItem.setEnabled(modelGraph.isCondition());
      orderSubMenu.setEnabled(modelGraph.getParent() != null
          && !(modelGraph.isCondition() && !modelGraph.getParent()
              .isCondition()));
    } else {
      boolean isCondition = false;
      if (state.getGraphs().size() > 0)
        isCondition = state.getGraphs().get(0).isCondition();
      viewReferrencedWorkflow.setEnabled(false);
      taskItem.setEnabled(!isCondition);
      condItem.setEnabled(isCondition);
    }

    actionsMenu.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals(DELETE_ITEM_NAME)) {
          GuiUtils.removeNode(state.getGraphs(), state.getSelected().getModel());
          state.setSelected(null);
          GraphView.this.notifyListeners();
        } else if (e.getActionCommand().equals(FORMAT_ITEM_NAME)) {
          GraphView.this.refreshView(state);
        } else if (e.getActionCommand().equals(VIEW_REF_WORKFLOW)) {
          scrollSelectedToVisible = true;
          GraphView.this.notifyListeners(new ViewChange.VIEW_MODEL(state
              .getSelected().getModel().getModelId(), GraphView.this));
        }
      }
    });
    PopupMenu edgesSubMenu = new PopupMenu(EDGES_SUB_POP_MENU_NAME);
    edgesSubMenu.add(new MenuItem(TASK_LEVEL));
    edgesSubMenu.add(new MenuItem(WORKFLOW_LEVEL));
    actionsMenu.add(edgesSubMenu);
    edgesSubMenu.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals(TASK_LEVEL)) {
          state.setProperty(EDGE_DISPLAY_MODE, TASK_MODE);
        } else if (e.getActionCommand().equals(WORKFLOW_LEVEL)) {
          state.setProperty(EDGE_DISPLAY_MODE, WORKFLOW_MODE);
        }
        GraphView.this.refreshView(state);
      }

    });
    actionsMenu.add(orderSubMenu);
    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.min(parent.getChildren().size(), 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);
          }
        }
        GraphView.this.notifyListeners();
      }
View Full Code Here

    public void mouseClicked(MouseEvent e) {
      curPoint = e.getPoint();
      if (e.getButton() == MouseEvent.BUTTON3) {
        Object mouseOverCell = GraphView.this.jgraph.getFirstCellForLocation(
            e.getX(), e.getY());
        ModelGraph mouseOverGraph = null;
        if (mouseOverCell != null) {
          mouseOverGraph = (GuiUtils.find(state.getGraphs(),
              ((ModelNode) ((DefaultMutableTreeNode) mouseOverCell)
                  .getUserObject()).getId()));
          if (mouseOverGraph != null) {
            if (GuiUtils.isDummyNode(mouseOverGraph.getModel())) {
              mouseOverGraph = mouseOverGraph.getParent();
            } else {
              while (mouseOverGraph != null
                  && mouseOverGraph.getParent() != null
                  && mouseOverGraph.getParent().getModel().isRef())
                mouseOverGraph = mouseOverGraph.getParent();
            }
            if (mouseOverGraph != null)
              mouseOverCell = GraphView.this.m_jgAdapter
                  .getVertexCell(mouseOverGraph.getModel());
            else
              mouseOverCell = null;
          }
          state.setSelected(mouseOverGraph);
        } else {
          state.setSelected(null);
        }
        PopupMenu actionsMenu = createActionMenu(state);
        GraphView.this.notifyListeners();
        GraphView.this.jgraph.add(actionsMenu);
        actionsMenu.show(GraphView.this.jgraph, e.getPoint().x, e.getPoint().y);
      } else if (e.getButton() == MouseEvent.BUTTON1) {
        if (state.getMode() == View.Mode.ZOOM_IN) {
          state.setProperty(SCALE, Double.toString(Double.parseDouble(state
              .getFirstPropertyValue(SCALE)) + 0.1));
          state.setSelected(null);
          GraphView.this.notifyListeners();
        } else if (state.getMode() == View.Mode.ZOOM_OUT) {
          state.setProperty(SCALE, Double.toString(Double.parseDouble(state
              .getFirstPropertyValue(SCALE)) - 0.1));
          state.setSelected(null);
          GraphView.this.notifyListeners();
        } else if (state.getMode() == View.Mode.EDIT) {
          Object cell = GraphView.this.jgraph.getFirstCellForLocation(e.getX(),
              e.getY());
          if (cell != null) {
            if (cell instanceof DefaultEdge) {
            } else if (cell instanceof DefaultGraphCell) {
              ModelGraph graph = GuiUtils.find(state.getGraphs(),
                  ((ModelNode) ((DefaultGraphCell) cell).getUserObject())
                      .getId());
              if (graph.getModel().isRef())
                while (graph.getParent() != null
                    && graph.getParent().getModel().isRef())
                  graph = graph.getParent();
              if (GuiUtils.isDummyNode(graph.getModel()))
                graph = graph.getParent();
              state.setSelected(graph);
              GraphView.this.notifyListeners();
            }
          } else if (cell == null && state.getSelected() != null) {
            state.setSelected(null);
            GraphView.this.notifyListeners();
          }
        } else if (state.getMode() == View.Mode.DELETE
            && e.getClickCount() == 2) {
          Object cell = GraphView.this.jgraph.getFirstCellForLocation(e.getX(),
              e.getY());
          if (cell != null) {
            if (cell instanceof DefaultEdge) {
              // do nothing
            } else if (cell instanceof DefaultGraphCell) {
              ModelGraph graph = GuiUtils.removeNode(state.getGraphs(),
                  (ModelNode) ((DefaultGraphCell) cell).getUserObject());
              GraphView.this.notifyListeners();
            }
          }
        }
View Full Code Here

    public void actionPerformed(ActionEvent e) {
      this.createNewGraph(e.getActionCommand());
    }

    private void createNewGraph(String actionCommand) {
      ModelGraph newGraph = null;
      if (actionCommand.equals(NEW_TASK_ITEM_NAME)) {
        newGraph = new ModelGraph(new ModelNode(state.getFile(),
            GuiUtils.createUniqueName()));
      } else if (actionCommand.equals(NEW_PARALLEL_ITEM_NAME)) {
        ModelNode node = new ModelNode(state.getFile(),
            GuiUtils.createUniqueName());
        node.setExecutionType("parallel");
        newGraph = new ModelGraph(node);
      } else if (actionCommand.equals(NEW_SEQUENTIAL_ITEM_NAME)) {
        ModelNode node = new ModelNode(state.getFile(),
            GuiUtils.createUniqueName());
        node.setExecutionType("sequential");
        newGraph = new ModelGraph(node);
      } else {
        return;
      }
      Object cell = GraphView.this.jgraph.getSelectionCell();
      if (cell != null) {
        if (cell instanceof DefaultGraphCell) {
          ModelGraph graph = GuiUtils.find(state.getGraphs(),
              ((ModelNode) ((DefaultGraphCell) cell).getUserObject()).getId());
          if (graph != null)
            graph.addChild(newGraph);
        }
      } else {
        state.addGraph(newGraph);
        GraphView.this.setShift(state, newGraph, curPoint);
      }
View Full Code Here

    this.setLayout(new BorderLayout());
  }

  private JTable createTable(final ViewState state) {
    JTable table = null;
    final ModelGraph selected = state.getSelected();
    if (selected != null) {
      final Vector<Vector<String>> rows = new Vector<Vector<String>>();
      HashMap<String, String> keyToGroupMap = new HashMap<String, String>();
      Metadata staticMet = selected.getModel().getStaticMetadata();
      Metadata inheritedMet = selected.getInheritedStaticMetadata(state);
      Metadata completeMet = new Metadata();
      if (staticMet != null) {
        completeMet.replaceMetadata(staticMet.getSubMetadata(state
            .getCurrentMetGroup()));
      }
      if (selected.getModel().getExtendsConfig() != null) {
        for (String configGroup : selected.getModel().getExtendsConfig()) {
          Metadata extendsMetadata = state.getGlobalConfigGroups()
              .get(configGroup).getMetadata()
              .getSubMetadata(state.getCurrentMetGroup());
          for (String key : extendsMetadata.getAllKeys()) {
            if (!completeMet.containsKey(key)) {
              keyToGroupMap.put(key, configGroup);
              completeMet.replaceMetadata(key,
                  extendsMetadata.getAllMetadata(key));
            }
          }
        }
      }
      if (inheritedMet != null) {
        Metadata inheritedMetadata = inheritedMet.getSubMetadata(state
            .getCurrentMetGroup());
        for (String key : inheritedMetadata.getAllKeys()) {
          if (!completeMet.containsKey(key)) {
            keyToGroupMap.put(key, "__inherited__");
            completeMet.replaceMetadata(key,
                inheritedMetadata.getAllMetadata(key));
          }
        }
      }
      List<String> keys = completeMet.getAllKeys();
      Collections.sort(keys);
      for (String key : keys) {
        if (key.endsWith("/envReplace"))
          continue;
        String values = StringUtils.join(completeMet.getAllMetadata(key), ",");
        Vector<String> row = new Vector<String>();
        row.add(keyToGroupMap.get(key));
        row.add(key);
        row.add(values);
        row.add(Boolean.toString(Boolean.parseBoolean(completeMet
            .getMetadata(key + "/envReplace"))));
        rows.add(row);
      }
      table = new JTable();// rows, new Vector<String>(Arrays.asList(new
                           // String[] { "key", "values", "envReplace" })));
      table.setModel(new AbstractTableModel() {
        public String getColumnName(int col) {
          switch (col) {
          case 0:
            return "group";
          case 1:
            return "key";
          case 2:
            return "values";
          case 3:
            return "envReplace";
          default:
            return null;
          }
        }

        public int getRowCount() {
          return rows.size() + 1;
        }

        public int getColumnCount() {
          return 4;
        }

        public Object getValueAt(int row, int col) {
          if (row >= rows.size())
            return null;
          String value = rows.get(row).get(col);
          if (value == null && col == 3)
            return "false";
          if (value == null && col == 0)
            return "__local__";
          return value;
        }

        public boolean isCellEditable(int row, int col) {
          if (row >= rows.size()) {
            if (selected.getModel().getStaticMetadata()
                .containsGroup(state.getCurrentMetGroup()))
              return true;
            else
              return false;
          }
          if (col == 0)
            return false;
          String key = rows.get(row).get(1);
          if (key == null
              || (selected.getModel().getStaticMetadata() != null && selected
                  .getModel().getStaticMetadata()
                  .containsKey(getKey(key, state))))
            return true;
          return false;
        }
View Full Code Here

    this.mode = state.mode;
  }

  public ViewState clone() {
    List<ModelGraph> cloneGraphs = null;
    ModelGraph selected = null;
    if (this.graphs != null) {
      cloneGraphs = new Vector<ModelGraph>();
      for (ModelGraph graph : this.graphs)
        cloneGraphs.add(graph.clone());
      if (this.selected != null)
View Full Code Here

      this.refresh();
    } else if (change instanceof ViewChange.VIEW_MODEL) {
      String modelId = ((ViewChange.VIEW_MODEL) change).getObject();
      for (ViewState state : this.stateViews.keySet()) {
        for (ModelGraph graph : state.getGraphs()) {
          ModelGraph found = graph.recursiveFindByModelId(modelId);
          if (found != null && !found.getModel().isRef()) {
            this.activeState = state;
            this.activeState.setSelected(found);
            break;
          }
        }
View Full Code Here

      if (this.getActiveView() != null) {
        ViewState viewState = null;
        if (this.state.getSelected() != null && findSelectedInTab) {
          TOP: for (Entry<View, ViewState> entry : this.mainViews.entrySet()) {
            for (ModelGraph graph : entry.getValue().getGraphs()) {
              ModelGraph found = graph.recursiveFindByModelId(this.state
                  .getSelected().getModel().getModelId());
              if (found != null && !found.getModel().isRef()) {
                viewState = entry.getValue();
                viewState.setSelected(found);
                this.tabbedPane.setSelectedComponent(entry.getKey());
                break TOP;
              }
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.