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...
https://www.czetsuyatech.com/2021/07/java-eclipse-rcp-call-command-with-code-parameter.html
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
ArrayListparameters = 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);
2 comments
Very useful code
useful thanks
Post a Comment