The example will be based on a (made-up) markup language called minimark, which is essentially a plain text file with blank delimited paragraphs that can be translated into an HTML file. This will involve creating an editor for text-based content, for minimark files. Perform the following steps:
com.packtpub.e4.minimark.ui
by going to File | New | Project | Plug-in project and filling in the following details:com.packtpub.e4.minimark.ui
com.packtpub.e4.minimark.ui
1.0.0.qualifier
Minimark
PACKTPUB
plugin.xml
file.org.eclipse.ui.editors
to the required dependencies.)com.packtpub.e4.minimark.ui.minimarkeditor
Minimark
minimark
com.packtpub.e4.minimark.ui.MinimarkEditor
plugin.xml
will look like the following code:<extension point="org.eclipse.ui.editors"> <editor name="Minimark" extensions="minimark" default="false"class="com.packtpub.e4.minimark.ui.MinimarkEditor"id="com.packtpub.e4.minimark.ui.minimarkeditor"/> </extension>
org.eclipse.jface.text
: Provides text-processing librariesorg.eclipse.ui.editors
: The general editor supportorg.eclipse.ui.workbench.texteditor
: The general text editorMinimarkEditor
in the com.packtpub.e4.minimark.ui
package as a subclass of AbstractTextEditor
:public class MinimarkEditor extends AbstractTextEditor { }
EditorTest
. Then use the File | New | File to create a file called test.minimark
. Double-click on this file and an error will be seen, as shown in the following screenshot:TextFileDocumentProvider
:import org.eclipse.ui.editors.text.TextFileDocumentProvider; public class MinimarkEditor extends AbstractTextEditor { public MinimarkEditor() { setDocumentProvider(new TextFileDocumentProvider()); } }
test.minimark
file and an empty text editor will be opened.A basic text editor was created and associated with files ending in .minimark
.
To add an editor type, the following bundles are needed:
org.eclipse.core.runtime
org.eclipse.jface.text
org.eclipse.ui
org.eclipse.ui.editors
org.eclipse.ui.workbench.texteditor
The editor needs to be a subtype of an EditorPart
. In this case, AbstractTextEditor
provides the basic functionality for editing text-based files. It also needs to be registered with the org.eclipse.ui.editors
extension point.
Note that building editors and the document providers that underpin them is a book in its own right; the implementation of the editor here is to support the resource-processing examples. More information on writing custom editors is available in the online help.