This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 415579 - Key bindings for custom context no longer works and conflicts are reported
Summary: Key bindings for custom context no longer works and conflicts are reported
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.3.1   Edit
Assignee: Daniel Rolka CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 387951
Blocks:
  Show dependency tree
 
Reported: 2013-08-21 09:23 EDT by Paul Webster CLA
Modified: 2013-08-29 03:59 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Webster CLA 2013-08-21 09:23:30 EDT
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)
Comment 1 Paul Webster CLA 2013-08-21 09:58:27 EDT
Reproducible with  attachment 231268 [details]

PW
Comment 2 Daniel Rolka CLA 2013-08-21 10:15:25 EDT
Gerrit review link: https://git.eclipse.org/r/#/c/15715/

Daniel
Comment 3 Paul Webster CLA 2013-08-21 10:25:23 EDT
Curtis, can I get you to review this for Daniel?

Thanks,
PW
Comment 5 Daniel Rolka CLA 2013-08-29 03:59:57 EDT
Verified in the build: M20130828-0800