Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Help with commands, handlers and testers.
Help with commands, handlers and testers. [message #327873] Tue, 06 May 2008 23:05 Go to next message
Fabio M is currently offline Fabio MFriend
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
Re: Help with commands, handlers and testers. [message #327881 is a reply to message #327873] Wed, 07 May 2008 09:16 Go to previous message
Fabio M is currently offline Fabio MFriend
Messages: 25
Registered: July 2009
Junior Member
Fabio Mancinelli wrote:

> 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?
>

Problem solved :)

Actually the problem was that I had to *iterate* on selected elements,
because the object the expression is evaluated against is the current
selection, and the current selection is a collection! That's why my
instanceof tests failed.

By using a custom property tester for DataManager objects that exports
the isConnected property and the following expression:

<activeWhen>
<iterate operator="and">
<test forcePluginActivation="true"
property="DataManager.isConnected" value="true">
</test>
</iterate>
</activeWhen>

Everything works perfectly.

Never code 'till late at night :)

Thank you and sorry for the noise.

Cheers,
Fabio
Previous Topic:Simple java editor
Next Topic:On pressing enter in a text box the cursor goes to the first position
Goto Forum:
  


Current Time: Thu Dec 26 19:24:14 GMT 2024

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

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

Back to the top