I am currently developing a plugin for eclipse that displays a tree using Zest.
I tried adding a custom MouseListener
to the Figures displaying the nodes, as I wanted to add a double-click functionality, but this overrides the naturally present functionality which allows the Nodes to be dragged around.
I have tried adding Draw2D based functionality for dragging, but it did not work. Here is the code I tried:
private Point location;
public void mousePressed(MouseEvent me) {
location = me.getLocation();
me.consume();
}
public void mouseReleased(MouseEvent me) {
location = null;
me.consume();
}
public void mouseDragged(MouseEvent me) {
if (location == null) {
return;
}
Point moved= me.getLocation();
if (moved == null) {
return;
}
Dimension offset= moved.getDifference(location);
if (offset.width == 0 && offset.height == 0) {
return;
}
location= moved;
UpdateManager uMgr= figure.getUpdateManager();
LayoutManager lMgr= figure.getLayoutManager();
Rectangle bounds= figure.getBounds();
uMgr.addDirtyRegion(figure.getParent(), bounds);
bounds= bounds.getCopy().translate(offset.width, offset.height);
lMgr.setConstraint(figure, bounds);
figure.translate(offset.width, offset.height);
uMgr.addDirtyRegion(figure.getParent(), bounds);
me.consume();
}
Can anyone provide a fix for my code or a workaround?