Eclipse plugin 如何访问IPParameterValues::getParameterValues()返回的映射?
我为此命令声明了一个命令和一个commandParameter。我将这个commandParameter的“值”指定为自己实现的类。该类的实现如下所示:Eclipse plugin 如何访问IPParameterValues::getParameterValues()返回的映射?,eclipse-plugin,eclipse-rcp,Eclipse Plugin,Eclipse Rcp,我为此命令声明了一个命令和一个commandParameter。我将这个commandParameter的“值”指定为自己实现的类。该类的实现如下所示: public class ParameterValues implements IParameterValues { @Override public Map<String, Double> getParameterValues() { // TODO Auto-generated method s
public class ParameterValues implements IParameterValues {
@Override
public Map<String, Double> getParameterValues() {
// TODO Auto-generated method stub
Map<String, Double> values = new HashMap<String, Double>(2);
values.put("testParam", 1.1239);
values.put("AnotherTest", 4.1239);
return values;
}
}
现在,我将命令添加到菜单中
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="my.edit"
label="Edit">
<command
commandId="myCommand.test"
label="Test1">
<parameter
name="my.parameter1"
value="testParam">
</parameter>
</command>
由于我为CommandParator指定了一个“values”类,我希望在单击菜单时,处理程序类中的代码行“String value=event.getParameter(PARAMETER_ID);”返回1.1239,而不是“testParam”。
但是,我仍然看到代码行返回“testParam”
有什么问题吗?如何访问getParameterValues()返回的映射
顺便说一下,下面的菜单声明仍然有效,即使我没有在地图中定义“ppp”
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="my.edit"
label="Edit">
<command
commandId="myCommand.test"
label="Test1">
<parameter
name="my.parameter1"
value="ppp">
</parameter>
</command>
谢谢 从javadoc,
org.eclipse.core.commands.ipParameterValues.getParameterValues()
“返回由参数值的外部化名称键入的映射。这些名称应该是人类可读的,并且通常用于在某种用户界面中向用户显示。这些值应为实际值,该值将由该命令的处理程序进行解释。”
此界面用于为命令参数提供可翻译的名称。因此,“显示视图(包资源管理器)”可以显示在密钥首选项页面中,而不是“显示视图(org.eclipse.jdt.ui.PackageExplorer)”
但是org.eclipse.ui.menus
定义必须包含参数值,而不是可翻译的名称
如果要处理字符串参数并将其转换为各种对象,可以在命令定义中定义参数类型和AbstractParameterValueConverter
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="my.edit"
label="Edit">
<command
commandId="myCommand.test"
label="Test1">
<parameter
name="my.parameter1"
value="ppp">
</parameter>
</command>