Destructor
Destructor

Reputation: 3294

How to pass parameters to comman in eclipse rcp application through code?

I am using the below code to run a command added via org.eclipse.ui.commands:

IServiceLocator serviceLocator = PlatformUI.getWorkbench();
ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);

try  {
        Command command = commandService.getCommand("my_command_id");
        command.executeWithChecks(new ExecutionEvent());

    } catch (ExecutionException ex1) {

    } catch (NotDefinedException ex2){

    } catch(NotEnabledException ex3){

    } catch(NotHandledException ex4){

    }


This works fine, but I want to pass a parameter to this command. I have mechanism to accept parameters, but how to pass it through code?

Upvotes: 0

Views: 603

Answers (1)

Destructor
Destructor

Reputation: 3294

Figured it! Did the following to do the same:

IServiceLocator serviceLocator = PlatformUI.getWorkbench();
ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);

try  { 
        Command command = commandService.getCommand("my_command_id");
        Map<String, String> map = new HashMap<String, String>();
        map.put("param_name", "param_value");
        /*more parameter's can be added to Map and passed*/
        command.executeWithChecks(new ExecutionEvent(null, map, null, null));

    } catch (ExecutionException e1) {

    } catch (NotDefinedException e2){

    } catch(NotEnabledException e3){

    } catch(NotHandledException e4){

    }

Upvotes: 1

Related Questions