Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » enable/disable commands handler(enable/disable commands handler)
enable/disable commands handler [message #674293] Thu, 26 May 2011 12:47 Go to next message
Gennady Gromov is currently offline Gennady GromovFriend
Messages: 24
Registered: May 2011
Junior Member
Hi all!
I am a beginner in eclipse RCP.
I am trying to use AbstractHandler.setBaseEnabled() for control of the handler state. But it is not enough clear how to call this method externally because it is private.
May be there is another way to control of enable state of handler programmically at runtime?
Re: enable/disable commands handler [message #674306 is a reply to message #674293] Thu, 26 May 2011 13:18 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

What are you trying to do? What behaviour do you want? i.e. The command is enabled when a database connection is open? The command is enabled when the user selects a file? an object?

What contributes your handler? plugin.xml? A view that uses IHandlerService?

PW


Re: enable/disable commands handler [message #674469 is a reply to message #674306] Fri, 27 May 2011 04:25 Go to previous messageGo to next message
Gennady Gromov is currently offline Gennady GromovFriend
Messages: 24
Registered: May 2011
Junior Member
At runtime in my application there are different situations which are not relating to workbench. According with these states I should change the status of menu/toolbar commands (items): visible, enabled, text and icon.
I know about the "enableWhen" and "activeWhen" conditions for the commands in plugin.xml but it supports only the workbench status.
This easiest question becomes to very big problem Sad
Re: enable/disable commands handler [message #674562 is a reply to message #674469] Fri, 27 May 2011 11:19 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

ALGROM wrote on Fri, 27 May 2011 00:25
At runtime in my application there are different situations which are not relating to workbench. According with these states I should change the status of menu/toolbar commands (items): visible, enabled, text and icon.
I know about the "enableWhen" and "activeWhen" conditions for the commands in plugin.xml but it supports only the workbench status.


You didn't really answer my questions, and that makes it difficult to actually help you. But I'll make 4 assumptions and provide an answer anyway Smile


visibleWhen, enabledWhen and activeWhen are core expressions, which support property testers [1] [2]. You can write a property tester that examines your "situations" and returns the correct enabled state. When your "situation" changes, you use org.eclipse.ui.services.IEvaluationService.requestEvaluation(String) to have the framework re-evaluate those expressions (updating the commands).

To update text and icons, your handler needs to implement org.eclipse.ui.commands.IElementUpdater. When you "situation" needs to update text, you use org.eclipse.ui.commands.ICommandService.refreshElements(String, Map).

Later,
PW


[1] http://wiki.eclipse.org/Command_Core_Expressions

[2] http://wiki.eclipse.org/Platform_Expression_Framework


Re: enable/disable commands handler [message #675097 is a reply to message #674562] Mon, 30 May 2011 09:55 Go to previous messageGo to next message
Gennady Gromov is currently offline Gennady GromovFriend
Messages: 24
Registered: May 2011
Junior Member
Thank you for answer, sorry for delay? I will try...

I just want to set the enabled state of menu/toolbar in dependence of my application state such as the project (specific, not java) is compiled or not compiled, the USB adapter is connected or not connected etc. I am searching for a simplest way to do it.
In AbstractHandler there is the method isEnabled(). I can put the need logic into this method but it is called by framework only once at the start of application.
Is it possible to force the framework to call this method in all handlers when it is necessary?
Re: enable/disable commands handler [message #675107 is a reply to message #675097] Mon, 30 May 2011 10:31 Go to previous messageGo to next message
Gennady Gromov is currently offline Gennady GromovFriend
Messages: 24
Registered: May 2011
Junior Member
Thank you for answer, sorry for delay? I will try...

I just want to set the enabled state of menu/toolbar in dependence of my application state such as the project (specific, not java) is compiled or not compiled, the USB adapter is connected or not connected etc. I am searching for a simplest way to do it.
In AbstractHandler there is the method isEnabled(). I can put the need logic into this method but it is called by framework only once at the start of application.
Is it possible to force the framework to call this method in all handlers when it is necessary?
Re: enable/disable commands handler [message #675155 is a reply to message #675097] Mon, 30 May 2011 12:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

ALGROM wrote on Mon, 30 May 2011 05:55
Thank you for answer, sorry for delay? I will try...

I just want to set the enabled state of menu/toolbar in dependence of my application state such as the project (specific, not java) is compiled or not compiled, the USB adapter is connected or not connected etc. I am searching for a simplest way to do it.
In AbstractHandler there is the method isEnabled(). I can put the need logic into this method but it is called by framework only once at the start of application.
Is it possible to force the framework to call this method in all handlers when it is necessary?


If you extend AbstractHandler you can extend setEnabled(Object evaluationContext). That will be called before your command is executed, but it is not sufficient to keep tool item state up to date.

The only part of the framework that allows requests for re-evaluation that would do what you want is if you use enabledWhen, property testers, and org.eclipse.ui.services.IEvaluationService.requestEvaluation(String).

See my post for URLs with examples.

PW




Re: enable/disable commands handler [message #675300 is a reply to message #675155] Tue, 31 May 2011 05:43 Go to previous messageGo to next message
Gennady Gromov is currently offline Gennady GromovFriend
Messages: 24
Registered: May 2011
Junior Member
Thank you Paul! I found the solution in similar way via enableWhen with variable defined by org.eclipse.ui.AbstractSourceProvider. But I hoped for easier way...
Re: enable/disable commands handler [message #1861009 is a reply to message #675300] Thu, 14 September 2023 10:04 Go to previous message
Rupavathi Dosapati is currently offline Rupavathi DosapatiFriend
Messages: 2
Registered: September 2023
Junior Member
Hi Gennady GromovFriend,

Have you wrote property tester and then you have used enabledWhen tag in plugin.xml to change the state of the command. How did you implement this one. Could you please share the details about this org.eclipse.ui.AbstractSourceProvider.

Thanks
Rupa
Previous Topic:ClassNotFoundException emf.ecore cannot find emf.common
Next Topic:laptest p2 repository update from kepler
Goto Forum:
  


Current Time: Tue Mar 19 02:03:44 GMT 2024

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

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

Back to the top