Execute command / handler of an existing plugin from another plugin

I have an RCP application with an existing command and handler to switch perspective programmatically. And I also have a new plugin consumed by an existing RCP application. I want this new plugin to execute the command / handler of my RCP application, what could be a possible solution for this?

+3


source to share


2 answers


You may need to define a handler for this command (not sure), but executing the commands programmatically looks like this:



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);

      

+4


source


There are many ways to execute a command. @Bela introduced one - I usually use the following code:

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);

      



The advantage of this method is that it allows you to add options to the team - for example, newWizardId

org.eclipse.ui.newWizard

.

+3


source







All Articles