Actions are disabled if editor loses focus. Why? [message #763238] |
Fri, 09 December 2011 06:55  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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 .
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 
Kind regards,
Philipp
[Updated on: Fri, 09 December 2011 07:58] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03687 seconds