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

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