【问题标题】:How does the parameter of the extension point "org.eclipse.ui.handlers" work?扩展点“org.eclipse.ui.handlers”的参数是如何工作的?
【发布时间】:2023-02-04 19:09:51
【问题描述】:

我定义一个扩展

<extension point="org.eclipse.ui.handlers">
    <handler commandId="com.abc.test.command">
        <class class="com.abc.test.TestHandler">
            <parameter
                name="a"
                value="111">
            </parameter>
        </class>
    </handler>
</extension>

测试处理器

public class TestHandler extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        Map parameters = event.getParameters() ;
        return null;
    }
    
}

当调用TestHandler.execute(ExecutionEvent)时,parameters为空。 为什么?它是如何工作的 ?

【问题讨论】:

    标签: eclipse


    【解决方案1】:

    ExecutionEvent.getParameters 方法返回使用定义命令的org.eclipse.ui.commands 扩展点的commandParameter 元素定义的参数。

    例如:

       <extension
             point="org.eclipse.ui.commands">
          <command
               categoryId="org.eclipse.ui.category.window"
               defaultHandler="org.eclipse.help.ui.internal.handlers.OpenBundleResourceHandler"
               description="%command.openBundleResource.description"
               id="org.eclipse.ui.browser.openBundleResource"
               name="%command.openBundleResource.name">
            <commandParameter
                   id="plugin"
                   name="%commandParameter.openBundleResource.plugin.name"
                   optional="true"/>
            <commandParameter
                   id="path"
                   name="%commandParameter.openBundleResource.path.name"
                   optional="true"/>
          </command>
    </extension>
    

    org.eclipse.ui.handlersparameter 元素仅在实现 IExecutableExtension 接口的情况下可用于实现处理程序的类。这有单一的方法:

    public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException;
    

    该类可以调用IConfigurationElement.getAttribute方法来获取参数值。

    【讨论】:

      猜你喜欢
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多