Java 如何告诉eclipse文件的首选内容类型

Java 如何告诉eclipse文件的首选内容类型,java,eclipse-plugin,file-type,Java,Eclipse Plugin,File Type,我正在开发一个插件,它可以处理给定类型的文件,比如说,.xyz,当我在Eclipse中尝试打开一个xyz文件时。我想用 org.eclipse.core.runtime.content.IContentType type = org.eclipse.core.runtime.Platform.getContentTypeManager().findContentTypeFor( fileURI.getPath()); 一旦我有了IContentType,我就有了代码来查找所需

我正在开发一个插件,它可以处理给定类型的文件,比如说,
.xyz
,当我在Eclipse中尝试打开一个
xyz
文件时。我想用

org.eclipse.core.runtime.content.IContentType type = 
  org.eclipse.core.runtime.Platform.getContentTypeManager().findContentTypeFor(
      fileURI.getPath());
一旦我有了
IContentType
,我就有了代码来查找所需的工厂。
我需要了解如何向Eclipse“注册”我的文件类型,这样当我选择要打开的文件类型时,Eclipse应用程序知道如何使用我的代码来处理它。我已经转到了Manifest.MF的Extensions选项卡,添加了扩展元素的详细信息,如基本类型、文件扩展名、id(代码所在的包)和名称。但是type仍然以null结尾。

我猜您希望使用编辑器打开文件。如果我没记错的话(从
.properties
编辑器示例中),您的编辑器贡献应该如下所示:

<extension point="org.eclipse.ui.editors">
  <editor>
  ...
  <extensions>xyz,txt,jpg</extensions> <!-- .xyz .txt and .jpg files       --> 
  <default>true</default>              <!-- default editor for these types -->
  </editor>
</extension>

...
xyz,txt,jpg
真的