Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Getting a handle to Workbench menu items
Getting a handle to Workbench menu items [message #444409] Wed, 15 February 2006 15:19 Go to next message
Eclipse UserFriend
Hi,

I'm trying to get a handle to the Workbench menus to enable/disable menu
items depending on context. My menus are defined in the plugin.xml:

<extension id="ActionSets"
name="ActionSets"
point="org.eclipse.ui.actionSets">
<actionSet id="actionSet"
label="Actions"
visible="true">
....

<action id="SaveActivatePlanAction"
menubarPath="file/main"
label="%action.saveActive.label"
tooltip="%action.saveActive.label"
class="actions.SaveActivatePlanAction">
</action>

I found this:

this.getViewSite().getActionBars().getMenuManager().getItems ();

(where "this" extends ViewPart), but getItems() returns 0 items. I've also
tried variations on this:

this.getViewSite().getActionBars().getGlobalActionHandler("SaveActivatePlanAction ");

but the result is null.

I've tried navigating all over from PlatformUI, but have not been able to
find the menu I'm looking for (the Workbench "File->Save and activate plan"
menu item).

Any ideas?

Todd
Re: Getting a handle to Workbench menu items [message #444413 is a reply to message #444409] Wed, 15 February 2006 22:31 Go to previous messageGo to next message
Eclipse UserFriend
hi,
Actually by this code you can get the reference of the menu of the view not workbench menu.
getViewSite().getActionBars().getMenuManager().getItems();
I am also searching this since last week.

i found one bug(106750) in eclipse site that we can not get the reference of the actions in the actionsets in our plugin.
Re: Getting a handle to Workbench menu items [message #444490 is a reply to message #444413] Thu, 16 February 2006 18:53 Go to previous message
Eclipse UserFriend
That was not getting what I needed (since the view doesn't actually
contribute any menu items, and those wouldn't be what I need in any case).

I found some more info on getting the menu manager, basically by saving the
reference on construction in a hash:

IMenuManager menuMgr = (IMenuManager)
Plugin.get(ApplicationConstants.MENU_BAR);

Here, iterating through the items in the view that needs to disable them:

for (int i = 0; i < menuMgr.getItems().length; i++) {
if (menuMgr.getItems()[i] instanceof ActionSetContributionItem &&
menuMgr.getItems()[i].getId().equals("file")) {
ActionSetContributionItem item = (ActionSetContributionItem)
menuMgr.getItems()[i];
IContributionItem contribItem = item.getInnerItem();
if (contribItem instanceof MenuManager) {
MenuManager fileMenu = (MenuManager) contribItem;
fileMenu.getMenu().setEnabled(false);
fileMenu.update();
}
}
}

does not actually disable the menu. I realize this cannot be the correct
way to manipulate a specific menu item (esp. since it doesn't work ;) ), but
I am a bit lost...

Todd
Previous Topic:layout.addStandaloneView showTitle=false loses toolbar and menu
Next Topic:How to use PropertyPage in a RCP application
Goto Forum:
  


Current Time: Sat Jul 12 11:57:53 EDT 2025

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

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

Back to the top