### Eclipse Workspace Patch 1.0 #P org.eclipse.zest.core Index: src/org/eclipse/zest/core/viewers/internal/AbstractStructuredGraphViewer.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.zest.core/src/org/eclipse/zest/core/viewers/internal/AbstractStructuredGraphViewer.java,v retrieving revision 1.18 diff -u -r1.18 AbstractStructuredGraphViewer.java --- src/org/eclipse/zest/core/viewers/internal/AbstractStructuredGraphViewer.java 6 Sep 2011 12:16:32 -0000 1.18 +++ src/org/eclipse/zest/core/viewers/internal/AbstractStructuredGraphViewer.java 2 Mar 2012 16:34:23 -0000 @@ -42,7 +42,8 @@ * * @author Del Myers */ -public abstract class AbstractStructuredGraphViewer extends AbstractZoomableViewer { +public abstract class AbstractStructuredGraphViewer extends + AbstractZoomableViewer { /** * Contains top-level styles for the entire graph. Set in the constructor. * */ @@ -90,7 +91,8 @@ public int compare(Object arg0, Object arg1) { if (arg0 instanceof GraphNode && arg1 instanceof GraphConnection) { return 1; - } else if (arg0 instanceof GraphConnection && arg1 instanceof GraphNode) { + } else if (arg0 instanceof GraphConnection + && arg1 instanceof GraphNode) { return -1; } if (arg0.equals(arg1)) { @@ -100,7 +102,8 @@ } private String getObjectString(Object o) { - String s = o.getClass().getName() + "@" + Integer.toHexString(o.hashCode()); + String s = o.getClass().getName() + "@" + + Integer.toHexString(o.hashCode()); while (storedStrings.contains(s)) { s = s + 'X'; } @@ -205,7 +208,8 @@ * true if the layout algorithm should be run immediately. This * is a hint. */ - public abstract void setLayoutAlgorithm(LayoutAlgorithm algorithm, boolean run); + public abstract void setLayoutAlgorithm(LayoutAlgorithm algorithm, + boolean run); /** * Gets the current layout algorithm. @@ -235,6 +239,10 @@ return this.nodesMap; } + HashMap getConnectionsMap() { + return this.connectionsMap; + } + GraphNode addGraphModelContainer(Object element) { GraphNode node = this.getGraphModelNode(element); if (node == null) { @@ -271,10 +279,12 @@ return node; } - GraphConnection addGraphModelConnection(Object element, GraphNode source, GraphNode target) { + GraphConnection addGraphModelConnection(Object element, GraphNode source, + GraphNode target) { GraphConnection connection = this.getGraphModelConnection(element); if (connection == null) { - connection = new GraphConnection((Graph) getControl(), SWT.NONE, source, target); + connection = new GraphConnection((Graph) getControl(), SWT.NONE, + source, target); this.connectionsMap.put(element, connection); connection.setData(element); } @@ -313,7 +323,9 @@ /* * (non-Javadoc) * - * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object) + * @see + * org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang. + * Object) */ protected void internalRefresh(Object element) { if (getInput() == null) { @@ -327,7 +339,8 @@ // After all the items are loaded, we call update to ensure drawing. // This way the damaged area does not get too big if we start // adding and removing more nodes - getGraphControl().getLightweightSystem().getUpdateManager().performUpdate(); + getGraphControl().getLightweightSystem().getUpdateManager() + .performUpdate(); } protected void doUpdateItem(Widget item, Object element, boolean fullMap) { @@ -342,7 +355,9 @@ /* * (non-Javadoc) * - * @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object) + * @see + * org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang. + * Object) */ protected Widget doFindInputItem(Object element) { @@ -355,7 +370,8 @@ /* * (non-Javadoc) * - * @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) + * @see + * org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) */ protected Widget doFindItem(Object element) { Widget node = (Widget) nodesMap.get(element); @@ -398,8 +414,9 @@ /* * (non-Javadoc) * - * @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, - * boolean) + * @see + * org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java. + * util.List, boolean) */ protected void setSelectionToWidget(List l, boolean reveal) { Graph control = (Graph) getControl(); @@ -415,7 +432,8 @@ selection.add(conn); } } - control.setSelection((GraphNode[]) selection.toArray(new GraphNode[selection.size()])); + control.setSelection((GraphNode[]) selection + .toArray(new GraphNode[selection.size()])); } /** @@ -432,7 +450,7 @@ * (non-Javadoc) * * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, - * java.lang.Object) + * java.lang.Object) */ protected void inputChanged(Object input, Object oldInput) { IStylingGraphModelFactory factory = getFactory(); @@ -476,9 +494,11 @@ GraphNode newNode = (GraphNode) nodesMap.get(data); if (newNode != null) { GraphNode oldNode = (GraphNode) oldNodesMap.get(data); - newNode.setLocation(oldNode.getLocation().x, oldNode.getLocation().y); + newNode.setLocation(oldNode.getLocation().x, + oldNode.getLocation().y); if (oldNode.isSizeFixed()) { - newNode.setSize(oldNode.getSize().width, oldNode.getSize().height); + newNode.setSize(oldNode.getSize().width, + oldNode.getSize().height); } } } @@ -557,7 +577,9 @@ /* * (non-Javadoc) * - * @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object) + * @see + * org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object + * ) */ protected Object[] getRawChildren(Object parent) { if (parent == getInput()) { @@ -628,12 +650,14 @@ * @param connection */ public void removeRelationship(Object connection) { - GraphConnection relationship = (GraphConnection) connectionsMap.get(connection); + GraphConnection relationship = (GraphConnection) connectionsMap + .get(connection); if (relationship != null) { // remove the relationship from the layout algorithm if (getLayoutAlgorithm() != null) { - getLayoutAlgorithm().removeRelationship(relationship.getLayoutRelationship()); + getLayoutAlgorithm().removeRelationship( + relationship.getLayoutRelationship()); } // remove the relationship from the model relationship.dispose(); @@ -667,8 +691,10 @@ // remove the node from the layout algorithm and all the connections if (getLayoutAlgorithm() != null) { getLayoutAlgorithm().removeEntity(node.getLayoutEntity()); - getLayoutAlgorithm().removeRelationships(node.getSourceConnections()); - getLayoutAlgorithm().removeRelationships(node.getTargetConnections()); + getLayoutAlgorithm().removeRelationships( + node.getSourceConnections()); + getLayoutAlgorithm().removeRelationships( + node.getTargetConnections()); } // remove the node and it's connections from the model node.dispose(); @@ -686,10 +712,12 @@ * @param destNode * The destination node data object. */ - public void addRelationship(Object connection, Object srcNode, Object destNode) { + public void addRelationship(Object connection, Object srcNode, + Object destNode) { // create the new relationship IStylingGraphModelFactory modelFactory = getFactory(); - modelFactory.createConnection(getGraphControl(), connection, srcNode, destNode); + modelFactory.createConnection(getGraphControl(), connection, srcNode, + destNode); } @@ -704,11 +732,13 @@ IStylingGraphModelFactory modelFactory = getFactory(); if (connectionsMap.get(connection) == null) { if (modelFactory.getContentProvider() instanceof IGraphContentProvider) { - IGraphContentProvider content = ((IGraphContentProvider) modelFactory.getContentProvider()); + IGraphContentProvider content = ((IGraphContentProvider) modelFactory + .getContentProvider()); Object source = content.getSource(connection); Object dest = content.getDestination(connection); // create the new relationship - modelFactory.createConnection(getGraphControl(), connection, source, dest); + modelFactory.createConnection(getGraphControl(), connection, + source, dest); } else { throw new UnsupportedOperationException(); } @@ -722,8 +752,10 @@ * @return GraphModelConnection[] */ protected GraphConnection[] getConnectionsArray(Graph graph) { - GraphConnection[] connsArray = new GraphConnection[graph.getConnections().size()]; - connsArray = (GraphConnection[]) graph.getConnections().toArray(connsArray); + GraphConnection[] connsArray = new GraphConnection[graph + .getConnections().size()]; + connsArray = (GraphConnection[]) graph.getConnections().toArray( + connsArray); return connsArray; } Index: src/org/eclipse/zest/core/viewers/internal/AbstractStylingModelFactory.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.zest.core/src/org/eclipse/zest/core/viewers/internal/AbstractStylingModelFactory.java,v retrieving revision 1.16 diff -u -r1.16 AbstractStylingModelFactory.java --- src/org/eclipse/zest/core/viewers/internal/AbstractStylingModelFactory.java 21 Feb 2011 01:39:54 -0000 1.16 +++ src/org/eclipse/zest/core/viewers/internal/AbstractStylingModelFactory.java 2 Mar 2012 16:34:24 -0000 @@ -38,7 +38,8 @@ */ // @tag zest.bug.160367-Refreshing.fix : update the factory to use the // IStylingGraphModelFactory -public abstract class AbstractStylingModelFactory implements IStylingGraphModelFactory { +public abstract class AbstractStylingModelFactory implements + IStylingGraphModelFactory { private AbstractStructuredGraphViewer viewer; private int connectionStyle; private int nodeStyle; @@ -71,7 +72,8 @@ leftList = getConnectionList(dest, source); } - int size = (leftList != null) ? leftList.size() + rightList.size() : rightList.size(); + int size = (leftList != null) ? leftList.size() + rightList.size() + : rightList.size(); // adjust the arcs going from source to destination adjustCurves(rightList, size); // adjust the arcs going from destination to source @@ -85,12 +87,13 @@ * the bezier curves based on the number of curves in the list. * * @param connections - * @param size -+ * total number of arcs - may be bigger then connections.size + * @param size + * + * total number of arcs - may be bigger then connections.size */ protected void adjustCurves(List connections, int size) { /* - * The connections should be curved if source and dest are equal, or there are multiple arcs between two nodes + * The connections should be curved if source and dest are equal, or + * there are multiple arcs between two nodes */ for (int i = 0; i < connections.size(); i++) { GraphConnection conn = (GraphConnection) connections.get(i); @@ -135,7 +138,8 @@ /* * (non-Javadoc) * - * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#getLabelProvider() + * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory# + * getLabelProvider() */ public IBaseLabelProvider getLabelProvider() { return viewer.getLabelProvider(); @@ -144,7 +148,8 @@ /* * (non-Javadoc) * - * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#getContentProvider() + * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory# + * getContentProvider() */ public IStructuredContentProvider getContentProvider() { return (IStructuredContentProvider) viewer.getContentProvider(); @@ -153,10 +158,12 @@ /* * (non-Javadoc) * - * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#createConnection(org.eclipse.zest.core.internal.graphmodel.GraphModel, - * java.lang.Object, java.lang.Object, java.lang.Object) + * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory# + * createConnection(org.eclipse.zest.core.internal.graphmodel.GraphModel, + * java.lang.Object, java.lang.Object, java.lang.Object) */ - public GraphConnection createConnection(Graph graph, Object element, Object source, Object dest) { + public GraphConnection createConnection(Graph graph, Object element, + Object source, Object dest) { if (source == null || dest == null) { return null; } @@ -164,7 +171,8 @@ GraphNode sn = viewer.getGraphModelNode(source); GraphNode dn = viewer.getGraphModelNode(dest); if (oldConnection != null) { - if (sn != oldConnection.getSource() || dn != oldConnection.getDestination()) { + if (sn != oldConnection.getSource() + || dn != oldConnection.getDestination()) { viewer.removeGraphModelConnection(oldConnection); } else { styleItem(oldConnection); @@ -205,23 +213,27 @@ /* * (non-Javadoc) * - * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#createNode(org.eclipse.zest.core.internal.graphmodel.GraphModel, - * java.lang.Object) + * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory# + * createNode(org.eclipse.zest.core.internal.graphmodel.GraphModel, + * java.lang.Object) */ public GraphNode createNode(Graph graph, Object element, IFigure figure) { GraphNode node = null; if (getContentProvider() instanceof INestedContentProvider) { - boolean isContainer = ((INestedContentProvider) getContentProvider()).hasChildren(element); + boolean isContainer = ((INestedContentProvider) getContentProvider()) + .hasChildren(element); if (isContainer) { node = viewer.addGraphModelContainer(element); styleItem(node); - Object[] childNodes = ((INestedContentProvider) getContentProvider()).getChildren(element); + Object[] childNodes = ((INestedContentProvider) getContentProvider()) + .getChildren(element); childNodes = filter(getViewer().getInput(), childNodes); if (childNodes == null) { return node; } for (int i = 0; i < childNodes.length; i++) { - GraphNode childNode = viewer.addGraphModelNode((IContainer) node, childNodes[i]); + GraphNode childNode = viewer.addGraphModelNode( + (IContainer) node, childNodes[i]); styleItem(childNode); } ((IContainer) node).applyLayout(); @@ -236,7 +248,8 @@ public GraphNode createNode(Graph graph, Object element) { IFigure nodeFigure = null; if (getLabelProvider() instanceof IFigureProvider) { - nodeFigure = ((IFigureProvider) getLabelProvider()).getFigure(element); + nodeFigure = ((IFigureProvider) getLabelProvider()) + .getFigure(element); } return this.createNode(graph, element, nodeFigure); } @@ -288,7 +301,8 @@ /* * (non-Javadoc) * - * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#refreshGraph(org.eclipse.zest.core.internal.graphmodel.GraphModel) + * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory# + * refreshGraph(org.eclipse.zest.core.internal.graphmodel.GraphModel) */ public void refreshGraph(Graph graph) { // with this kind of graph, it is just as easy and cost-effective to @@ -301,6 +315,13 @@ Object key = keys.next(); nodesMap.put(key, oldMap.get(key)); } + Map oldConnectionMap = viewer.getConnectionsMap(); + HashMap connectionsMap = new HashMap(); + for (Iterator keys = oldConnectionMap.keySet().iterator(); keys + .hasNext();) { + Object key = keys.next(); + connectionsMap.put(key, oldConnectionMap.get(key)); + } clearGraph(graph); doBuildGraph(graph); // update the positions on the new nodes to match the old ones. @@ -308,11 +329,14 @@ // save a little time, go with the smallest list as the primary list if (nodes.length < nodesMap.keySet().size()) { for (int i = 0; i < nodes.length; i++) { - GraphNode oldNode = (GraphNode) nodesMap.get(nodes[i].getData()); + GraphNode oldNode = (GraphNode) nodesMap + .get(nodes[i].getData()); if (oldNode != null) { - nodes[i].setLocation(oldNode.getLocation().x, oldNode.getLocation().y); + nodes[i].setLocation(oldNode.getLocation().x, + oldNode.getLocation().y); if (oldNode.isSizeFixed()) { - nodes[i].setSize(oldNode.getSize().width, oldNode.getSize().height); + nodes[i].setSize(oldNode.getSize().width, + oldNode.getSize().height); } } } @@ -322,12 +346,25 @@ GraphNode node = viewer.getGraphModelNode(key); if (node != null) { GraphNode oldNode = (GraphNode) nodesMap.get(key); - node.setLocation(oldNode.getLocation().x, oldNode.getLocation().y); + node.setLocation(oldNode.getLocation().x, + oldNode.getLocation().y); if (oldNode.isSizeFixed()) { - node.setSize(oldNode.getSize().width, oldNode.getSize().height); + node.setSize(oldNode.getSize().width, + oldNode.getSize().height); } } } + for (Iterator i = connectionsMap.keySet().iterator(); i.hasNext();) { + Object key = i.next(); + GraphConnection connection = viewer + .getGraphModelConnection(key); + if (connection != null) { + GraphConnection oldConnection = (GraphConnection) connectionsMap + .get(key); + connection.setRoutingConstraint(oldConnection + .getRoutingConstraint()); + } + } } } @@ -382,7 +419,8 @@ /* * (non-Javadoc) * - * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#isFiltered(java.lang.Object) + * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory# + * isFiltered(java.lang.Object) */ protected Object[] filter(Object parent, Object[] elements) { Object[] result = elements; @@ -396,8 +434,9 @@ /* * (non-Javadoc) * - * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#refresh(org.eclipse.zest.core.internal.graphmodel.GraphModel, - * java.lang.Object) + * @see + * org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#refresh + * (org.eclipse.zest.core.internal.graphmodel.GraphModel, java.lang.Object) */ public void refresh(Graph graph, Object element) { refresh(graph, element, false); @@ -415,13 +454,17 @@ } /** - * Converts the list of GraphConnections objects into an array and return it. + * Converts the list of GraphConnections objects into an array and return + * it. + * * @param graph * @return */ protected GraphConnection[] getConnectionArray(Graph graph) { - GraphConnection[] connectionArray = new GraphConnection[graph.getConnections().size()]; - connectionArray = (GraphConnection[]) graph.getConnections().toArray(connectionArray); + GraphConnection[] connectionArray = new GraphConnection[graph + .getConnections().size()]; + connectionArray = (GraphConnection[]) graph.getConnections().toArray( + connectionArray); return connectionArray; } } Index: src/org/eclipse/zest/core/widgets/GraphConnection.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/GraphConnection.java,v retrieving revision 1.24 diff -u -r1.24 GraphConnection.java --- src/org/eclipse/zest/core/widgets/GraphConnection.java 21 Oct 2011 21:08:11 -0000 1.24 +++ src/org/eclipse/zest/core/widgets/GraphConnection.java 2 Mar 2012 16:34:24 -0000 @@ -9,6 +9,11 @@ ******************************************************************************/ package org.eclipse.zest.core.widgets; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.AbsoluteBendpoint; +import org.eclipse.draw2d.BendpointConnectionRouter; import org.eclipse.draw2d.ChopboxAnchor; import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.Connection; @@ -74,8 +79,10 @@ private boolean highlighted; private GraphLayoutConnection layoutConnection = null; private boolean hasCustomTooltip; + private Object routingConstraint; - public GraphConnection(Graph graphModel, int style, GraphNode source, GraphNode destination) { + public GraphConnection(Graph graphModel, int style, GraphNode source, + GraphNode destination) { super(graphModel, style); this.connectionStyle |= graphModel.getConnectionStyle(); @@ -106,8 +113,11 @@ (source).addSourceConnection(this); (destination).addTargetConnection(this); - if (source.getParent().getItemType() == GraphItem.CONTAINER && destination.getParent().getItemType() == GraphItem.CONTAINER && (source.getParent() == destination.getParent())) { - // 196189: Edges should not draw on the edge layer if both the src and dest are in the same container + if (source.getParent().getItemType() == GraphItem.CONTAINER + && destination.getParent().getItemType() == GraphItem.CONTAINER + && (source.getParent() == destination.getParent())) { + // 196189: Edges should not draw on the edge layer if both the src + // and dest are in the same container // https://bugs.eclipse.org/bugs/show_bug.cgi?id=196189 graphModel.addConnection(this, ZestRootLayer.EDGES_ON_TOP); } else { @@ -115,18 +125,26 @@ } if ((source.getParent()).getItemType() == GraphItem.CONTAINER) { - // If the container of the source is a container, we need to draw another + // If the container of the source is a container, we need to draw + // another // arc on that arc layer sourceContainerConnectionFigure = doCreateFigure(); - ((GraphContainer) source.getParent()).addConnectionFigure((PolylineConnection) sourceContainerConnectionFigure); + ((GraphContainer) source.getParent()) + .addConnectionFigure((PolylineConnection) sourceContainerConnectionFigure); this.setVisible(false); } - if ((destination.getParent()).getItemType() == GraphItem.CONTAINER) { //&& src_destSameContainer == false) { - // If the container of the source is a container, we need to draw another + if ((destination.getParent()).getItemType() == GraphItem.CONTAINER) { // && + // src_destSameContainer + // == + // false) + // { + // If the container of the source is a container, we need to draw + // another // arc on that arc layer targetContainerConnectionFigure = doCreateFigure(); - ((GraphContainer) destination.getParent()).addConnectionFigure((PolylineConnection) targetContainerConnectionFigure); + ((GraphContainer) destination.getParent()) + .addConnectionFigure((PolylineConnection) targetContainerConnectionFigure); this.setVisible(false); } graphModel.getGraph().registerItem(this); @@ -135,18 +153,21 @@ void removeFigure() { if (connectionFigure.getParent() != null) { if (connectionFigure.getParent() instanceof ZestRootLayer) { - ((ZestRootLayer) connectionFigure.getParent()).removeConnection(connectionFigure); + ((ZestRootLayer) connectionFigure.getParent()) + .removeConnection(connectionFigure); } else { connectionFigure.getParent().remove(connectionFigure); } } connectionFigure = null; if (sourceContainerConnectionFigure != null) { - sourceContainerConnectionFigure.getParent().remove(sourceContainerConnectionFigure); + sourceContainerConnectionFigure.getParent().remove( + sourceContainerConnectionFigure); sourceContainerConnectionFigure = null; } if (targetContainerConnectionFigure != null) { - targetContainerConnectionFigure.getParent().remove(targetContainerConnectionFigure); + targetContainerConnectionFigure.getParent().remove( + targetContainerConnectionFigure); targetContainerConnectionFigure = null; } @@ -159,10 +180,12 @@ (getDestination()).removeTargetConnection(this); graphModel.removeConnection(this); if (sourceContainerConnectionFigure != null) { - sourceContainerConnectionFigure.getParent().remove(sourceContainerConnectionFigure); + sourceContainerConnectionFigure.getParent().remove( + sourceContainerConnectionFigure); } if (targetContainerConnectionFigure != null) { - targetContainerConnectionFigure.getParent().remove(targetContainerConnectionFigure); + targetContainerConnectionFigure.getParent().remove( + targetContainerConnectionFigure); } } @@ -204,7 +227,8 @@ public String toString() { String arrow = (isBidirectionalInLayout() ? " <--> " : " --> "); String src = (sourceNode != null ? sourceNode.getText() : "null"); - String dest = (destinationNode != null ? destinationNode.getText() : "null"); + String dest = (destinationNode != null ? destinationNode.getText() + : "null"); String weight = " (weight=" + getWeightInLayout() + ")"; return ("GraphModelConnection: " + src + arrow + dest + weight); } @@ -449,16 +473,19 @@ } /** - * Sets the curve depth of the arc. The curve depth is defined as - * the maximum distance from any point on the chord (i.e. a vector - * normal to the chord with magnitude d). - * - * If 0 is set, a Polyline Connection will be used, otherwise a - * PolylineArcConnectoin will be used. Negative depths are also supported. - * @param depth The depth of the curve + * Sets the curve depth of the arc. The curve depth is defined as the + * maximum distance from any point on the chord (i.e. a vector normal to the + * chord with magnitude d). + * + * If 0 is set, a Polyline Connection will be used, otherwise a + * PolylineArcConnectoin will be used. Negative depths are also supported. + * + * @param depth + * The depth of the curve */ public void setCurveDepth(int depth) { - if (this.curveDepth == 0 && depth != 0 || this.curveDepth != 0 && depth == 0) { + if (this.curveDepth == 0 && depth != 0 || this.curveDepth != 0 + && depth == 0) { // There is currently no curve, so we have to create // a curved connection graphModel.removeConnection(this); @@ -484,10 +511,12 @@ /* * (non-Javadoc) * - * @see org.eclipse.mylar.zest.core.internal.graphmodel.GraphItem#setVisible(boolean) + * @see + * org.eclipse.mylar.zest.core.internal.graphmodel.GraphItem#setVisible( + * boolean) */ public void setVisible(boolean visible) { - //graphModel.addRemoveFigure(this, visible); + // graphModel.addRemoveFigure(this, visible); if (getSource().isVisible() && getDestination().isVisible() && visible) { this.getFigure().setVisible(visible); if (sourceContainerConnectionFigure != null) { @@ -559,7 +588,7 @@ connectionShape.setLineStyle(getLineStyle()); if (this.getText() != null || this.getImage() != null) { - //Label l = new Label(this.getText(), this.getImage()); + // Label l = new Label(this.getText(), this.getImage()); if (this.getImage() != null) { this.connectionLabel.setIcon(this.getImage()); } @@ -593,28 +622,33 @@ } IFigure toolTip; - if (this.getTooltip() == null && getText() != null && getText().length() > 0 && hasCustomTooltip == false) { + if (this.getTooltip() == null && getText() != null + && getText().length() > 0 && hasCustomTooltip == false) { toolTip = new Label(); ((Label) toolTip).setText(getText()); } else { toolTip = this.getTooltip(); } connection.setToolTip(toolTip); + + if (routingConstraint != null) { + connection.setRoutingConstraint(routingConstraint); + } } private Connection createFigure() { /* - if ((sourceNode.getParent()).getItemType() == GraphItem.CONTAINER) { - GraphContainer container = (GraphContainer) sourceNode.getParent(); - sourceContainerConnectionFigure = doCreateFigure(); - container.addConnectionFigure((PolylineConnection) sourceContainerConnectionFigure); - } - if ((destinationNode.getParent()).getItemType() == GraphItem.CONTAINER) { - GraphContainer container = (GraphContainer) destinationNode.getParent(); - targetContainerConnectionFigure = doCreateFigure(); - container.addConnectionFigure((PolylineConnection) targetContainerConnectionFigure); - } - */ + * if ((sourceNode.getParent()).getItemType() == GraphItem.CONTAINER) { + * GraphContainer container = (GraphContainer) sourceNode.getParent(); + * sourceContainerConnectionFigure = doCreateFigure(); + * container.addConnectionFigure((PolylineConnection) + * sourceContainerConnectionFigure); } if + * ((destinationNode.getParent()).getItemType() == GraphItem.CONTAINER) + * { GraphContainer container = (GraphContainer) + * destinationNode.getParent(); targetContainerConnectionFigure = + * doCreateFigure(); container.addConnectionFigure((PolylineConnection) + * targetContainerConnectionFigure); } + */ return doCreateFigure(); @@ -628,7 +662,8 @@ Locator labelLocator = null; if (getSource() == getDestination()) { - // If this is a self loop, create a looped arc and put the locator at the top + // If this is a self loop, create a looped arc and put the locator + // at the top // of the connection connectionFigure = new PolylineArcConnection(); sourceAnchor = new LoopAnchor(getSource().getNodeFigure()); @@ -637,19 +672,23 @@ protected Point getReferencePoint() { Point p = Point.SINGLETON; p.x = getConnection().getPoints().getPoint(getIndex()).x; - p.y = (int) (getConnection().getPoints().getPoint(getIndex()).y - (curveDepth * 1.5)); + p.y = (int) (getConnection().getPoints().getPoint( + getIndex()).y - (curveDepth * 1.5)); return p; } }; } else { if (curveDepth != 0) { connectionFigure = new PolylineArcConnection(); - ((PolylineArcConnection) connectionFigure).setDepth(this.curveDepth); + ((PolylineArcConnection) connectionFigure) + .setDepth(this.curveDepth); } else { connectionFigure = new PolylineConnection(); } - sourceAnchor = new RoundedChopboxAnchor(getSource().getNodeFigure(), 8); - targetAnchor = new RoundedChopboxAnchor(getDestination().getNodeFigure(), 8); + sourceAnchor = new RoundedChopboxAnchor( + getSource().getNodeFigure(), 8); + targetAnchor = new RoundedChopboxAnchor(getDestination() + .getNodeFigure(), 8); labelLocator = new MidpointLocator(connectionFigure, 0); } @@ -658,16 +697,21 @@ connectionFigure.add(this.connectionLabel, labelLocator); doUpdateFigure(connectionFigure); + + connectionFigure.setConnectionRouter(new BendpointConnectionRouter()); return connectionFigure; } /* * (non-Javadoc) * - * @see org.eclipse.mylar.zest.layouts.LayoutRelationship#isBidirectionalInLayout() + * @see + * org.eclipse.mylar.zest.layouts.LayoutRelationship#isBidirectionalInLayout + * () */ private boolean isBidirectionalInLayout() { - return !ZestStyles.checkStyle(connectionStyle, ZestStyles.CONNECTIONS_DIRECTED); + return !ZestStyles.checkStyle(connectionStyle, + ZestStyles.CONNECTIONS_DIRECTED); } class GraphLayoutConnection implements LayoutRelationship { @@ -675,7 +719,7 @@ Object layoutInformation = null; public void clearBendPoints() { - // @tag TODO : add bendpoints + routingConstraint = null; } public LayoutEntity getDestinationInLayout() { @@ -691,11 +735,17 @@ } public void populateLayoutConstraint(LayoutConstraint constraint) { - graphModel.invokeConstraintAdapters(GraphConnection.this, constraint); + graphModel.invokeConstraintAdapters(GraphConnection.this, + constraint); } public void setBendPoints(LayoutBendPoint[] bendPoints) { - // @tag TODO : add bendpoints + List list = new ArrayList(); + for (int i = 0; i < bendPoints.length; i++) { + list.add(new AbsoluteBendpoint((int) bendPoints[i].getX(), + (int) bendPoints[i].getY())); + } + setRoutingConstraint(list); } public void setLayoutInformation(Object layoutInformation) { @@ -712,6 +762,24 @@ } + /** + * Sets the routing constraint + * + * @param cons + * The routing constraint + */ + public void setRoutingConstraint(Object cons) { + routingConstraint = cons; + updateFigure(connectionFigure); + } + + /** + * @return the routingConstraint + */ + public Object getRoutingConstraint() { + return routingConstraint; + } + IFigure getFigure() { return this.getConnectionFigure(); }