no

How to Call a Command With Parameter in Code in Rcp

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.xm...

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 Example -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");
parameters.add(params);

//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);

Related

java-eclipse-rcp 3770810471995098294

Post a Comment Default Comments

2 comments

Vasil Lukach said...

Very useful code

Anonymous said...

useful thanks

item