Exemplo n.º 1
0
 // Connection logic.
 // The deletion is acceptable if the resulting relationship is valid.
 // selected are the nodes to removed.
 public boolean acceptRemove(GraphCell[] selected) {
   // All roles considered in the relationship.
   List roles = this.getOrderedRoles();
   // Valid deletion.
   boolean ok = true;
   // Check all roles.
   for (int i = 0; i < roles.size(); i++) {
     String roleName = (String) roles.get(i);
     Integer minAllowedTimes = this.getArity(roleName, true);
     Integer maxAllowedTimes = this.getArity(roleName, false);
     // Objects playing roleName in this relationship.
     GraphCell[] roleObjects = this.getObjects(roleName);
     // newUse is roleObjects number minus those objects in selected (which will be removed).
     int currentUse = roleObjects.length;
     for (int j = 0; j < roleObjects.length; j++)
       for (int k = 0; k < selected.length; k++) {
         // Object to be compared with roleObjects.
         Object object = null;
         // Default Edge.
         if (selected[k] instanceof DefaultEdge) {
           DefaultPort targetPort = (DefaultPort) ((DefaultEdge) selected[k]).getTarget();
           object = targetPort.getParent();
           // Vertex
         } else if ((selected[k] instanceof DefaultGraphCell)
             && !(selected[k] instanceof DefaultPort)) {
           object = selected[k];
         }
         // If the object is in the deleted list, there is one less object playing the role.
         if (roleObjects[j].equals(object)) currentUse--;
       }
     // Check the role for the deletion.
     ok =
         ok
             && (minAllowedTimes.intValue() <= currentUse)
             && (currentUse <= maxAllowedTimes.intValue());
   }
   return ok;
 }
Exemplo n.º 2
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);
  }
Exemplo n.º 3
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;
  }