How to get an IContributionItem from the main menu [message #487944] |
Thu, 24 September 2009 20:02  |
Eclipse User |
|
|
|
Hi
I am contributing my menus completely with the org.eclipse.ui.menus
extensionpoint for my rcp.
In order to test my menus (and handlers) with junit, I need to get a reference
to a particular IContributionItem. My problem now is, I cannot figure out a way
how I can get the main menu. It is no problem for view-menus (-toolbars, etc.).
IContributionItem newMenuItem = myView.getViewSite()
..getActionBars().getToolBarManager().find("my.view.id");
I am looking for something similar to that and I tried some ways, like
workbench.getActiveWorkbenchWindow().getShell().getMenu/getM enuBar
or via a ServiceLocator
IMenuService menuServive = (IMenuService) PlatformUI.getWorkbench()
..getActiveWorkbenchWindow().getService(IMenuService.class);
but both ways didnt give me the easy way of finding my contributionitem via the id.
I want to test this menus, first to learn TDD :-D, but also to bring my
application into a certain state, and test automatically if my menus are enabled
or not (according to the expressions).
regards
|
|
|
|
|
Re: How to get an IContributionItem from the main menu [message #489397 is a reply to message #489202] |
Fri, 02 October 2009 15:08  |
Eclipse User |
|
|
|
Thanks for your answer Paul, now I dont need to waste more time on that.
Paul Webster schrieb:
> While I don't recommend it, If your menu has been instantiated you can
> use shell.getMenuBar() and walk the SWT Menu/MenuItem hierarchy until
> your find items you want.
I got that far on one point but as you say, it just didnt seem right.
I will try to test direclty against the handlers then (active or not)
according to the state of the application.
have a nice weekend
Marc
|
|
|
Powered by
FUDForum. Page generated in 0.58829 seconds