Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Adding a menu listener
Adding a menu listener [message #794075] Wed, 08 February 2012 22:22 Go to next message
Josh Davis is currently offline Josh DavisFriend
Messages: 20
Registered: August 2011
Junior Member
Is there a way to listen for the part menu about to be shown?

With a IMenuManager I could add a menu listener to listen for menuAboutToShow. I would like to do something similar with a MMenu that is used as a the Part Menu

I tried this ...
final ESelectionService eSelectionService = mPart.getContext().get(ESelectionService.class);
final ISelectionListener listener = new ISelectionListener() {

Override
public void selectionChanged(final MPart part, final Object selection) {
   System.out.println("Made it here");
}
};
eSelectionService.addSelectionListener(mPart.getElementId(), listener);


But it wasn't called when I went to open the part menu.

I started looking at the renderer code to see how the renderer was triggered. I saw that the renderer is putting some listeners on the widget of the menu or menu item. I tried doing mMenu.getWidget() but it is null when I am building out my part.

Is it possible to capture the "about to show" event for MMenu? I know there has to be something that notifies the renderer that it is time to show the menu but I haven't been able to locate it yet. Any ideas or suggestions?


Edit: I found that the renderer creates EventHandlers and adds them to the IEventBroker. There is a handler that is called for the event TOBERENDERED when the part menu is selected. The instance of the EventBroker is retrieved using injection.

final IEventBroker eventManager = (IEventBroker) mPart.getContext().get(IEventBroker.class.getName());
final EventHandler toBeRenderedUpdater = new EventHandler() {
            public void handleEvent(final Event event) {
                final Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
                final String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
            }
};
eventManager.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC), toBeRenderedUpdater);


The above code catches the event when I go to open the part menu, however this logic also catches tons of events. I doubt that this is a very optimal solution. Not sure how this will behave if I change the items in the menu, they may already be rendered.


[Updated on: Wed, 08 February 2012 23:14]

Report message to a moderator

Re: Adding a menu listener [message #809052 is a reply to message #794075] Tue, 28 February 2012 12:39 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I don't believe there's a way to listen for the SWT.Show event (well, the model equivalent) at the moment.

Ideally the model would include a model element that provides an appropriate callback when it's rendered, so it could update the model.

You can open a bug https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform&component=UI

PW


PW


Previous Topic:Customize perspective doesn't exist anymore ?
Next Topic:@Preference & PreferenceStore
Goto Forum:
  


Current Time: Thu Apr 25 14:03:58 GMT 2024

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

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

Back to the top