|Problems with adding commands to the toolbar. [message #856192]
||Wed, 25 April 2012 13:02
| Lorand Szakacs
Registered: April 2012
I have 4 commands, for brevity let's give them the ids: c1, c2, c3, c4.
In my plugin I hook up to the following extensions:
- ToolBarContributionFactory extends ExtensionContributionFactory;
- MenuContribution extends CompoundContributionItem
- (I tried adding </dynamic><dynamic> to the toolbar; it wouldn't even display, hence the difference in approach)
Both classes contribute 4 newly constructed CommandContributionItem objects, associated with the commands mentioned before.
The entries in the menu function properly, i.e. they are enabled/disabled as I'd expect according to the isEnabled() method of their respective handlers.
The entries in the toolbar are not updated properly. They start out enabled, even though they shouldn't be (the ones in the menu aren't).
I added a SelectionListener to the ISelectionService in which I force a refresh of the buttons:
public void selectionChanged(IWorkbenchPart part, ISelection selection)
CommandService commandService = (ICommandService) PlatformUI.getWorkbench()
Map<String, IWorkbenchWindow> filter = new HashMap<String, IWorkbenchWindow>();
//and so on for all commands
The plugin doesn't seem to load before I click the CommandsMenu. After that, if I click on an item in the treeviewer the buttons are displayed properly.
Another weird thing is that once I add bindings to my commands (Ctrl+1, ...; with "org.eclipse.ui.contexts.window" as a context), the toolbar items are always enabled, the ones in the menu still work properly.
I would greatly appreciate an elegant solution to the problem, not only a quick hack to my approach.(I'm also fairly new to RCP and I'd like to learn new stuff). Preferably without actions.
And yes, I am sure that I associated the same commands to the items.
- Tried adding actionSets to the Menu and toolbar. But had trouble with:
Once the action set is added the relation between "cx" commands and their handlers got obscured and the isEnabled() or execute() methods would never run.(I put breakpoints and logging to check it);
public class ToolbarActionDelegate implements IWorkbenchWindowActionDelegate
public void run(IAction action)
//values always are "c1", "c2", etc...
String actionDefinitionId = action.getActionDefinitionId();
public void selectionChanged(IAction action, ISelection selection)
String commandID = action.getActionDefinitionId();
ICommandService cs = (ICommandService) PlatformUI.getWorkbench()
Command command = cs.getCommand(commandID);
boolean result = command.isEnabled();
- adding the items to the toolbar individually instead of using an ExtensionContributionFactory exhibited the same problem as described above.
Thank you for your help!
Powered by FUDForum
. Page generated in 0.02057 seconds