Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Handler enablement doesn't work unless widow focus changes
Handler enablement doesn't work unless widow focus changes [message #514599] Mon, 15 February 2010 17:32 Go to next message
Mark Leone is currently offline Mark Leone
Messages: 123
Registered: July 2009
Senior Member
I have an RCP app with a handler that appears in a menu added to the main menu bar. I set the enablement of the handler using a property tester.

When the system property changes such that a command should be disabled, it still shows up as enabled in the menu. But If I select it, I get an exception that says I'm trying to run a command that's disabled.

I found that if, after the system property changes such that the handler should be disabled, I select a different window and the re-select the RCP app window, the menu shows the proper enablement state. So it seems like the menu is not being refreshed when the system property changes, until the app window loses and re-gains focus.

Am I supposed to do something to refresh the menu when the system property changes? I also tried using <visibleWhen> on the menu item, with the same property tester. The same thing happens- I have to make the app window lose and re-gain focus to show the proper visibility state.

My enablement extension looks like this

<handler
class=...
commandId=... />
<enabledWhen>
<systemTest property="myPropertyName" value="theExpectedValue" />
</enabledWhen>
/handler>
Re: Handler enablement doesn't work unless widow focus changes [message #514673 is a reply to message #514599] Tue, 16 February 2010 05:01 Go to previous messageGo to next message
martin is currently offline martin
Messages: 12
Registered: July 2009
Junior Member
A Change in System Properties does not trigger a reevaluation of variables,
you should propably consider using a SourceProvider and you should also have a look at IEvaluationService.

I hope this helps.
A german tutorial how to use Source Providers can be found here.
http://splitshade.wordpress.com/2008/11/11/sourceproviders/
Re: Handler enablement doesn't work unless widow focus changes [message #514840 is a reply to message #514673] Tue, 16 February 2010 15:11 Go to previous messageGo to next message
Mark Leone is currently offline Mark Leone
Messages: 123
Registered: July 2009
Senior Member
Thanks! That's exactly what I needed. Implementing a SourceProvider and accessing an implementation of ISourceProviderService is the necessary approach. Unfortunately I don't speak German, but I searched on SourceProvider and found the following excellent article.

http://blog.eclipse-tips.com/2009/02/commands-part-5-authent ication-in-rcp.html

The article gives everything needed to update enablement or visibility on commands or handlers in response to an arbitrarily defined variable. It also covers how to dynamically change a command or handler's label, which was also something I was interested in.
Re: Handler enablement doesn't work unless widow focus changes [message #515016 is a reply to message #514840] Wed, 17 February 2010 08:55 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

As an aside, you can also use
org.eclipse.ui.services.IEvaluationService.requestEvaluation (String) to
request that expressions using a specific property tester be
re-evaluated without having to create a source provider.

Source providers are really handy if you want to expose one or more
variables, that can then be used in <with/> expressions.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:Placing label text on left side of check box
Next Topic:Build Eclipse RCP Application using Apache Ant scripts?
Goto Forum:
  


Current Time: Wed Jul 30 15:27:37 EDT 2014

Powered by FUDForum. Page generated in 0.09655 seconds