【发布时间】:2016-02-21 20:11:07
【问题描述】:
我有一个带有现有命令和处理程序的 RCP 应用程序,用于以编程方式切换视角。而且我还有现有 RCP 应用程序使用的新插件。我希望这个新插件能够执行我的 RCP 应用程序的命令/处理程序,对此有什么可能的解决方案?
【问题讨论】:
标签: eclipse eclipse-plugin eclipse-rcp
我有一个带有现有命令和处理程序的 RCP 应用程序,用于以编程方式切换视角。而且我还有现有 RCP 应用程序使用的新插件。我希望这个新插件能够执行我的 RCP 应用程序的命令/处理程序,对此有什么可能的解决方案?
【问题讨论】:
标签: eclipse eclipse-plugin eclipse-rcp
您可能需要为该命令定义一个处理程序(不确定),但以编程方式执行命令如下所示:
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);
【讨论】:
执行命令的方法有很多种。 @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);
这种方法的主要优点是它允许您向命令添加参数 - 例如newWizardId 的 org.eclipse.ui.newWizard。
【讨论】: