6

I want to call an RCP command in code, like this:

IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class);
    handlerService.executeCommand(cmdID, null);

With considerably more code, I can call the command with a string argument by assembling a Parameterization object then building a ParameterizedCommand and so forth but Paramaterization only allows for string values, and can't be subclassed.

What I really want to do is call the command with an object as a parameter. How can I do this?

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
TL Stillman
  • 305
  • 1
  • 3
  • 10

1 Answers1

2

Use ParameterizedCommand.generateCommand(). You can pass the command object (obtained from ICommandService) and the parameters in a map.

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
Prakash G. R.
  • 4,746
  • 1
  • 24
  • 35
  • 2
    That doesn't work. I'm only getting a "cannot be cast to java.lang.String" exception if i try to add an object instead of a String. – Chris Mar 14 '13 at 09:09
  • I looked into this, it looks like you also need define a ParemeterValueConverter to converter your objects into Strings and back. I find that very impractical, tbh. You might be able to get away with using HandlerUtil.getCurrentSelection(event) for some parameters. – Alex Pruss Sep 02 '15 at 15:55