How to write a MultiPage Editor Eclipse plug-in

Eclipse comes with a small set of example plug-ins that need to be downloaded separately. For example, for the latest release (Eclipse 3.2 M5) get the example plug-ins from here.

If you have done this and looked at the source code for org.eclipse.ui.examples.multipageeditor, you see that it’s rather simple to add a multi-page editor to your plug-in.

Here are the steps though (this assumes you already know the basics for writing Eclipse plug-ins):

1- Add a new extension to org.eclipse.ui.editors
2- For the class, make sure you have it extend MultiPageEditorPart
3- Associate this plug-in extension with mpe files (or any other file extension you like)
4- Add the editor pages in createPages. For example:


    protected void createPages() {
        createPage0();
        createPage1();
    }

5 - Each createPageX() basically creates a Composite then adds it to the editor by calling addPage(composite). This method returns the page index in the editor. Get the index and call setPageText(index, "page name") to give the page tab a name.

That’s basically it, nice an easy. Run the plug-in, add an “mpe” file (if that’s the file extension you associated with the plug-in) and you should see something like this:

Multi-page editor, with 3 pages for viewing .mpe files.

Leave a Comment