【问题标题】:Execute command/handler of an existing plugin from a different plugin从不同的插件执行现有插件的命令/处理程序
【发布时间】:2016-02-21 20:11:07
【问题描述】:

我有一个带有现有命令和处理程序的 RCP 应用程序,用于以编程方式切换视角。而且我还有现有 RCP 应用程序使用的新插件。我希望这个新插件能够执行我的 RCP 应用程序的命令/处理程序,对此有什么可能的解决方案?

【问题讨论】:

    标签: eclipse eclipse-plugin eclipse-rcp


    【解决方案1】:

    您可能需要为该命令定义一个处理程序(不确定),但以编程方式执行命令如下所示:

    Command command = ((ICommandService) getSite().getService(ICommandService.class)).getCommand(commandId);
    ...
    final Event trigger = new Event();
    ExecutionEvent executionEvent = ((IHandlerService) getSite().getService(IHandlerService.class)).createExecutionEvent(command, trigger);
    command.executeWithChecks(executionEvent);
    

    【讨论】:

      【解决方案2】:

      执行命令的方法有很多种。 @Bela 提出了一个 - 我通常使用以下代码:

      ICommandService commandService = (ICommandService) locationService.getService(ICommandService.class);
      IHandlerService hs = (IHandlerService) locationService.getService(IHandlerService.class);
      
      ParameterizedCommand pc = commandService.deserialize("<cmd-id>(<p-id>=<value>)");
      
      hs.executeCommand(pc, null);
      

      这种方法的主要优点是它允许您向命令添加参数 - 例如newWizardIdorg.eclipse.ui.newWizard

      【讨论】:

        猜你喜欢
        • 2018-12-28
        • 1970-01-01
        • 2011-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-02
        • 1970-01-01
        • 2013-09-06
        相关资源
        最近更新 更多