Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to get an IContributionItem from the main menu
How to get an IContributionItem from the main menu [message #487944] Fri, 25 September 2009 00:02 Go to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 92
Registered: July 2009
Member
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 #489177 is a reply to message #487944] Thu, 01 October 2009 17:27 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 92
Registered: July 2009
Member
Is there no way of doing this? I still couldnt find a way.

Marc Schlegel schrieb:
> 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 #489202 is a reply to message #487944] Thu, 01 October 2009 19:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

There's no suggested way to get IContributionItems from the main menu or main toolbar. You've found a way in the toolbar case although it's not always guarantee to work (since the IMenuService makes the dynamic in some cases).

For the main menu, some parts aren't even instantiated until the first time that particular SWT Menu is about to show.

As an aside, an IContributionItem cannot be executed, it's more in the nature of a renderer for a specific SWT Item.

The short answer is there is no way to get that information.

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.

PW


Re: How to get an IContributionItem from the main menu [message #489397 is a reply to message #489202] Fri, 02 October 2009 19:08 Go to previous message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 92
Registered: July 2009
Member
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
Previous Topic:no launcher executable in generated RCP app
Next Topic:Re: Where to get started with RCP?
Goto Forum:
  


Current Time: Thu Dec 18 04:08:00 GMT 2014

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

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