如何在多页面编辑器中管理不同命令的键冲突处理程序

时间:2014-02-03 05:48:29

标签: eclipse eclipse-plugin command

我有多页编辑器,我在两个页面中使用相同键序列'M3 + O'的不同命令。我正在获得关键的冲突处理程序。

错误:

!MESSAGE A conflict occurred for ALT+O:
      Binding(ALT+O,
            ParameterizedCommand(Command(adt.tools.wda_com.sap.adt.wda.controller.ui.addmethcommand,Add Method,
                ,
                Category(org.eclipse.core.commands.categories.autogenerated,Uncategorized,Commands that were either auto-generated or have no category,true),
                org.eclipse.ui.internal.MakeHandlersGo@2f2e3d,
                ,,true),null),
            org.eclipse.ui.defaultAcceleratorConfiguration,
            com.sap.adt.wda.controller.ui.contextTabScope,,,system)
        Binding(ALT+O,
            ParameterizedCommand(Command(adt.tools.wda_com.sap.adt.wda.controller.ui.addnodecommand,Add Node,

        ,
                Category(org.eclipse.core.commands.categories.autogenerated,Uncategorized,Commands that were either auto-generated or have no category,true),
                org.eclipse.ui.internal.MakeHandlersGo@184af18,
                ,,true),null),
            org.eclipse.ui.defaultAcceleratorConfiguration,
            com.sap.adt.wda.controller.ui.contextTabScope,,,system)

扩展程序:

  <extension
             point="org.eclipse.ui.bindings">
          <key
                commandId="adt.tools.wda_com.sap.adt.wda.controller.ui.addmethcommand"
                contextId="com.sap.adt.wda.controller.ui.contextScope"
                schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
                sequence="M3+O">
          </key>
          <key
                commandId="adt.tools.wda_com.sap.adt.wda.controller.ui.addnodecommand"
                contextId="com.sap.adt.wda.controller.ui.contextScope"
                schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
                sequence="M3+O">
          </key>
    </extension>

我自己的背景:

   <extension
         point="org.eclipse.ui.contexts">
      <context
            description="context scope"
            id="com.sap.adt.wda.controller.ui.contextScope"
            name="context scope"
            parentId="org.eclipse.ui.contexts.window">
      </context>
   </extension>

激活和停用:通过激活和停用上下文来完成。以下是页面更改时的代码段。

第一页激活:

private void activateHandlers() {
            IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
            if (contextService != null) {
                activation = contextService.activateContext(IControllerConstants.CONTEXT_TAB_ECLIPSE_CONTEXT_ID);
            }
            IEditorSite site = getEditor().getEditorSite();
            IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);

            IHandlerActivation nodeActivation = service.activateHandler(AddNodeHandler.COMMAND_ID, new AddNodeHandler());
            activatedHandlers = new ArrayList<IHandlerActivation>();
            activatedHandlers.add(nodeActivation );

        }

第二页激活:

private void activateHandlers() {
                IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
                if (contextService != null) {
                    activation = contextService.activateContext(IControllerConstants.CONTEXT_TAB_ECLIPSE_CONTEXT_ID);
                }
                IEditorSite site = getEditor().getEditorSite();
                IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);


    IHandlerActivation methodActivation = service.activateHandler(AddMethodHandler.COMMAND_ID, new AddMethodHandler());
                activatedHandlers = new ArrayList<IHandlerActivation>();
                activatedHandlers.add(methodActivation );
            }

各页中的停用类似:

public void deactivateHandlers() {
            IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
            contextService.deactivateContext(activation);
            IHandlerService service = (IHandlerService) getEditor().getEditorSite().getService(IHandlerService.class);
            if (activatedHandlers != null) {
                service.deactivateHandlers(activatedHandlers);
                activatedHandlers = null;
            }
        }

即使在页面更改停用/激活后,也会出现冲突。 如果有更好的方法,请告诉我。

感谢。

1 个答案:

答案 0 :(得分:0)

为每个页面使用不同的上下文ID。您可以使主com.sap.adt.wda.controller.ui.contextScope成为每个页面上下文的父级。