如何在eclipse插件开发中使用我的编辑器打开xml文件?

时间:2012-09-26 03:00:29

标签: java eclipse eclipse-plugin

我有一个流程图编辑器,其中xml文件是输入。在plugin.xml中,我已将扩展名指定为编辑器的xml,但它在默认的xml编辑器中打开。是什么让文件在我的编辑器中打开?我想在我的插件开发中这样做。在我启动我的插件后,没有首选项或打开上下文菜单。我想将我的编辑器保留为xml文件的默认值

2 个答案:

答案 0 :(得分:2)

检查文件的“打开方式”上下文菜单,以及“文件关联”首选项页面上的默认值。

答案 1 :(得分:2)

Eclipse提供了一种机制,可以根据实际内容以编程方式识别文件类型。组织。日食。核心。内容类型。 contentTypes扩展点可用于定义由"描述符"描述的内容类型。这是一个能够在给定输入流的情况下识别特定类型内容的类。旨在使用特定内容类型的编辑器可以绑定到它而不是文件扩展名。

我们需要在plugin.xml中指定内容类型,如下所示

<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type base-type="org.eclipse.core.runtime.xml"
             file-extensions="xml"
             id="ca.ecliptical.examples.contenttype.apples"
             name="Apples File"
             priority="normal">
  <describer class="org.eclipse.core.runtime.content
                    .XMLRootElementContentDescriber">
     <parameter name="element"
                value="apples">
     </parameter>
  </describer>
</content-type>

下面是引用,它工作正常

http://www.developer.com/java/data/article.php/3648736/Eclipse-Tip-Define-Custom-Content-Types-to-Identify-Your-Data-Files.htm