I have an RCP application with an existing command and handler to switch perspective programmatically. And I also have and new plugin consumed by the existing RCP application. I want this new plugin to execute the command/handler of my RCP application, what can be the possible solution for this?
Asked
Active
Viewed 4,541 times
2 Answers
4
You may need to define a handler for that command (not sure), but executing 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);

Lii
- 11,553
- 8
- 64
- 88

Bela Vizer
- 2,527
- 22
- 26
3
There are many ways to execute a command. @Bela presented 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 primary that it allows you to add parameters to a command - e.g. the newWizardId
of the org.eclipse.ui.newWizard
.

Lii
- 11,553
- 8
- 64
- 88

Tonny Madsen
- 12,628
- 4
- 31
- 70