4

I was trying the bellow snippet, but the invoked command is executed with empty parameter map.

ICommandService service = (ICommandService) ((IServiceLocator) PlatformUI.getWorkbench())
                         .getService(ICommandService.class);

Command command = service.getCommand(Constants.COMMAND_ID);

ExecutionEvent eventWithParam = new ExecutionEvent(command, 
         Collections.singletonMap(Constants.COMMAND_PARAM, "true"), null, null);

command.execute(eventWithParam);

The issue seems to be that when it goes to compatibility layer is looses PARM_MAP in HandlerServiceHanlder.execute method.

Is there any workaround?

Lii
  • 11,553
  • 8
  • 64
  • 88
kmaziarz
  • 154
  • 5
  • `Command.execute` (which is deprecated) does not touch the `ExecutionEvent` - it just passes it straight to the current handler. Show us your handler code. – greg-449 Oct 13 '14 at 13:16
  • Invoked handler: public class RunHandler extends AbstractHandler implements IHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { String sIsCleanup = event.getParameter(Constants.COMMAND_PARAM); if (sIsCleanup != null) { isCleanup = Boolean.parseBoolean(sIsCleanup); } – kmaziarz Oct 13 '14 at 13:34

1 Answers1

3

Thanks @greg-449, you inspired me to keep digging ;).

In the end it turned out that neither the Command.excecute nor Command.executeWithChecks does work (all parameters are lost whilst passing to HandlerServiceHandler).

But that reminds me that there was something like HandlerService - which basically can do the job. Here is the snippet:

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

Parameterization[] params = new Parameterization[] { new Parameterization(
                    command.getParameter(Constants.COMMAND_PARAM), "true") };
ParameterizedCommand parametrizedCommand = new ParameterizedCommand(command, params);
handlerService.executeCommand(parametrizedCommand, null);
Lii
  • 11,553
  • 8
  • 64
  • 88
kmaziarz
  • 154
  • 5