Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » ControlContribution Does not fire MouseTrackListener
ControlContribution Does not fire MouseTrackListener [message #1016316] Wed, 06 March 2013 01:38 Go to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 69
Registered: April 2012
Member
I've subclassed ControlContribution, and added a MouseTrackListener to the Control that is created in ControlContribution#createControl. When I move the mouse over the ControlContribution on the toolbar, the listener does not fire. I also tried adding a MouseListener to the Control, and a SelectionListener as well (the Control is a Button). In all these cases the listener does not fire. The strange thing is this used to work, and suddenly it's not. I've looked all through my code for the regression and scoured SVN logs, to no avail. Does anyone have any idea what could be preventing this from working? My RCP app is running on a Juno target.

Here's an idea of what I'm doing:

class MyView extends ViewPart {
...
   public void createPartControl(Composite parent) {
      ...
      ToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
      MyControlContribution cc = new MyControlContribution("MyLabel");
      mgr.add(cc);
      getViewSite().getActionBars().updateActionBars();
      cc.getControl().addMouseTrackListener(new MouseTrackAdapter() {
      
          pubic void mouseEnter(MouseEvent event) {
               System.err.println("Mouse Enter"); //does not fire
          }

          pubic void mouseHover(MouseEvent event) {
               System.err.println("Mouse Hover"); //does not fire
          }
      });

      cc.getControl().addMouseListener(new MouseAdapter() {
      
          pubic void mouseDown(MouseEvent event) {
               System.err.println("Mouse Down"); //does not fire
          }
      });

      ((Button) cc.getControl()).addSelectionListener(new SelectionAdapter() {
      
          pubic void widgetSelected(SelectionEvent event) {
               System.err.println("Button Selected"); //does not fire
          }
      });
   ...
   }
}
class MyControlContribution extends ControlContribution {

   Button control;

   public Control createControl(Composite parent) {
     this.control = new Button(parent, SWT.PUSH);
      ...
      return this.control;
   }

   public Control getControl() {
      return this.control;
   }
}

[Updated on: Wed, 06 March 2013 01:51]

Report message to a moderator

MouseListeners on ControlContributions broken in Juno? [message #1016320 is a reply to message #1016316] Wed, 06 March 2013 02:55 Go to previous messageGo to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 69
Registered: April 2012
Member
So I just tried this on Indigo, and it works. So it was the upgrade to Juno that broke it. Don't know if it's a bug, or I need to do something different in Juno.
Re: MouseListeners on ControlContributions broken in Juno? [message #1016326 is a reply to message #1016320] Wed, 06 March 2013 04:07 Go to previous messageGo to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 69
Registered: April 2012
Member
Here's a working example. The following code works in Indigo but not Juno. Create a views extension for the View below, and then hover over the button that appears in the toolbar. In indigo you see console output from the listener firing, but in Juno you don't.

package controlcontribution.test.views;


import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.action.ControlContribution;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.part.ViewPart;


public class SampleView extends ViewPart {

	public static final String ID = "test.views.SampleView";

	private MyControlContribution cc;

	class MyControlContribution extends ControlContribution {
		protected MyControlContribution(String id) {
			super(id);
		}

		Button b;
		private List<MouseTrackListener> deferredListeners = new ArrayList<MouseTrackListener>();
		@Override
		protected Control createControl(Composite parent) {
			b = new Button(parent, SWT.PUSH);
			b.setText("Button");
			for (MouseTrackListener listener : this.deferredListeners) {
				b.addMouseTrackListener(listener);
			}
			this.deferredListeners.clear();
			return b;
		}

		public Control getContro() {
			return b;
		}

		public void addMouseTrackListener(MouseTrackListener listener) {
			if (b != null) {
				this.b.addMouseTrackListener(listener);
			} else {
				this.deferredListeners.add(listener);
			}
		}
		
	};

	public void createPartControl(Composite parent) {
		IActionBars bars = getViewSite().getActionBars();
		cc = new MyControlContribution("ControlContribution");
		bars.getToolBarManager().add(cc);
		cc.addMouseTrackListener(new MouseTrackAdapter() {

			@Override
			public void mouseEnter(MouseEvent e) {
				System.err.println("MOUSE ENTER");
			}
		});
		bars.updateActionBars();
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		
	}
}
Re: MouseListeners on ControlContributions broken in Juno? [message #1032435 is a reply to message #1016326] Wed, 03 April 2013 01:53 Go to previous message
Mark Leone is currently offline Mark LeoneFriend
Messages: 69
Registered: April 2012
Member
I opened this bug on the issue

https://bugs.eclipse.org/bugs/show_bug.cgi?id=402593

The problem seems to be limited to the compatibility layer. I found a workaround using a pure E4 view, an E3 View explicitly added to the E4 workbench model, and an E3 view that wraps an E4 vie and is explicitly added to the workbench model. The code is in this github project.
Previous Topic:jface treeviewer with 2 columns
Next Topic:Remove / Change Highlight-Color of ListViewer
Goto Forum:
  


Current Time: Thu Mar 28 16:15:15 GMT 2024

Powered by FUDForum. Page generated in 0.03121 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top