Help with commands, handlers and testers. [message #327873] |
Tue, 06 May 2008 23:05 |
Fabio M Messages: 25 Registered: July 2009 |
Junior Member |
|
|
Dear all,
I am using the command framework for managing menu contributions. I have
a common navigator and I use the CommonActionProvider to build a menu
with all the possible commands that are executable when the popup menu
is open on a selection.
The scenario is the following: I have some DataManagers in a tree that
can be connected/disconnected.
So I have two commands connect/disconnect with their respective handlers.
In the CommonActionProvider I create the menu contributions:
CommandContributionItemParameter contributionItemParameter = new
CommandContributionItemParameter(PlatformUI.getWorkbench(),
UIConstants.DATA_MANAGER_CONNECT_COMMAND,
UIConstants.DATA_MANAGER_CONNECT_COMMAND,
0);
connect = new CommandContributionItem(contributionItemParameter);
....
and add them to the menu. Everything works.
Now I would like the connect/disconnect menu items to be
enabled/disabled depending on the state of the DataManager.
I tried with core expressions in plugin.xml.
At first I defined a custom property tester for my DataManager and used
it in test expressions. But the property tester never got instantiated
so I tried to use some already defined expressions: I put some
instanceof tests. What I did is to define the expression with
instanceof=DataManager and instanceof=Somethingelse, expecting the menu
items to be enabled in the first case and disabled in the second. I
tried this with every combination for activeWhen and enabledWhen but it
seems that as soon as I specify an activeWhen or enabledWhen clause,
things stop to work.
If I just specify the handler the two menu items appear enabled and
working but, of course, this is not what I would like.
I ended up in doing things programmatically by hand:
handlerService.activateHandler(UIConstants.DATA_MANAGER_CONN ECT_COMMAND,
new DataManagerConnectHandler(), new Expression() {
@Override
public EvaluationResult evaluate(IEvaluationContext context) throws
CoreException {
//Check if connected then return FALSE else return TRUE
}
});
Same thing for the disconnect command. And everything started to work.
But this is not the way I would like things to be done, since it is a
lot of code (almost 50 lines) for every command that needs a conditional
enablement, instead of a bunch of XML tags.
Now I am wondering why by using expressions specified in plugin.xml
things fails and how can I debug where the problem is or where things go
wrong?
Thanks,
Fabio
|
|
|
|
Powered by
FUDForum. Page generated in 0.03336 seconds