java - 为什么我的 Eclipse 插件 ICommand IParameter 的值没有出现在 Preferences/Keys 设置中?

标签 java eclipse eclipse-plugin key-bindings

我正在尝试开发一个 Eclipse 插件,它将以键绑定(bind)命令的形式启动特定目标。

这是 plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension point="org.eclipse.ui.commands">
      <category name="Custom Launcher" id="Eclipse_Keybound_Launch_Plugin.commands.category"/>
      <command
            categoryId="Eclipse_Keybound_Launch_Plugin.commands.category"
            defaultHandler="eclipse_keybound_launch_plugin.handlers.CustomLaunchCommandHandler"
            description="Launch/terminate then relaunch a custom target in debug mode"
            id="Eclipse_Keybound_Launch_Plugin.commands.terminateLaunch"
            name="Launch">
            <commandParameter
                  id="Eclipse Keybound Launch Plugin.launchTarget"
                  name="target"
                  optional="false"
            />
      </command>
   </extension>

   <extension point="org.eclipse.ui.bindings">
      <key  commandId="Eclipse_Keybound_Launch_Plugin.commands.terminateLaunch"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            contextId="org.eclipse.ui.contexts.window"
            sequence="M1+6">
            <parameter id="Eclipse Keybound Launch Plugin.launchTarget" value="RunMe"/>
      </key>
   </extension>

   <extension point="org.eclipse.ui.bindings">
      <key  commandId="Eclipse_Keybound_Launch_Plugin.commands.terminateLaunch"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            contextId="org.eclipse.ui.contexts.window"
            sequence="M1+7">
            <parameter id="Eclipse Keybound Launch Plugin.launchTarget" value="RunMeAlso"/>
      </key>
   </extension>

</plugin>

为了完整起见,下面是它在扩展 View 中的样子:

enter image description here

插件在我进行测试时有效;参数值在 ExecutionEvent 中可用。但是,该值未显示在首选项/键设置中:

enter image description here

为什么会这样?我需要做什么才能让 Eclipse 不仅显示名称 (target:),还显示参数值(RunMeRunMeAlso在这种情况下)?

请注意,我使用的是 Eclipse SDK 版本:3.6.1,构建 ID:M20100909-0800。

最佳答案

定义 commandParameter 时,使用 values 元素提供 org.eclipse.core.commands.IParameterValues。该类将命令参数中的信息映射到人类可读的标签。

请参阅 org.eclipse.ui.internal.registry.PerspectiveParameterValuesorg.eclipse.ui.internal.registry.ViewParameterValues 作为示例,但基本上您返回的是标签到 ID 的映射:

public final Map getParameterValues() {
    final Map values = new HashMap();

    final IViewDescriptor[] views = PlatformUI.getWorkbench()
            .getViewRegistry().getViews();
    for (int i = 0; i < views.length; i++) {
        final IViewDescriptor view = views[i];
        values.put(view.getLabel(), view.getId());
    }

    return values;
}

关于java - 为什么我的 Eclipse 插件 ICommand IParameter 的值没有出现在 Preferences/Keys 设置中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6085794/

相关文章:

java - Spring Boot + Intellij Idea + Hibernate - 奇怪的堆栈跟踪

java - 如何定义继承内部类的子类的构造函数?

eclipse - 如何自动化 Eclipse 插件版本控制?

java - Maven.surefire.util.SurefireReflectionException 在测试 Junit 测试时

eclipse - 停止 Wildfly Windows 服务失败

java - 如何以编程方式从自定义视角隐藏默认菜单?

java - 如何以编程方式从 OSGI 蓝图中获取 bean?

java - 为什么这会导致 "The field name is ambiguous"错误?

Eclipse Kepler 不允许我安装插件

java - 如何使用 eclipse 插件将文件发送到服务器?