gpt4 book ai didi

java - 如何通过代码将参数传递给eclipse rcp应用程序中的命令?

转载 作者:行者123 更新时间:2023-12-01 13:48:37 31 4
gpt4 key购买 nike

我使用下面的代码来运行通过 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){

}

关于java - 如何通过代码将参数传递给eclipse rcp应用程序中的命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20145464/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com