以编程方式触发Eclipse插件菜单项?

时间:2016-02-01 11:11:19

标签: java eclipse eclipse-plugin eclipse-rcp

我有这个问题:我的Eclipse插件中有一个菜单项。它有一个扩展AbstractHandler并覆盖execute()的处理程序,它带有ExecutionEvent个参数。

现在我想做的是在发生特定事件时触发此功能。有人可以告诉我怎么做吗?

我想我必须以某种方式自己创建一个ExecutionEvent

1 个答案:

答案 0 :(得分:4)

您可以使用IHandlerService执行处理程序处理的命令,该命令将调用您的处理程序:

IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);

handlerService.executeCommand("command id", event);

如果您需要传递命令参数,还有executeCommand的另一种变体需要ParameterizedCommand