The Java example editor inherits a lot of useful default behavior from AbstractTextEditor. The text editing framework handles several other responsibilities that you can customize by overriding methods in AbstractTextEditor. Browse the implementation of this class and its subclasses to see how behavior is customized in the framework.
The following are some of the useful framework features that can be configured.
Text editors typically contribute user preferences that control the presentation and behavior of the editor. In the text framework, each text editor instance has an associated preference store that is used for accessing user preferences. This preference store can be set up by your editor, or you can inherit from preference stores already used in the framework.
In the case of the Java example editor, it inherits the preference store initialized by TextEditor. This is the preference store defined by the workbench editors plug-in.
protected void initializeEditor() { ... setPreferenceStore(EditorsPlugin.getDefault().getPreferenceStore()); }The editors plug-in preferences can be manipulated in the Workbench > Editors and Workbench > Editors > Text Editor preference pages.
If you do not want to use the standard workbench text preferences for your editor, you can set a different preference store. This is typically done by overriding initializeEditor and setting your own preference store. If you do use your own preference store, you will also need to override the method handlePreferenceStoreChanged() which is triggered whenever a preference is updated.
Key binding scopes are useful for establishing a lookup order for key bindings. Having contextual scopes reduces the chances of different plug-ins contributing conflicting key sequences. By default, the workbench operates in a global scope. When a text editor becomes active, it is responsible for resetting the scope to the text editor scope, so that editor specific key bindings will be active.
In the platform text framework, each text editor instance has an associated key binding scope. It is responsible for setting this scope when it becomes active. TextEditor defines this scope and takes care of making it active. The scope is assigned in a method that is called from the constructor:
protected void initializeKeyBindingScopes() { setKeyBindingScopes(new String[] { "org.eclipse.ui.textEditorScope" }); }
The argument to the method is an array of string key binding scope ids. If you want your editor to define its own key binding scope, then you can override this method in your editor class, or set the scope dynamically using setKeybindingScopes.
The scope itself must be defined with the corresponding id in the org.eclipse.ui.commands extension point. The following is the definition for the text editor scope.
<extension point="org.eclipse.ui.commands"> ... <scope name="%scope.text.name" parent="org.eclipse.ui.globalScope" description="%scope.text.description" id="org.eclipse.ui.textEditorScope"> </scope> </extension>