Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Enable action in menubar?(How can I update the enable state of an main menubar action.)
icon11.gif  Enable action in menubar? [message #529893] Tue, 27 April 2010 15:22 Go to next message
Andreas is currently offline AndreasFriend
Messages: 9
Registered: February 2010
Location: Germany/Berlin
Junior Member
I have write an (GMF based) editor plugin. I have implement my own revert action and retargeted the global revert action to my revert action. I enable my revert action and everything works fine. Razz
Only one thing is not working:
I want that the revert action is only enable if the editor is dirty. So I add a PropertyListener.
Every time the property is the same like IEditorPart.PROP_DIRTY I check the editor.isDirty() value and set the enable state of my revert action. But in the main menubar, the state of this action is not change. On the actionbar I tried updateActionBars() and getMenuManager().updateAll(true) without any effect. So how can I update the enable state of my revert action? Embarrassed

Thank You!

Re: Enable action in menubar? [message #530120 is a reply to message #529893] Wed, 28 April 2010 14:34 Go to previous messageGo to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 123
Registered: July 2009
Senior Member
I had a similar problem, and resolved it by using a SourceProvider. You may also find the Evalutation Service useful for what you're trying to do.

See this post for the advice I was given, which worked for me.

http:// www.eclipse.org/forums/index.php?t=msg&goto=514599&# msg_514599
Re: Enable action in menubar? [message #532893 is a reply to message #529893] Tue, 11 May 2010 13:47 Go to previous messageGo to next message
Andreas is currently offline AndreasFriend
Messages: 9
Registered: February 2010
Location: Germany/Berlin
Junior Member
Thanks for your advice. Revert is an eclipse build-in Action. SourceProvider only works with Handlers?
But I solve my problem, by call setEnabled() twice: Twisted Evil

setEnabled(!isDirty);
setEnabled(isDirty);


to make sure that firePropertyChange is called.

org.eclipse.jface.action.AbstractAction.firePropertyChange(ENABLED, oldVal, newVal);
Re: Enable action in menubar? [message #1047489 is a reply to message #532893] Tue, 23 April 2013 09:23 Go to previous message
Sacha Warning is currently offline Sacha WarningFriend
Messages: 1
Registered: April 2013
Junior Member
I just had the same problem and found out the following:

Enabling or disabling an Action is trivial as long as the method isEnabled() is not overwritten. Just call setEnabled(true) or setEnabled(false) to disable an Action. This fires a property change event for the ENABLED property if the enabled state actually changes as a consequence. A problem occurs if the method isEnabled() is overwritten, because when calling setEnabled the framework checks if the value of enabled will change by calling isEnabled.
If isEnabled() has to be overwritten anyway, the property change event is not fired when calling setEnabled().
So you have to fire this event explicitely by calling firePropertyChange(ENABLED, !isEnabled(), isEnabled());
Previous Topic:Product Root file Shows no copyright information
Next Topic:Overriding existing menu entries in eclipse
Goto Forum:
  


Current Time: Sun Dec 21 14:40:44 GMT 2014

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

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