Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Enable/disable commands
Enable/disable commands [message #559144] Wed, 15 September 2010 18:42 Go to next message
Giddi Ohm is currently offline Giddi OhmFriend
Messages: 10
Registered: September 2010
Junior Member
How do I disable a command based on a state in my program? I have a PLAY command that puts my application in a play-state after the command has been confirmed by the user. I've created a STOP command and put it on a toolbar and assigned a handler to it, but the isEnabled() method isn't called often enough.

The STOP command's isEnabled() method is invoked immediately before and after the dialog is shown (most likely a result of the application window losing and gaining focus), but not after my code has regained control. Hence the stop button is never enabled.

I want to achieve something like this in my PLAY handler:
//state == IDLE;
if(openQuestion(...))
{
setState(PLAYING);
// somehow enable the STOP command
}

I have looked at the command service class but there seems to be no method of triggering an enable-evaluation of all commands. I've tried with and without enabledWhen to no avail.

I have no problems doing this with actions or delegates, but I want to learn how to use commands from the beginning even though the framework seems overly complex for simple applications.

Please advice.
Re: Enable/disable commands [message #559154 is a reply to message #559144] Wed, 15 September 2010 19:22 Go to previous messageGo to next message
eshvar60  is currently offline eshvar60 Friend
Messages: 51
Registered: March 2010
Member
Hey I am actually working on the same issue right now. Where I have to enable/disable commands based on the status of my program.

My solution is this.
The handlers have an enabledWhen/visibleWhen item attached to them. I have a custom PropertyTester which I declaratively send a collection of contexts using the eclipse command framework.(Let me know if you need help setting this up)

My PropertyTester looks at the list of active contexts and returns true or false based on whether the context I need for this command is active or not.

To trigger the revaluation of commands you need to use the IEvaluationService which you can get from the workbench. It has a method called requestEvaluation where you specify the name of the property you want evaluated.

I activate/deactivate contexts using the IContextService and I have it set up in PartChangeListners(this is specific to my implementation, you can stick activation of contexts anywhere you need to).

Re: Enable/disable commands [message #632848 is a reply to message #559154] Thu, 14 October 2010 13:35 Go to previous message
Giddi Ohm is currently offline Giddi OhmFriend
Messages: 10
Registered: September 2010
Junior Member
Sounds like a lot of work for something that should be simple, but thanks for the tip Smile I'll check out property testers.

(Sorry for the late reply, but I've been on holiday).
Previous Topic:help on status manager and (a)syncExec
Next Topic:Change RCP application's default font
Goto Forum:
  


Current Time: Sun Nov 23 12:24:26 GMT 2014

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

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