Feb 13, 2008

Using ConnectionDragCreationTool in GEF

Connection creation tools in the palette are nice. But the only problem with those is that it would require three mouse clicks from the user. Click the connection creation tool in the palette; the click the source edit part and then finally click the target edit part.

How good if we can simplify this further? Like just drag-n-drop an edit part into another should create a connection between them. Implementing this feature might be much easier than you think. Override the getDragTracker in your source edit part and return the ConnectionDragCreationTool :-)

@Override
public DragTracker getDragTracker(Request request) {
return new ConnectionDragCreationTool();
}

Remember this will be applicable only if your edit parts are not moveable. If they have to be movable in your application, then drag-n-drop should change their position - not create a connection!

[Update]
You cannot select the source edit part, if you use the ConnectionDragCreationTool. The fix is simple:

@Override
public DragTracker getDragTracker(Request request) {
getViewer().select(this);
return new ConnectionDragCreationTool();
}

0 comments: