如何通过代码将参数传递给eclipse rcp应用程序中的comman?
我正在使用下面的代码来运行通过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){
}
这工作正常,但我想传递一个参数到这个命令。 我有接受参数的机制,但如何通过代码传递它?
想想吧! 以下做法是否同样如此:
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){
}
链接地址: http://www.djcxy.com/p/18685.html
上一篇: How to pass parameters to comman in eclipse rcp application through code?