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