Exemplo n.º 1
0
  public void renderInJGraph() {
    /** the real renderer */
    ConnectionSet cs = new ConnectionSet();
    Map<Object, AttributeMap> attributes = new Hashtable<Object, AttributeMap>();
    for (DefaultEdge linkEdge : retrieveLinks()) {
      DefaultPort srcPort = (DefaultPort) linkEdge.getSource();
      DefaultPort trgtPort = (DefaultPort) linkEdge.getTarget();
      DefaultGraphCell sourceCell = (DefaultGraphCell) srcPort.getParent();
      DefaultGraphCell targetCell = (DefaultGraphCell) trgtPort.getParent();

      AttributeMap lineStyle = linkEdge.getAttributes();
      AttributeMap sourceNodeCellAttribute = null;
      if (sourceCell != null) sourceNodeCellAttribute = sourceCell.getAttributes();
      AttributeMap targetNodeCellAttribute = null;
      if (targetCell != null) targetNodeCellAttribute = targetCell.getAttributes();

      Object sourceNode = srcPort.getUserObject();
      Object targetNode = trgtPort.getUserObject();
      try {
        if (sourceNode instanceof DefaultMappableTreeNode) {
          if ((targetNode instanceof DefaultMappableTreeNode)) {
            // change target node
            DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) targetNode;
            adjustToNewPosition(treeNode, targetNodeCellAttribute);
          }
          // change source node
          DefaultMutableTreeNode srcNode = (DefaultMutableTreeNode) sourceNode;
          adjustToNewPosition(srcNode, sourceNodeCellAttribute);
        }
        if (sourceNodeCellAttribute != null
            && targetNodeCellAttribute
                != null) { // put in attribute if and only if it is constructed.
          attributes.put(sourceCell, sourceNodeCellAttribute);
          attributes.put(targetCell, targetNodeCellAttribute);
          attributes.put(linkEdge, lineStyle);
          // cs.connect(linkEdge, sourceCell.getChildAt(0), targetCell.getChildAt(0));
          // Log.logInfo(this, "Drew line for : " + mappingComponent.toString());
        }
      } catch (Throwable e) {
        e.printStackTrace();
        // Log.logInfo(this, "Did not draw line for : " + mappingComponent.toString(true));
      }
    } // end of for
    getGraph().getGraphLayoutCache().edit(attributes, cs, null, null);
    getGraph().getGraphLayoutCache().setSelectsAllInsertedCells(false);
  }
 public int hashCode() {
   int result;
   result = (sourceNode != null ? sourceNode.hashCode() : 0);
   result = 29 * result + (targetNode != null ? targetNode.hashCode() : 0);
   result = 29 * result + (sourceCell != null ? sourceCell.hashCode() : 0);
   result = 29 * result + (targetCell != null ? targetCell.hashCode() : 0);
   result = 29 * result + (linkEdge != null ? linkEdge.hashCode() : 0);
   return result;
 }
Exemplo n.º 3
0
  /**
   * 连接两个Port
   *
   * @param source
   * @param target
   */
  public void connect(Port source, Port target) {
    for (Iterator it = source.edges(); it.hasNext(); ) {
      Edge e = (Edge) it.next();
      if (e.getTarget() == target) {
        this.repaint();
        return;
      }
    }
    // Construct Edge with no label
    DefaultEdge edge = new DefaultEdge();
    if (graph.getModel().acceptsSource(edge, source)
        && graph.getModel().acceptsTarget(edge, target)) {

      edge.setUserObject(new FlowEdgeObject(edge));
      // Create a Map thath holds the attributes for the edge
      edge.getAttributes().applyMap(createEdgeAttributes());
      // Insert the Edge and its Attributes
      graph.getGraphLayoutCache().insertEdge(edge, source, target);

      // 添加到树结构
      // editor.strutcView.addFlowRoute(graph, edge);
    }
  }
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof MappingViewCommonComponent)) return false;

    final MappingViewCommonComponent mappingViewCommonComponent = (MappingViewCommonComponent) o;

    if (linkEdge != null
        ? !linkEdge.equals(mappingViewCommonComponent.linkEdge)
        : mappingViewCommonComponent.linkEdge != null) return false;
    if (sourceCell != null
        ? !sourceCell.equals(mappingViewCommonComponent.sourceCell)
        : mappingViewCommonComponent.sourceCell != null) return false;
    if (sourceNode != null
        ? !sourceNode.equals(mappingViewCommonComponent.sourceNode)
        : mappingViewCommonComponent.sourceNode != null) return false;
    if (targetCell != null
        ? !targetCell.equals(mappingViewCommonComponent.targetCell)
        : mappingViewCommonComponent.targetCell != null) return false;
    if (targetNode != null
        ? !targetNode.equals(mappingViewCommonComponent.targetNode)
        : mappingViewCommonComponent.targetNode != null) return false;

    return true;
  }
