protected void setDummyEdges() { Node targetNode = null; int nodeCount = nodeList.size(); // if node count is only one then we don't have to worry about whether // the nodes are connected if (nodeCount > 1) { for (Iterator iter = nodeList.iterator(); iter.hasNext();) { Node sourceNode = (Node) iter.next(); // we will need to set up a dummy relationship for any table not // in one already if (sourceNode.outgoing.size() == 0 && sourceNode.incoming.size() == 0) { targetNode = findTargetNode(sourceNode); Edge edge = newDummyEdge(targetNode, sourceNode); edgesAdded.add(edge); } } } }
protected void addEdges(AbstractGraphicalEditPart diagram) { for (Object obj : diagram.getChildren()) { AbstractGraphicalEditPart part = (AbstractGraphicalEditPart) obj; for (Object item : part.getSourceConnections()) { RelationshipPart rpart = (RelationshipPart) item; Node source = (Node) partToNodesMap.get(rpart.getSource()); Node target = (Node) partToNodesMap.get(rpart.getTarget()); if (source != null && target != null) { Edge e = new Edge(rpart, source, target); e.weight = 2; graph.edges.add(e); partToNodesMap.put(rpart, e); } } } }
/** * Returns the children those should be locate to the south. * * @return the children those should be locate to the south. */ @SuppressWarnings("unchecked") public NodeList getSouthNodes() { EdgeList edgeList = new EdgeList(); NodeList nodeList = new NodeList(); for (Object obj : node.outgoing) { if (!DcaseDirectedGraph.isEast((Node) ((Edge) obj).target)) { edgeList.add(obj); } } // sorts by the sibling order. if (edgeList.size() > 1) { Collections.sort(edgeList, new DcaseEditPartLayoutComparator()); } for (int i = 0; i < edgeList.size(); i++) { nodeList.add(((Edge) edgeList.get(i)).target); } return nodeList; }
/** * Returns the children those should be locate to the east. * * @return the children those should be locate to the east. */ @SuppressWarnings("unchecked") public NodeList getEastNodes() { EdgeList edgeList = new EdgeList(); NodeList nodeList = new NodeList(); for (Object obj : node.outgoing) { if (DcaseDirectedGraph.isEast((Node) ((Edge) obj).target)) { edgeList.add(obj); } } // sorts by the sibling order. if (edgeList.size() > 1) { Collections.sort(edgeList, new DcaseEditPartLayoutComparator()); } for (int i = 0; i < edgeList.size(); i++) { nodeList.add(((Edge) edgeList.get(i)).target); } return nodeList; }
/** * Returns the root of the specified node. * * @param node the node. */ private void getRootParent(Node node) { if (getNodeEx(node) != null) { return; } if (workStack.contains(node)) { return; } workStack.push(node); EdgeList edgeList = node.incoming; if (edgeList.size() > 0) { for (int i = 0; i < edgeList.size(); i++) { Node parent = ((Edge) edgeList.get(i)).source; getRootParent(parent); } } else { addBaseNodeList(node); collectBaseNode(node); } workStack.pop(); return; }
/** * Returns the value of the sibling order. * * @param edge the edge. * @return the value of the sibling order. */ private int getValueSiblingOrder(Edge edge) { int siblingOrder = 0; ConnectionEditPart linkEditPart = (ConnectionEditPart) edge.data; ConnectorImpl connectLink = (ConnectorImpl) linkEditPart.getModel(); String strValue = null; if (connectLink.getElement() != null) { strValue = ((BasicLink) connectLink.getElement()) .getSiblingOrder(); } if (strValue == null) { siblingOrder = NON_NUMBER; } else { siblingOrder = NumberUtil.parseIntWithDefault(strValue, NON_NUMBER); } return siblingOrder; }
@Override @SuppressWarnings("unchecked") public void execute(ICustomContext context) { Diagram diagram = getDiagram(); CompoundDirectedGraph draw2dGrap = new CompoundDirectedGraph(); BiMap<PictogramElement, Node> draw2dGraphMap = HashBiMap.create(); for (Shape shape : diagram.getChildren()) { final EObject eObject = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(shape); if (eObject instanceof ProcessingUnit || eObject instanceof Medium) { Node node = new Node(); draw2dGrap.nodes.add(node); node.setSize(new Dimension(SHAPE_WIDTH, SHAPE_HEIGHT)); draw2dGraphMap.put(shape, node); } } for (Connection connection : diagram.getConnections()) { Node start = draw2dGraphMap.get(connection.getEnd().getParent()); Node end = draw2dGraphMap.get(connection.getStart().getParent()); Edge edge = new Edge(start, end); draw2dGrap.edges.add(edge); } new CompoundDirectedGraphLayout().visit(draw2dGrap); for (Entry<PictogramElement, Node> e : draw2dGraphMap.entrySet()) { PictogramElement pe = e.getKey(); Node n = e.getValue(); Graphiti.getGaService().setLocation(pe.getGraphicsAlgorithm(), n.x, n.y); } hasDoneChanges = true; }
/** * creates a new dummy edge to be used in the graph */ private Edge newDummyEdge(Node sourceNode, Node targetNode) { DummyEdgePart edgePart = new DummyEdgePart(); Edge edge = new Edge(edgePart, sourceNode, targetNode); edge.weight = 2; // add the new edge to the edge list edgeList.add(edge); targetNode = sourceNode; return edge; }
/** * @param graph */ private void init(DirectedGraph graph) { this.graph = graph; this.nodeList = graph.nodes; this.edgeList = graph.edges; edgesAdded = new ArrayList<Edge>(); }
/** * creates a new dummy edge to be used in the graph */ private Edge newDummyEdge(Node targetNode, Node sourceNode) { DummyEdgePart edgePart = new DummyEdgePart(); Edge edge = new Edge(edgePart, sourceNode, targetNode); edge.weight = 2; edgeList.add(edge); targetNode = sourceNode; return edge; }
protected void applyResults(RelationshipPart relationshipPart) { Edge e = (Edge) partToNodesMap.get(relationshipPart); if (e == null) return; NodeList nodes = e.vNodes; PolylineConnection conn = (PolylineConnection) relationshipPart .getConnectionFigure(); if (nodes != null) { List<AbsoluteBendpoint> bends = new ArrayList<AbsoluteBendpoint>(); for (int i = 0; i < nodes.size(); i++) { Node vn = nodes.getNode(i); int x = vn.x; int y = vn.y; if (e.isFeedback()) { bends.add(new AbsoluteBendpoint(x, y + vn.height)); bends.add(new AbsoluteBendpoint(x, y)); } else { bends.add(new AbsoluteBendpoint(x, y)); bends.add(new AbsoluteBendpoint(x, y + vn.height)); } } conn.setRoutingConstraint(bends); } else { conn.setRoutingConstraint(Collections.EMPTY_LIST); } }
private static void sortEdges(final List<Edge> edges) { Collections.sort(edges, new Comparator<Edge>() { @Override public int compare(final Edge e1, final Edge e2) { final Node v1 = e1.target; final Node v2 = e2.target; final Long id1 = (Long) v1.data * (v1.incoming.size() == 0 ? -1 : 1); final Long id2 = (Long) v2.data * (v2.incoming.size() == 0 ? -1 : 1); return id1 < 0 && id2 < 0 ? (int) (id2 - id1) : (int) (id1 - id2); } }); }
@SuppressWarnings("unchecked") @Override public void addEdge(final Node x, final Node y) { final Edge e = new Edge(x, y); graph.edges.add(e); x.outgoing.add(e); y.incoming.add(e); }
@SuppressWarnings("unchecked") private void visitBF(final Node u, final DiagramSection section, final IHierarchicalPosition parent) { setColor(u, Color.BLACK); int column = 0; // subtrees of this object ContourGraphFactory.sortEdges(u.outgoing); for (final Object o : u.outgoing) { final Edge e = (Edge) o; final Node v = e.target; if (getColor(v) == Color.WHITE) { final IHierarchicalPosition position = setPosition(v, section, parent, column++); visitBF(v, section, position); } } // subtrees leading into this object // ContourGraphFactory.sortEdges(u.incoming); // for (final Object o : u.incoming) // { // final Edge e = (Edge) o; // final Node v = e.source; // if (getColor(v) == Color.WHITE) // { // final IHierarchicalPosition position = setPosition(v, section, parent, column++); // visitBF(v, section, position); // } // } }
private void visitDF(final Node u, final DiagramSection section, final int column, int layer, final Map<Integer, Integer> layerToNextCellMapping) { if (layerToNextCellMapping.containsKey(layer)) { final int cell = layerToNextCellMapping.get(layer); setPosition(u, section, column, layer, cell); layerToNextCellMapping.put(layer, cell + 1); } else { setPosition(u, section, column, layer, 0); layerToNextCellMapping.put(layer, 1); } setColor(u, Color.BLACK); layer++; for (final Object o : u.outgoing) { final Edge e = (Edge) o; final Node v = e.target; if (getColor(v) == Color.WHITE) { visitDF(v, section, column, layer, layerToNextCellMapping); } } setColor(u, Color.BLACK); }
/** * Returns the count of the children those should be locate to the south. * * @return the count of the children those should be locate to the south. */ public int getSouthCount() { int count = 0; for (Object obj : node.outgoing) { if (!DcaseDirectedGraph.isEast((Node) ((Edge) obj).target)) { count++; } } return count; }
/** * Returns the count of the children those should be locate to the east. * * @return the count of the children those should be locate to the east. */ public int getEastCount() { int count = 0; for (Object obj : node.outgoing) { if (DcaseDirectedGraph.isEast((Node) ((Edge) obj).target)) { count++; } } return count; }
/** * Returns the parents. * * @return the parents. */ @SuppressWarnings("unchecked") public NodeList getParent() { NodeList nodeList = new NodeList(); for (Object obj : node.incoming) { nodeList.add((Node) ((Edge) obj).source); } return nodeList; }
/** * Returns the children. * * @return Returns the children. */ @SuppressWarnings("unchecked") public NodeList getChildren() { NodeList nodeList = new NodeList(); for (Object obj : node.outgoing) { nodeList.add((Node) ((Edge) obj).target); } return nodeList; }
/** * Compares the edges. * * @param object1 the first edge. * @param object2 the second edge. * @return -1 if and only if the first edge is lower than second edge<br> * 0 if and only if the first edge equals second edge<br> * 1 if and only if the first edge is higher than second edge * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Edge object1, Edge object2) { // gets the sibling order of the first edge. int first001Value = getValueSiblingOrder(object1); // gets the sibling order of the second edge. int second001Value = getValueSiblingOrder(object2); int n = compareValue(first001Value, second001Value); if (n == 0) { String firstNameValue = getNameValue(object1); String secondNameValue = getNameValue(object2); // name order n = compareNameValue(firstNameValue, secondNameValue); if (n == 0) { // graphic location order // compares the coordinates if the sibling order of first edge equals the sibling order of second edge first001Value = object1.target.x; second001Value = object2.target.x; if (compareValue(first001Value, second001Value) != 0) { return compareValue(first001Value, second001Value); } else { // compares the Y axis. first001Value = object1.target.y; second001Value = object2.target.y; if (compareValue(first001Value, second001Value) != 0) { return compareValue(first001Value, second001Value); } } } } return n; }
/** * Returns the value of the name property. * * @param edge the edge. * @return the value of the name property. */ private String getNameValue(Edge edge) { ConnectionEditPart connection = (ConnectionEditPart) edge.data; GraphicalEditPart gEditPart = (GraphicalEditPart) connection.getTarget(); if (gEditPart != null) { BasicNode node = (BasicNode) DcaseEditorUtil. getElement(gEditPart); if (node == null) { return StringUtil.EMPTY; } return node.getName(); } return StringUtil.EMPTY; }
protected void removeDummyEdges() { for (Edge edge : edgesAdded) edgeList.remove(edge); }
/** * Locates the edges. */ private void locateEdge() { EdgeList list = getGraph().getEdgeList(); for (int i = 0; i < list.size(); i++) { Edge edge = list.getEdge(i); Node source = edge.source; Node target = edge.target; Point start = new Point(); Point end = new Point(); PointList mid = new PointList(); int direction = getDirection(source, target); switch (direction) { case LEFT_TO_RIGHT: start.x = source.x + source.width; start.y = source.y + source.height / 2; end.x = target.x; end.y = target.y + target.height / 2; break; case RIGHT_TO_LEFT: start.x = source.x; start.y = source.y + source.height / 2; end.x = target.x + target.width; end.y = target.y + target.height / 2; break; case BOTTOM_TO_TOP: start.x = source.x + source.width / 2; start.y = source.y; end.x = target.x + target.width / 2; end.y = target.y + target.height; break; default: start.x = source.x + source.width / 2; start.y = source.y + source.height; end.x = target.x + target.width / 2; end.y = target.y; } if (getNodeEx(target).getLooped()) { if (direction == BOTTOM_TO_TOP || direction == RIGHT_TO_LEFT) { if (Math.abs(start.x - end.x) < GAP) { end.x = target.x + target.width / 2; end.y = target.y + target.height; int xPoint = start.x - source.width / 2 - VERTICAL_SPACING; mid.addPoint(xPoint, start.y - HORIZONTAL_SPACING / 2); mid.addPoint(xPoint, end.y + (start.y - end.y) / 2); mid.addPoint(xPoint, end.y + HORIZONTAL_SPACING / 2); } else if (Math.abs(start.y - end.y) < GAP) { end.x = target.x + target.width; end.y = target.y + target.height / 2; int yPoint = start.y - source.height / 2 - HORIZONTAL_SPACING; mid.addPoint(start.x - VERTICAL_SPACING / 2, yPoint); mid.addPoint(end.x + (start.x - end.x) / 2, yPoint); mid.addPoint(end.x + VERTICAL_SPACING / 2, yPoint); } } } edge.getPoints().removeAllPoints(); edge.getPoints().addPoint(start); for (int j = 0; j < mid.size(); j++) { edge.getPoints().addPoint(mid.getPoint(j)); } edge.getPoints().addPoint(end); edge.getPoints(); } }