0

I'm creating a graph using the visualization toolkit Zest. I start by creating a graph then I add a node. I want to add to this node a mouse Double click event. I tried the following code, but it doesn't work. Is it because of the verification e.button == 3?

[...]
Graph graph = new Graph(parent, SWT.BORDER);

graph.addListener(SWT.MouseDown, new Listener() {
    public void handleEvent(Event e) {
        if (e.button == 3) {

            Menu menu = new Menu(parent);
            final MenuItem a1 = new MenuItem(menu, SWT.None);
            a1.setText("New Node");
            a1.addSelectionListener(new SelectionListener() {
                                @Override
                public void widgetSelected(SelectionEvent e) {
                                  GraphNode graphNode = new GraphNode(graph, SWT.NONE);
                                  graphNode.addListener(SWT.MouseDoubleClick, new Listener
                                         (
                                           @Override
                       public void handleEvent(Event event) {
                                               System.out.println("node created");});

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {}
                    }
           }
});

Thank you

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

0

Try using MouseAdapter instead of untyped Listener. And override its mouseDoubleClick(MouseEvent e) method.

upd. how about

graph.addMouseListener(new MouseListener(){

     @Override
     public void mouseDoubleClick(MouseEvent arg0)
     {
          // TODO Auto-generated method stub
     }
     ...
}
Alex Stybaev
  • 4,623
  • 3
  • 30
  • 44
  • I tried using this, and I had this message : The method addListener(int, Listener) in the type Widget is not applicable for the arguments (int, new MouseAdapter(){}) – user1338839 Apr 18 '12 at 12:00
  • the one in the package : org.eclipse.draw2d.MouseListener ? it asks me to cast my GraphNode to a Ifigure !! I tried it before, but I can't drag my node anymore! because I have to override the following methods : - public void mouseDoubleClicked(org.eclipse.draw2d.MouseEvent arg0) {} - public void mousePressed(org.eclipse.draw2d.MouseEvent arg0) {} - public void mouseReleased(org.eclipse.draw2d.MouseEvent arg0) {} – user1338839 Apr 18 '12 at 13:01
  • I think, Alex meant the swt MouseAdapter class. – Zoltán Ujhelyi Jun 09 '12 at 11:14