【问题标题】:Extension point to refer another extension引用另一个扩展的扩展点
【发布时间】:2015-07-03 21:38:02
【问题描述】:


让我们考虑一个名为“列编辑器”的编辑器,其中我们有许多列。我们将此列提供为“扩展点”,以便任何想要贡献列的人都可以向该扩展点添加“扩展”。

现在,我们正在为这些列提供排序功能。每当编辑器启动并加载列时,列数据应按“默认列”(其中之一来自贡献的列)排序。

首先,我想为这些“扩展点”提供一个属性来设置它是否是默认排序的列。但是,多重贡献为该属性提供了“真实”,这导致了歧义。

是否有一个价值可以消除这种歧义并提供一个默认排序列的干净解决方案?

我想提供另一个扩展点并说明哪一列可以是默认的排序列。但是,这需要对 Extension 的引用。如何在扩展点中引用另一个扩展?

因此,我正在考虑提供另一个扩展 proint

【问题讨论】:

    标签: eclipse-plugin


    【解决方案1】:

    一个扩展点引用另一个扩展点是很常见的。

    例如,看 Ant 编辑器声明:

     <extension
         point="org.eclipse.ui.editors">
      <editor
            name="%AntEditor.name"
            icon="$nl$/icons/full/obj16/ant_buildfile.png"
            class="org.eclipse.ant.internal.ui.editor.AntEditor"
            contributorClass="org.eclipse.ant.internal.ui.editor.AntEditorActionContributor"
            id="org.eclipse.ant.ui.internal.editor.AntEditor">
            <contentTypeBinding
               contentTypeId="org.eclipse.ant.core.antBuildFile"/> 
      </editor>
    

    contentTypeBinding 元素指的是contentTypeId,其中声明了 id org.eclipse.ant.core.antBuildFile

    <extension 
        point="org.eclipse.core.contenttype.contentTypes"> 
        <content-type  
            id="org.eclipse.ant.core.antBuildFile" 
            name="%antBuildFileContentType.name" 
            base-type="org.eclipse.core.runtime.xml"
            file-names="build.xml"
            file-extensions="macrodef,ent,xml,ant"
            priority="normal"> 
            <describer 
                class="org.eclipse.ant.internal.core.contentDescriber.AntBuildfileContentDescriber">
            </describer> 
        </content-type> 
    </extension>
    

    所以关键是为扩展程序提供一个唯一的 id。在您的扩展点架构中,您将 id 声明为 required 并具有类型 identifier

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-05
      • 1970-01-01
      相关资源
      最近更新 更多