我目前正在实现 Eclipse 4.3 应用程序并遇到问题。我尝试参数化命令来删除特定文件。我的方法对应于在 Eclipse RCP 4.2 中获取参数化命令的参数 https://stackoverflow.com/questions/9852088/getting-parameter-of-parameterized-command-in-eclipse-rcp-4-2,但我不知何故无法正常工作。
在我的 Application.e4xmi 中,我添加了一个带有参数的命令:
<commands xmi:id="_K1MVgDGKEeOO8o2ChqdHMA" elementId="first.application.command.deleteproject" commandName="deleteProjectCommand">
<parameters xmi:id="_Hr4FEDGTEeOO8o2ChqdHMA" elementId="cmd0" name="cmd0" typeId="" optional="false"/>
</commands>
在我的代码中的某一时刻,我创建命令、设置参数并执行它:
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("cmd0", "test");
final Command command =commandService.getCommand("first.application.command.deleteproject");
final ParameterizedCommand pcmd = ParameterizedCommand.generateCommand(command, parameters);
pcmd.executeWithChecks(null, null);
我有一个与命令链接的处理程序,它具有以下执行方法:
@Execute
public void execute(@Optional @Named("cmd0") String file) {
System.out.println("delete project " + file);
}
一切正常,只是file
没有被注入,它保留下来null
。当我检查pcmd
在我执行它之前,它告诉我它已正确设置参数{cmd0=test}
(using System.out.println(pcmd.getParameterMap());
)。当我删除时@Optional
,根本没有调用execute方法。
某个地方的参数cmd0
丢失了。我的代码哪里有错误?
Thanks!