简体   繁体   中英

Trigger Eclipse plugin menu-entry programmatically?

I've got this question: I have an menu entry in my Eclipse plugin. It has a handler which extends AbstractHandler and overrides execute() which takes an ExecutionEvent parameter.

Now what I want to do is to trigger this function when something specific happens. May someone tell me how to do it?

I guess I have to create a ExecutionEvent on my own somehow?

You can use the IHandlerService to execute the command that the handler handles, which will call your handler:

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

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

There is another variant of executeCommand which takes a ParameterizedCommand if you need to pass command parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM