Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Actions are disabled if editor loses focus. Why?
Actions are disabled if editor loses focus. Why? [message #763238] Fri, 09 December 2011 06:55 Go to next message
Philipp Bouillon is currently offline Philipp Bouillon
Messages: 16
Registered: July 2009
Junior Member
Hi,

I have an editor with some action contributions to a toolbar.
As long as my editor has the focus, everything is fine and I can click on the actions (read: toolbar buttons).
However, if I click on another view in my RCP, the actions in the toolbar are disabled, and the strange thing (to me at least) is, that the "setEnabled" method of the action is never called. So, I conclude that the toolbar itself must be rendered inactive somehow by someone...

Question is: How can I change this behaviour?!

Any ideas?!
Thank you very much!
Kind regards,
Philipp
Re: Actions are disabled if editor loses focus. Why? [message #763261 is a reply to message #763238] Fri, 09 December 2011 07:57 Go to previous message
Philipp Bouillon is currently offline Philipp Bouillon
Messages: 16
Registered: July 2009
Junior Member
Ok, I found a "solution", but it seems like a dirty hack to me...
The action in the toolbar is disabled, because the ActionContributionItem is disabled. The ACI is disabled, because it receives an update of the "enable" property and "isEnabledAllowed()" returns false.
Hence, I extended ActionContributionItem and "hacked" the update method in a way that ignored the isEnabledAllowed state... It works, but I don't know which demons from hell I conjured up Smile.
For the daring, here's the extension:

import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionManagerOverrides;

public class GeometryEditorActionContributionItem extends
		ActionContributionItem {

	public GeometryEditorActionContributionItem(IAction action) {
		super(action);
	}

	public void update(String propertyName) {
		final IAction action = getAction();
		if (getWidget() != null) {
			boolean enableStateChanged = propertyName == null
					|| propertyName.equals(IAction.ENABLED)
					|| propertyName.equals(IContributionManagerOverrides.P_ENABLED);
			if (enableStateChanged) {				
				if (action.isEnabled() && !isEnabledAllowed()) {
					return;
				}
			}
		}
		super.update(propertyName);
	}	
}


To use it (in your EditorActionBarContributor class):

    private final void add(IToolBarManager toolBarManager, IAction action) {
	GeometryEditorActionContributionItem item = new GeometryEditorActionContributionItem(action);
        toolBarManager.add(item);
    }
	
    public void contributeToToolBar(IToolBarManager toolBarManager) {
        super.contributeToToolBar(toolBarManager);
        
        add(toolBarManager, zoomInAction);
        add(toolBarManager, zoomOutAction);
        ...
    }


Maybe, this helps someone Smile
Kind regards,
Philipp

[Updated on: Fri, 09 December 2011 07:58]

Report message to a moderator

Previous Topic:How to generate RCP for xxx.diagram.dawn project
Next Topic:Proper way to programmatically copy files inside of eclipse
Goto Forum:
  


Current Time: Wed Aug 20 00:54:22 EDT 2014

Powered by FUDForum. Page generated in 0.04192 seconds