org.eclipse.ui.editors

An editor is a workbench part that allows a user to edit an object (often a file). Editors operate in a manner similar to file system editing tools, except that they are tightly integrated into the platform workbench UI. An editor is always associated with an input object (IEditorInput). You can think of the input object as the document or file that is being edited. Changes made in an editor are not committed until the user saves them.

Only one editor can be open for any particular editor input in a workbench page. For example, if the user is editing readme.txt in the workbench, opening it again in the same perspective will activate the same editor. (You can open another editor on the same file from a different workbench window or perspective).  Unlike views, however, the same editor type, such as a text editor, may be open many times within one workbench page for different inputs. The editor input can also be a path to an in memory model, as in the InfoEditor example.

The workbench extension point org.eclipse.ui.editors is used by plug-ins to add editors to the workbench. Plug-ins that contribute an editor must register the editor extension in their plugin.xml file, along with configuration information for the editor. Some of the editor information, such as the implementation class and the name and the icon to be used in the workbench menus and labels, is similar to the view information. In addition, editor extensions specify the file extensions or file name patterns of the file types that the editor understands. Editors also use org.eclipse.ui.commands and org.eclipse.ui.menus to contribute to the workbench menus and toolbars when that editor is active.

The interface for editors is defined in IEditorPart, but plug-ins can choose to extend the EditorPart class rather than implement an IEditorPart from scratch.

Note:  An editor extension can also be configured to launch an external program or to call pre-existing java code. In this discussion, we are focusing on those editors that are actually tightly integrated with the workbench and are implemented using IEditorPart.

The editor can contribute its own content outliner page to the workbench outline view.  

The configuration for the editor extension is defined as follows.

<extension
    point = "org.eclipse.ui.editors">
      <editor
            class="org.eclipse.ui.examples.contributions.editor.InfoEditor"
            icon="icons/editor.gif"
            id="org.eclipse.ui.examples.contributions.editor"
            name="%contributions.editor.name">
      </editor>
</extension>

We see the familiar configuration markup for id, name, icon (which must be specified when specifying class), and class.   You could use the extensions attribute describes the file types that the editor understands, like extensions="person", although this example doesn't need it. (You could also specify filenames if you need to be more specific.)  The class implements the editor.

Editor menus and editor toolbars are placed in the main menu and main toolbar. See org.eclipse.ui.menus for how to use the locationURI to place the commands correctly.

Showing a global menu additions

These menu and tool bar items can be shown only when the editor is active using core expressions. To define a re-usable core expression for your editor, use org.eclipse.core.expressions.definitions

<extension
    point = "org.eclipse.core.expressions.definitions">
      <definition id="org.eclipse.ui.examples.contributions.view.activeEditor">    
         <with variable="activeEditorId">
            <equals value="org.eclipse.ui.examples.contributions.editor"/>
         </with>
      </definition>
</extension>

Editors and content outliners

Although the Info Editor does not, editors often have corresponding content outliners that provide a structured view of the editor's contents and assist the user in navigating through the contents of the editor.  See Content outliners for more detail.

We'll look at the implementation of text editors in Text editors and platform text.