Search code examples
eclipse-plugineclipse-rcp

Open single instance of form editor


I have Form Editor and on every double click event on editor input I need to avoid duplicate instance of the form editor to open. I'm setting the editor name by setPartName I need to check that name and to be open only one instance


Solution

  • You can specify a matchingStrategy class in your org.eclipse.ui.editors definition of the editor which lets you control which editor is used to open files,

    For example this is the definition of the PDE plugin.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>
    

    The matchingStrategyclass must implementIEditorMatchingStrategy` which has one method:

    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.