Skip to main content



      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] Thu, 24 September 2009 20:02 Go to next message
Eclipse UserFriend
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 13:27 Go to previous messageGo to next message
Eclipse UserFriend
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 15:55 Go to previous messageGo to next message
Eclipse UserFriend
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 15:08 Go to previous message
Eclipse UserFriend
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: Tue Jul 22 18:40:18 EDT 2025

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

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

Back to the top