Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Enable/Disable menu items using source provider
Enable/Disable menu items using source provider [message #799983] Thu, 16 February 2012 14:37 Go to next message
Megha Bassi is currently offline Megha BassiFriend
Messages: 3
Registered: February 2012
Junior Member
Hi,

I am working on a project that requires me to contribute menu contributions to a context menu attached to the navigator which I did using the ContributionItems.
The problem statement also requires me to first disable the commands(menu items) and later on enable them depending upon certain conditions.

However, all this needs to be done programmatically. I went through a lot of articles signed Paul Webster and I could gather that I need to use source providers or a property tester since the state needs to be evaluated. Could someone please explain me how I could create variables and use a source provider to enable menu items.
Code snippets would be of great help.

Thanks in advance.
Smile

Re: Enable/Disable menu items using source provider [message #808434 is a reply to message #799983] Mon, 27 February 2012 19:40 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Are you talking about using org.eclipse.ui.menus to place commands (as menu items) in menus? Then the enabled state is controlled by the handler, either programmatically or via org.eclipse.ui.handlers/handler/enabledWhen. Source providers and PropertyTesters are used with enabledWhen.

Or do you mean something else?

PW


Re: Enable/Disable menu items using source provider [message #808922 is a reply to message #808434] Tue, 28 February 2012 09:41 Go to previous messageGo to next message
Megha Bassi is currently offline Megha BassiFriend
Messages: 3
Registered: February 2012
Junior Member
Hi Paul,

Yes I am placing commands as menu items in a context menu in the navigator.
[All this being done using CommandService and HandlerService and ContributionItems].
Currently I enable/disable these items by overriding the setEnabled(*) method in the respective handlers depending on certain conditions.

What I would next want to know is that is there any other way I can do the same which doesn't require me to modify the handlers for these commands.

Also I am not using the org.eclipse.ui.menus extension and all this is done programatically. Do you mean to say that only when I use the ui.handlers extension can I use enabledwhen?
Is there no alternative of using enabledWhen otherwise?

Regards,
Megha
Re: Enable/Disable menu items using source provider [message #809044 is a reply to message #808922] Tue, 28 February 2012 12:28 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You're doing it right. Your handler will control the enabled state, and an outside influence can respond to setEnabled(*). It has to fire a HandlerEvent, but setBaseEnabled(*) will do that for you.

There is no way to use enabledWhen if you are providing handlers programmatically. Only activeWhen (a core expression can be used when activating a handler). But you can just call setEnabled(*).

Another option if you wanted to align with the enabledWhen/visibleWhen/activeWhen is to use the IEvaluationService (which takes a core expression) and have the listener update the handler enabled state for you.

PW


Re: Enable/Disable menu items using source provider [message #814215 is a reply to message #809044] Tue, 06 March 2012 07:09 Go to previous message
Megha Bassi is currently offline Megha BassiFriend
Messages: 3
Registered: February 2012
Junior Member
Thanks Paul for clarifying the doubts. Smile

Regards,
Megha
Previous Topic:What is trim?
Next Topic:Setting a custom classloader for my plug-in
Goto Forum:
  


Current Time: Wed Apr 24 18:34:44 GMT 2024

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

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

Back to the top