13.3. Customizing an Editor


You’ve created a new plug-in using a PDE wizard, and you want to customize the editor.


Customize the editor’s .java file.


If you followed the discussion over the previous two recipes, you already have in hand a good template for a plug-in with an editor, and customizing that template is easy. The editor is supported by two files, MultiPageEditor.java and MultiPageEditorContributor.java. The toolbar and menu support is in MultiPageEditorContributor.java, and the actual Java support for the editor is in MultiPageEditor.java.

In this example, we’ll take a look at the code for MultiPageEditor.java and modify it. As it stands, this code displays three pages: the text in the document created by the plug-in’s wizard, a page that enables you to select the display font, and a page that displays the words in the document in sorted order. We don’t need all that in our example; we’ll just make use of the first page, which displays the text in the document in a text editor.

To display the text in the first page of the editor, the code uses an org.eclipse.editors.ui.text.TextEditor object named editor. After creating that object, you can use the MultiPageEditorPart class’s addPage method to add the new page to the editor. Here’s how it works; the code starts by creating a new TextEditor object (the MultiPageEditor class extends MultiPageEditorPart, which uses an SWT tab control to display multiple editor pages).

public class MultiPageEditor extends ...

Get Eclipse Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.