Question

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?

Was it helpful?

Solution

In the Debug Visualization project we added a double click listener while the dragging support remained.

Our code is at line 159 in http://code.google.com/a/eclipselabs.org/p/debugvisualisation/source/browse/hu.cubussapiens.debugvisualisation/src/hu/cubussapiens/debugvisualisation/views/DebugVisualisationView.java:

  // double click on nodes
  graphViewer.getGraphControl().addMouseListener(new MouseAdapter() {

          @Override
          public void mouseDoubleClick(MouseEvent e) {
                 toggleOpen.run();
          }
  });

You could either read the selected node from the MouseEvent (if I am not mistaken), or you could check for the current selection (that is the approach we haven taken in the project).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top