Community
Participate
Working Groups
Backport to 4.3.1 +++ This bug was initially created as a clone of Bug #387951 +++ The purpose is to bind some keys to some action bar actions used by a view (org.eclipse.ui.ViewPart). The view part is used both within a workbench view and a modal dialog. For the modal dialog I've defined a custom context (see below) and, before the dialog executes I try to activate my custom context and link the commands associated with the key bindings to the view actions. It works very well up until 3.8 (I never tested for 4.0 and 4.1). In 4.2 I get key binding conflict warning when I activate my context and even if I remove the conflicting bindings (for F2, F3 and F4), although the commands are correctly associated with the view actions (the accelerator appears within the tool-tip), pressing the shortcut keys still has no effect. The code for dialog configuration: class MyDialog extends TitleAreaDialog { protected Control createDialogArea(Composite parent) { Composite area = (Composite) super.createDialogArea(parent); ... //The toolbar used for view actions: ToolBar toolBar = new ToolBar(area, SWT.FLAT | SWT.RIGHT); mnuMgr = new ToolBarManager(toolBar); ... Composite container = new Composite(area, SWT.NONE); ... cv = new CustomView(mnuMgr); //the ViewPart cv.createPartControl(container); area.setTabList(new Control[]{toolBar, container}); //Activate my custom context (see code below) cv.hookKeyboard(); area.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { ViewManager.INSTANCE.unRegisterViewPart(cv); //deactivate the custom context: cv.releaseKeyboard(); } }); return area; } ... } public class CustomView extends ViewPart { public static final String CONTEXT_ID = "com.example.my.custom.context" ... public void hookKeyboard() { if (isDialogMode && activation == null) { IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class); ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); contextService.registerShell(shell, IContextService.TYPE_DIALOG); //THIS IS THE POINT WHERE THE KEY BINDING CONFLICT IS ISSUED: activation = contextService.activateContext(CONTEXT_ID); //Associating the defined commands with the dialog defined //handler (see below) Command c = commandService.getCommand(CMD_ACTION_DEL); c.setHandler(handler); c = commandService.getCommand(CMD_ACTION_MOD); c.setHandler(handler); c = commandService.getCommand(CMD_ACTION_ADD); c.setHandler(handler); } } public void releaseKeyboard() { if (isDialogMode && activation != null) { IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class); contextService.deactivateContext(activation); activation = null; } } ... public class Handler extends AbstractHandler { // THIS IS NEVER EXECUTED IN 4.2 ! @Override public Object execute(ExecutionEvent event) throws ExecutionException { if (inCommand) return null; inCommand = true; try { if (event.getCommand().getId().equals(CMD_ACTION_DEL)) actionDelete.run(); //view action else if (event.getCommand().getId().equals(CMD_ACTION_MOD)) actionEdit.run(); //view action else if (event.getCommand().getId().equals(CMD_ACTION_ADD)) actionAdd.run(); //view action } finally { inCommand = false; } return null; } } final AbstractHandler handler = new Handler(); ... } Context definition in plugin.xml: <extension point="org.eclipse.ui.contexts"> <context id="com.example.my.custom.context" name="My custom context" parentId="org.eclipse.ui.contexts.dialog"> </context> </extension> Binding definitions: <extension point="org.eclipse.ui.bindings"> <key commandId="com.example.my.view.edit" contextId="com.example.my.custom.context" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" sequence="F3"> </key> <key commandId="com.example.my.view..add" contextId="com.example.my.custom.context" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" sequence="F2"> </key> <key commandId="com.example.my.view.delete" contextId="com.example.my.custom.context" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" sequence="F4"> </key> </extension> Command definitions: <extension point="org.eclipse.ui.commands"> <category description="My Dialog Actions" id="com.example.category.dialog.actions" name="Dialog actions"> </category> <command categoryId="com.example.category.dialog.actions" id="com.example.dialog.add" name="New..."> </command> <command categoryId="com.example.category.dialog.actions" id="com.example.dialog.edit" name="Edit..."> </command> <command categoryId="com.example.category.dialog.actions" id="com.example.dialog.delete" name="Delete"> </command> </extension> The conflicting bindings (notice the different contexts "org.eclipse.ui.contexts.window" and "com.example.my.custom.context" : ENTRY org.eclipse.jface 2 0 2012-08-24 10:54:50.641 !MESSAGE Keybinding conflicts occurred. They may interfere with normal accelerator operation. !SUBENTRY 1 org.eclipse.jface 2 0 2012-08-24 10:54:50.641 !MESSAGE A conflict occurred for F4: Binding(F4, ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.open.type.hierarchy,Open Type Hierarchy, Open a type hierarchy on the selected element, Category(org.eclipse.ui.category.navigate,Navigate,null,true), org.eclipse.ui.internal.MakeHandlersGo@282c55f1, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, org.eclipse.ui.contexts.window,,,system) Binding(F4, ParameterizedCommand(Command(com.example.dialog.delete,Delete, , Category(com.example.category.dialog.actions,Dialog actions,null,true), com.example.views.CustomView$Handler@76be55d1, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, com.example.my.custom.context,,,system) !SUBENTRY 1 org.eclipse.jface 2 0 2012-08-24 10:54:50.641 !MESSAGE A conflict occurred for F2: Binding(F2, ParameterizedCommand(Command(org.eclipse.ui.edit.rename,Rename, Rename the selected item, Category(org.eclipse.ui.category.file,File,null,true), org.eclipse.ui.internal.MakeHandlersGo@58fe210a, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, org.eclipse.ui.contexts.window,,,system) Binding(F2, ParameterizedCommand(Command(com.example.dialog.add,New..., , Category(com.example.category.dialog.actions,Dialog actions,null,true), com.example.views.CustomView$Handler@76be55d1, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, com.example.my.custom.context,,,system) !SUBENTRY 1 org.eclipse.jface 2 0 2012-08-24 10:54:50.641 !MESSAGE A conflict occurred for F3: Binding(F3, ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.open.editor,Open Declaration, Open an editor on the selected element, Category(org.eclipse.ui.category.navigate,Navigate,null,true), org.eclipse.ui.internal.MakeHandlersGo@49f4493e, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, org.eclipse.ui.contexts.window,,,system) Binding(F3, ParameterizedCommand(Command(com.example.dialog.edit,Edit..., , Category(com.example.category.dialog.actions,Dialog actions,null,true), com.example.views.CustomView$Handler@76be55d1, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, com.example.my.custom.context,,,system)
Reproducible with attachment 231268 [details] PW
Gerrit review link: https://git.eclipse.org/r/#/c/15715/ Daniel
Curtis, can I get you to review this for Daniel? Thanks, PW
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=0c314f51dca6c35de4cea8eb977fa5d3bf2132cb +1
Verified in the build: M20130828-0800