Search code examples
eclipseeclipse-gefdraw2d

Eclipse GEF FanRouter


I am using GEF to create a tool that visualises dependencies between files. I successfully managed to do the connections between nodes and I can also switch the functionality to use the ManhattenConnectionRouter.

However I find trouble using the FanRouter.

I tried following the logic example that GEF provides, but I still have problems. Unfortunately there is no other tutorial that shows how to implement a FanRouter.

Here are excerpts of my code:

The base class, implementing the FreeformLayer:

public class DependencyGraphPart extends AbstractGraphicalEditPart implements LayerConstants {

    private DependencyGraphAdapter adapter;

    public DependencyGraphPart(){
        super();
        adapter = new DependencyGraphAdapter();
    }

    @Override protected IFigure createFigure() {
        FreeformLayer layer = new FreeformLayer();
        layer.setLayoutManager(new FreeformLayout());
        layer.setBorder(new LineBorder(1));

        return layer;
    }

    @Override protected void refreshVisuals(){
        ConnectionLayer cLayer = (ConnectionLayer) getLayer(CONNECTION_LAYER);
        cLayer.setAntialias(SWT.ON);
        AutomaticRouter frouter = new FanRouter();
        cLayer.setConnectionRouter(frouter);
    }

And here my ConnectionClass:

public class DCDependencyPart extends AbstractConnectionEditPart{       
    private DCDependencyAdapter adapter;
    private Label label;

    public DCDependencyPart() {
        super();
        adapter = new DCDependencyAdapter();
    }

    @Override protected void createEditPolicies() {
        installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new ConnectionEndpointEditPolicy());
    }

    @Override
    protected IFigure createFigure(){
        PolylineConnection conn = new PolylineConnection();
        conn.setLineWidth(conn.getLineWidth()*2);
        conn.setConnectionRouter(new FanRouter());
        conn.setTargetDecoration(new PolylineDecoration());
        conn.setToolTip(new TooltipFigure());

        label = new Label("1"); 
        label.setOpaque(true); 
        label.setBackgroundColor(ColorConstants.buttonLightest); 
        label.setBorder(new LineBorder()); 
        conn.add(label, new MidpointLocator (conn, 0)); 

        return conn;
    }

When I tried to implement the ManhattenConnectionRouter I had no problems doing so by just adding it to the Connection-class. (No modification of the DependencyGraphPart)

These are the two places where I make actively usage of any Router. Unfortunately I don't know draw2d and/or GEF well enough to find my problem.


Solution

  • FanRouter is the router for handling collisions. It requires the "next" router which can be BendpointConnectionRouter for example that would do the all the hard work for laying out a connection. Once Fanrouter is laying out a connection it would first use the "next" router to do the actual connection layout and after that would check if this connection overlaps with any other connections with the same source and target and if yes it would introduce extra bendpoints to ensure conneftions don't overlap each other. Below is the example of proper usage of FanRouter:

    AutomaticRouter router = new FanRouter();
    router.setNextRouter(new BendpointConnectionRouter());
    connectionLayer.setConnectionRouter(router);