Best-Practice: Developing a Model-Based Editor - Preparation
3. March 2006
Developing a Model-Based Editor - TOC
The following describes the basics of creating editors.
Declaring the extension-point
In our example we want to provide an simple editor for the object org.javawiki.model.SubProcess and a MultiPageEditor with two pages for the object org.javawiki.model.Step. At first we define the extension points.
-
contributorClass="org.javawiki.editors.ProcessEditorContributor"
-
default="false"
-
extensions="step"
-
icon="icons/sample.gif"
-
id="org.javawiki.editors.StepEditor"
-
name="StepEditor"/>
-
contributorClass="org.javawiki.editors.ProcessEditorContributor"
-
default="false"
-
extensions="subp"
-
icon="icons/sample.gif"
-
id="org.javawiki.editors.parts.SubProcessEditor"
-
name="SubProcessEditor"/>
Declaration in the plugin.xml
Managing the Object-Editor-Mapping
The assignment which object-signature is linked with a special editor is realized in the EditorContributor. This class knows the correct editor-id (specified in your plugin.xml) to a special Object.
-
public static final String SUBPROCESS_EDITOR_ID = "org.javawiki.editors.parts.SubProcessEditor"; //$NON-NLS-1$
-
static {
-
editorMapping.put(Step.class,STEP_EDITOR_ID);
-
editorMapping.put(SubProcess.class,SUBPROCESS_EDITOR_ID);
-
}
-
/**
-
* Returns the correct editor id by the given
-
* class-signature
-
* @param clazz the class of the object that will be
-
* edited with an Editor
-
* @return the editor-id definded in the <code>plugin.xml</code>
-
*/
-
}
Open programmatically an editor
The command for opening an editor is:
-
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(
-
myEditorInput,"editor.id.specified.in.plugin.xml");
In the Best-Practice example we wrote a wrapper for opening an editor, the ResourceHandler, that has a Method #openEditor(final AbstractBaseElement model) and a method for checking if the model is already represented by an open editor #getEditorIndex(IEditorInput input)
Open the editor on doubleClick on an item in the JFace-Viewer
Just add an IDoubleClickListener and call the ResourceHandler
-
this.viewer.addDoubleClickListener(new IDoubleClickListener() {
-
public void doubleClick(DoubleClickEvent event) {
-
ResourceHandler.getDefault().openEditor(
-
(AbstractBaseElement) ((IStructuredSelection) event.getSelection()).getFirstElement());
-
}
-
});
Conclusion
OK, what do we have? - We have two editors defined (without any implementation), the assignment from editor to model-object and the capability to open an editor on double-click on an elemnt in the JFace-Viewer. Now only the editors are missing.
Let's take the rest!!!