Exemplo n.º 5
0
  /**
   * The abstract function that descendant classes must be overridden to provide customsized
   * handling.
   *
   * @param e
   * @return true if the action is finished successfully; otherwise, return false.
   */
  protected boolean doAction(ActionEvent e) throws Exception {

    // System.out.println("Delete node clicked.......");
    if (treeNode == null) {
      // System.out.println("Tree node null returning.......");
      return false;
    }

    DefaultEdge[] linkEdge = null;
    DefaultEdge linkEdgeTemp = null;
    DefaultPort[] srcPort = null;
    DefaultPort srcPortTemp = null;
    DefaultPort[] tgtPort = null;
    DefaultPort tgtPortTemp = null;
    for (Object child : MainFrame.getMappingMainPanel().getMiddlePanel().getGraph().getRoots()) {
      if (child instanceof DefaultEdge) {
        linkEdge = new DefaultEdge[2];
        srcPort = new DefaultPort[1];
        tgtPort = new DefaultPort[1];
        linkEdgeTemp = (DefaultEdge) child;
        // linkEdge[0] = linkEdgeTemp;
        srcPortTemp = (DefaultPort) linkEdgeTemp.getSource();
        srcPort[0] = srcPortTemp;
        tgtPortTemp = (DefaultPort) linkEdgeTemp.getTarget();
        tgtPort[0] = tgtPortTemp;
        Iterator edges = srcPortTemp.getEdges().iterator();
        int i = 0;
        while (edges.hasNext()) {
          linkEdge[i] = (DefaultEdge) edges.next();
          i++;
        }

        Object sourceNode = srcPortTemp.getUserObject();
        if (sourceNode instanceof DefaultMutableTreeNode) {
          DefaultMutableTreeNode srcTreeNode = (DefaultMutableTreeNode) sourceNode;
          if (srcTreeNode.getParent().equals(treeNode)) {

            MainFrame.getMappingMainPanel()
                .getMiddlePanel()
                .getGraphController()
                .removeCells(linkEdge, true);
            // MainFrame.getMappingMainPanel().getMiddlePanel().getGraphController().removeCells(tgtPort,true);
            MainFrame.getMappingMainPanel().getTargetScrollPane().repaint();
          }
        }
      }
    }
    // System.out.println("Before Tree node removal.......");
    if (treeNode.getParent() != null) {
      treeNode.removeFromParent();
    } else {
      tree.removeAll();
    }
    // remove the resource from the list
    MainFrame.getMappingMainPanel().getPOJOClassList().remove(treeNode.toString());
    // System.out.println("TREENODE STR..."+treeNode.toString());
    //
    tree.updateUI();
    //
    if (MainFrame.getMappingMainPanel().getMappingTargetFile() != null) {
      Mapping mappingData =
          MainFrame.getMappingMainPanel()
              .getMiddlePanel()
              .getGraphController()
              .retrieveMappingData(true, "Temp");
      if (mappingData != null) {
        MainFrame.getMappingMainPanel()
            .getMiddlePanel()
            .getGraphController()
            .setMappingData(mappingData, true);
        MainFrame.getMappingMainPanel().getMiddlePanel().setMappingNamesforLinkInGraph(mappingData);
      }
    }
    return true;
  }