Looking for a JavaEE Architect or Potential Tech Co-Founder?
Please don't hesitate to contact me.

eclipse-rcp calling a command with parameter in code

In case you come up with the same situation as mine, here's how I've done it.

1.) in your eclipse-rcp's project's plugin.xml create a new command with a parameter, set the ids
-commandId: org.ipiel.demo.commands.click
-commandParameterId: org.ipiel.demo.commands.click.paramenter1

Here's the code

ArrayList parameters = new ArrayList();
IParameter iparam;

//get the command from plugin.xml
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ICommandService cmdService = (ICommandService)window.getService(ICommandService.class);
Command cmd = cmdService.getCommand("org.ipiel.demo.commands.click");

//get the parameter
iparam = cmd.getParameter("org.ipiel.demo.commands.click.paramenter1");
Parameterization params = new Parameterization(iparam, "commandValue");

//build the parameterized command
ParameterizedCommand pc = new ParameterizedCommand(cmd, parameters.toArray(new Parameterization[parameters.size()]));

//execute the command
IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class);
handlerService.executeCommand(pc, null);
eclipse-rcp calling a command with parameter in code eclipse-rcp calling a command with parameter in code Reviewed by Edward Legaspi on Thursday, April 08, 2010 Rating: 5


Vasil Lukach said...

Very useful code

Anonymous said...

useful thanks

Powered by Blogger.