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); }
/** * 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; }