ExampleGuide-JavaEditor

Download Report

Transcript ExampleGuide-JavaEditor

Eclipse Example Guide
Example : Java Editor
1
Introduction

The Java Editor example :
» demonstrates the standard features available
for custom text editors.
» shows how to register an editor for a file
extension (in this case .jav) and
» how to define a custom Document provider for
use by that editor.
» only for demonstration purposes. Java editing
support is provided by the Eclipse Java
Tooling.
2
Learn by Doing





All programs in the book are available on the CD
that comes with the book
It is a good idea to run the programs as you read
about them
Do not forget that you will need the
SavitchIn.java file for keyboard input
Classes are used to define objects and provide
methods to act on the objects
Classes are also programs that declare these
objects and process them to solve the problem
3
Features demonstrated






syntax highlighting
content type sensitive content assist (JavaDoc and Java
code)
communication between content outliner and editor,
» i.e. content outliner selection feeds the highlight range
of the editor
two different presentation modes
» marking the highlight range using a visual range
indicator
» confining the editor to show only text within the
highlight range (e.g. show a single method of a Java
class)
marker handling
document sharing
4
How to run the editor
5
Principles for creating custom text editors
1.
2.
3.
4.
5.
Create a document provider.
Create a document partitioner
Determine source viewer plugins to be provided
Create for all source viewer plugins the
appropriate extensions for each supported
content type
Build a source viewer configuration using the
previously created plugins and extensions.
6
6. Customize the class TextEditor or AbstractTextEditor with
the developed document partitioner and source viewer
configuration.
» Add or replace actions and adapt the construction of
the editor's context menu. In the actual version, this
customization must be done in a subclass. See
JavaEditor in the example editor.
7. Set up an appropriate action bar contributor who
contributes editor-related actions to the desktop's
toolbar and menus. See JavaActionContributor in the
example editor.
8. Extend the XML configuration file of the editor's plugin, so
that the editor registers at the predefined editor
extension point for a specific set of file extensions. Also
set up the action bar contributor in the XML file. See
plugin.xml of this example.
7
Code organization





four packages:
org.eclipse.ui.examples.javaeditor
» contains all the editor specific classes.
org.eclipse.ui.examples.javaeditor.java
» contains all Java specific source viewer plugins such
as the JavaDamagerRepairer as well as the Java
specific document partitioner.
org.eclipse.ui.examples.javaeditor.javadoc
» contains all JavaDoc specific source viewer plugins
such as the JavaDocDamagerRepairer.
org.eclipse.ui.examples.javaeditor.util
» contains convenience classes shared by the three
other packages.
8