Skip to main content



      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 11:22 Go to next message
Eclipse UserFriend
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 10:34 Go to previous messageGo to next message
Eclipse UserFriend
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 09:47 Go to previous messageGo to next message
Eclipse UserFriend
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 05:23 Go to previous message
Eclipse UserFriend
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: Wed Mar 26 04:13:48 EDT 2025

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

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

Back to the top