Skip to content

Commit

Permalink
Added support for setting connection routers for graph connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ujhelyiz committed Jun 28, 2011
1 parent 66581d1 commit c1a6902
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
54 changes: 54 additions & 0 deletions org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.eclipse.draw2d.Animation;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.ConnectionRouter;
import org.eclipse.draw2d.CoordinateListener;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.FreeformLayer;
Expand Down Expand Up @@ -103,6 +104,8 @@ public class Graph extends FigureCanvas implements IContainer {
private ScalableFreeformLayeredPane rootlayer;
private ZestRootLayer zestRootLayer;

private ConnectionRouter defaultConnectionRouter;

/**
* Constructor for a Graph. This widget represents the root of the graph,
* and can contain graph items such as graph nodes and graph connections.
Expand Down Expand Up @@ -1255,4 +1258,55 @@ public DisplayIndependentRectangle getLayoutBounds() {
return new DisplayIndependentRectangle(0, 0, preferredSize.width,
preferredSize.height);
}

/**
* Sets the default connection router for the graph view, but does not apply
* it retroactively.
*
* @param defaultConnectionRouter
* @since 2.0
*/
public void setDefaultConnectionRouter(
ConnectionRouter defaultConnectionRouter) {
this.defaultConnectionRouter = defaultConnectionRouter;
}

/**
* Returns the default connection router for the graph view.
*
* @return the default connection router; may be null.
* @since 2.0
*/
public ConnectionRouter getDefaultConnectionRouter() {
return defaultConnectionRouter;
}

/**
* Sets the default connection router for all connections that have no
* connection routers attached to them.
*
* @since 2.0
*/
public void applyConnectionRouter() {
// for (GraphConnection conn : getConnections()){
Iterator iterator = getConnections().iterator();
while (iterator.hasNext()) {
GraphConnection conn = (GraphConnection) iterator.next();
conn.getConnectionFigure().setConnectionRouter(
defaultConnectionRouter);
}
this.getRootLayer().getUpdateManager().performUpdate();
}

/**
* Updates the deafult connection router and applies to to all existing
* connections that have no connection routers set to them.
*
* @param defaultConnectionRouter
* @since 2.0
*/
public void applyConnectionRouter(ConnectionRouter defaultConnectionRouter) {
setDefaultConnectionRouter(defaultConnectionRouter);
applyConnectionRouter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionRouter;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
Expand Down Expand Up @@ -73,6 +74,8 @@ public class GraphConnection extends GraphItem {
private boolean highlighted;
private boolean hasCustomTooltip;

private ConnectionRouter router = null;

public GraphConnection(Graph graphModel, int style, GraphNode source,
GraphNode destination) {
super(graphModel, style);
Expand Down Expand Up @@ -614,6 +617,9 @@ private void doUpdateFigure(Connection connection) {
PolylineArcConnection arcConnection = (PolylineArcConnection) connection;
arcConnection.setDepth(curveDepth);
}
if (connectionFigure != null) {
applyConnectionRouter(connectionFigure);
}
if ((connectionStyle & ZestStyles.CONNECTIONS_DIRECTED) > 0) {
PolygonDecoration decoration = new PolygonDecoration();
if (getLineWidth() < 3) {
Expand Down Expand Up @@ -667,6 +673,7 @@ protected Point getReferencePoint() {
} else {
connectionFigure = new PolylineConnection();
}
applyConnectionRouter(connectionFigure);
sourceAnchor = new RoundedChopboxAnchor(
getSource().getNodeFigure(), 8);
targetAnchor = new RoundedChopboxAnchor(getDestination()
Expand Down Expand Up @@ -736,4 +743,17 @@ void applyLayoutChanges() {
layout.applyLayout();
}
}

/**
* Sets the connection router
*
* @param conn
*/
void applyConnectionRouter(Connection conn) {
if (router != null) {
conn.setConnectionRouter(router);
} else if (graph.getDefaultConnectionRouter() != null) {
conn.setConnectionRouter(graph.getDefaultConnectionRouter());
}
}
}

0 comments on commit c1a6902

Please sign in to comment.