Results 1 to 2 of 2
  1. #1
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default [SOLVED] Attaching a mouseListener to a TreeViewer

    I have a treeviewer that reacts to double click and now I need to make it react to right click but I'm not sure if I'm doing this right. My doubleclick listener is this
    Java Code:
    //Double click listener
    treeViewer.addOpenListener(new IOpenListener() {
    	public void open(final OpenEvent event) {
    		Object firstElement = ((IStructuredSelection)event.getSelection()).getFirstElement();
    		String targetName = firstElement.toString();			   
    
    	//...code to determine what view to open...
    		
    		if (treeViewer.getExpandedState(firstElement)) {
    			treeViewer.collapseToLevel(firstElement, AbstractTreeViewer.ALL_LEVELS);
    		} else {
    			treeViewer.expandToLevel(firstElement, 1);
    	        	}
    		}
    	});
    and this is what I have for my mouse listener
    Java Code:
    treeViewer.getTree().addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent e){
    		if(e.button==1){
    			System.out.println("1 Pressed");
    		}
    		if(e.button==2){
    			System.out.println("2 pressed");
    		}
    		if(e.button==3){
    			System.out.println("3 pressed");
    		}
    	}
    });
    everything compiles but when I single click somewhere in the tree nothing happens. I came across this website Java Programming: Section 6.4 and was reading over the MouseEvent and MouseListener section and came across the isMetaPressed() method which is exactly what I need but there were incompatibilities between java.awt.event and org.eclipse.swt.events when trying to use MouseAdapter. This method becomes undefined for Type MouseEvent when I import org.eclipse.swt.events so I tried using java.awt.event instead and that method works but addMouseListener iin type Control is not applicable for the arguments new MouseAdapter(){} so the entire listener dies.

    I'm curious if I need to attach my mouse listener to my selection listener and how I would manage that or if I'm going about this the right way and just doing something wrong.

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    wow just wow. The entire time I was trying trying to use mousePressed instead of mouseDown >_<

Similar Threads

  1. Attaching the Java documentation
    By Eranga in forum NetBeans
    Replies: 11
    Last Post: 08-09-2010, 04:17 AM
  2. SWT treeviewer
    By sushistix in forum SWT / JFace
    Replies: 4
    Last Post: 10-28-2008, 09:25 PM
  3. Attaching a drop-down box within a view(not toolbar)
    By xcallmejudasx in forum Eclipse
    Replies: 1
    Last Post: 10-28-2008, 06:59 PM
  4. TreeViewer Demonstration
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:54 PM
  5. [SOLVED] Attaching/Including extra package
    By Eranga in forum NetBeans
    Replies: 16
    Last Post: 07-01-2008, 10:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •