Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Disable whole menu (not a separate menu item)
Disable whole menu (not a separate menu item) [message #671967] Thu, 19 May 2011 13:37 Go to next message
arkadyz  is currently offline arkadyz Friend
Messages: 16
Registered: March 2011
Junior Member
Hi,

I have a menu. I would like to disable it programmatically. I know it is possible for a separate menu item, but haven't find how to disable the whole menu.

I am trying the following code:

IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow();

MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
MenuManager fixActionsMenu = (MenuManager)menuManager.find("my menu id");
fixActionsMenu.getMenu().setEnabled( false);

It doesn't work. Can anybody help ?

Thank you,
Arkady.
Re: Disable whole menu (not a separate menu item) [message #671980 is a reply to message #671967] Thu, 19 May 2011 13:56 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I'll just mention that your code is hacking into eclipse internals, and while it might currently work in 3.6 and possibly even 3.7, it won't work in Eclipse 4.0 or 4.1.

You are also trying to bypass the MenuManager's possible handling of its SWT widget. It can be disposed or re-created based on the algorithms used in the main menu bar.

MenuManager does allow for making its Menu disappear. That might be a better bet for you, using MenuManager.setVisible(false)

How did you contribute this menu in the first place? In your ActionBarAdvisor?

PW


Re: Disable whole menu (not a separate menu item) [message #672240 is a reply to message #671980] Fri, 20 May 2011 12:35 Go to previous messageGo to next message
arkadyz  is currently offline arkadyz Friend
Messages: 16
Registered: March 2011
Junior Member
Paul, thank you for answer.

I contributed by menu first in plugin.xml

I don't have ActionBarAdvisor in this plug-in (I have ActionBarAdvisor in the "main" plugin for my RCP application and this "main" plugin doesn't know nothing about all the rest plugins).

I don't want to hide the menu, I want to enable/disable it programmatically according to some conditions. This is demand of my customer. But if you say it is impossible, I can try to persuade the customer.

My Eclipse is:

Eclipse SDK

Version: 3.6.2
Build id: M20110210-1200

Thank you,
Arkady.
Re: Disable whole menu (not a separate menu item) [message #672253 is a reply to message #672240] Fri, 20 May 2011 13:03 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

It's impossible to do it while using any of the API or standard RCP mechanisms in eclipse. You can hack part way there in 3.x, but then that won't work when you finally move to 4.x.

If you cannot convince your customer, there is potentially another option. Use org.eclipse.ui.menus and the <dynamic/> menu contribution in place of the <menu/> element.

You can write your own org.eclipse.jface.action.ContributionItem (painful, but you get to provide either a SWT MenuItem with an SWT Menu or a disabled one with a label) or use org.eclipse.ui.actions.CompoundContributionItem (and alternately provide a MenuManager or a disabled action in an ActionContributionItem) ... these are both hacks. But potentially more reliable then what you are trying to do.

PW


Re: Disable whole menu (not a separate menu item) [message #672277 is a reply to message #672253] Fri, 20 May 2011 14:09 Go to previous messageGo to next message
arkadyz  is currently offline arkadyz Friend
Messages: 16
Registered: March 2011
Junior Member
I have another idea:

I have just saw <menu/> element has "commandid" attribute. So, I can create a command with empty handler (i.e it's "execute" function doesn't do nothing), assign this command to menu, and enable/disable command's handler by a variable using org.eclipse.ui.services

Will try next week and let you know.

Thank you for your time anyway.

Arkady.
Re: Disable whole menu (not a separate menu item) [message #672283 is a reply to message #672277] Fri, 20 May 2011 14:19 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

arkadyz wrote on Fri, 20 May 2011 10:09
I have another idea:

I have just saw <menu/> element has "commandid" attribute.



That command ID is just to identify a shortcut for menus that can be opened separately. Ex, ALT+SHIFT+T opens a local refactor context menu and so should be listed on the main context menu. It won't do what you expect.

PW


Previous Topic:Standalone view not resizable
Next Topic:How to enable the "Save" Command in the EMF Editor
Goto Forum:
  


Current Time: Fri Mar 29 00:30:42 GMT 2024

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

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

Back to the top