Project: Eclipse_Platform_UI
Bug 180503 [Contributions] Updating UIElement from Command Handler not working
Reported: 2007-04-02 11:43:27 | Status: verified fixed

I'm seeing inconsistent behavior with the updateElement(...) method provided by IElementUpdater when trying to manipulate a toolbar item with a "toggle" state. When the toolbar item is clicked by the user and put in a "checked" (depressed) state, the CommandContributionItem.setChecked method indicates that the checkedState member variable is stored as false. This causes any calls to UIElement.setChecked(false) to be silently ignored, and the toolbar item remains in a checked state. Steps to reproduce: I added the following command to a simple RCP application with a view application: <extension point="org.eclipse.ui.commands"> <command defaultHandler="demo.DemoHandler" id="demo.command" name="Demo"> </command> </extension> The Handler code looks like: public class DemoHandler extends AbstractHandler implements IElementUpdater { @Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); ICommandService service = (ICommandService) window.getService(ICommandService.class); service.refreshElements(event.getCommand().getId(), null); return null; } public void updateElement(UIElement element, Map parameters) { element.setChecked(false); } } The menu extension is as follows: <extension point="org.eclipse.ui.menus"> <menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions"> <toolbar id="main"> <command commandId="demo.command" icon="icons/alt_window_16.gif" style="toggle"> </command> </toolbar> </menuContribution> </extension>

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/HandlerAuthority.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java