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.
com.packtpub.e4.minimark.ui
by going to File | New | Project | Plug-in project and fill in:com.packtpub.e4.minimark.ui
com.packtpub.e4.minimark.ui
1.0.0.qualifier
Minimark
PACKTPUB
minimark
files. Open the plug-in's manifest, by right-clicking on the project and selecting Plug-in Tools | Open Manifest, or by double-clicking on the MANIFEST.MF
or plugin.xml
files.editors
and it should show up in the list (if it doesn't, uncheck the Show only extension points from the required plug-ins option and it will prompt to add org.eclipse.ui.editors
to the required dependencies).If you see a warning saying Plug-ins declaring extension points must set the singleton directive to true, then go into the MANIFEST.MF
file and add ;singleton:=true
at the end of the line containing the Bundle-SymbolicName
header. A quick fix is provided and can be chosen by clicking on the lightbulb in the margin or by pressing Ctrl + 1 when the cursor is on that line.
org.eclipse.ui.editors
extension point (if this is not added automatically, right-click on the extension point and select New | Editor from the menu to add a template extension point). Fill it in as follows:com.packtpub.e4.minimark.ui.minimarkeditor
Minimark
minimark
com.packtpub.e4.minimark.ui.MinimarkEditor
plugin.xml
will look like:<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
: This provides text-processing librariesorg.eclipse.ui.editors
: This provides general editor supportorg.eclipse.ui.workbench.texteditor
: This provides general text editorMinimarkEditor
class 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: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.
3.144.161.116