打开表单编辑器的单个实例

Open single instance of form editor

我有表单编辑器,在编辑器输入的每个双击事件中,我都需要避免打开表单编辑器的重复实例。我通过 setPartName 设置编辑器名称 我需要检查该名称并只打开一个实例

您可以在编辑器的 org.eclipse.ui.editors 定义中指定 matchingStrategy class,这样您就可以控制使用哪个编辑器打开文件,

例如这是 PDE 插件的定义。xml/MANIFEST.MF/build.properties editor:

<extension
     point="org.eclipse.ui.editors">
  <editor
        default="true"
        name="%editors.pluginManifest.name"
        icon="$nl$/icons/obj16/plugin_mf_obj.png"
        class="org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor"
        contributorClass="org.eclipse.pde.internal.ui.editor.plugin.ManifestEditorContributor"
        matchingStrategy="org.eclipse.pde.internal.ui.editor.plugin.ManifestEditorMatchingStrategy"
        id="org.eclipse.pde.ui.manifestEditor">
        <contentTypeBinding contentTypeId="org.eclipse.pde.pluginManifest"/>
        <contentTypeBinding contentTypeId="org.eclipse.pde.fragmentManifest"/>
        <contentTypeBinding contentTypeId="org.eclipse.pde.bundleManifest"/>            
  </editor>

matchingStrategyclass must implementIEditorMatchingStrategy` 有一个方法:

public boolean matches(IEditorReference editorRef, IEditorInput input)

Returns whether the editor represented by the given editor reference matches the given editor input.

Implementations should inspect the given editor input first, and try to reject it early before calling IEditorReference.getEditorInput(), since that method may be expensive.