![]() | The Java Developer's Guide to Eclipse |
NOTE:
This project fixes the incompatibility between the version 2.0 and 2.1 editor key bindings.
In Chapter 27, Building a Custom Text Editor with JFace Text, you
walked through an example of building a custom text editor. The completed implementation
of a SQL editor is contained on the CD-ROM in the project com.ibm.lab.soln.sqltexteditor
.
test.sql
file from the host/build-time workspace
into the new project in the runtime-workspace.test.sql
file.The SQL Editor implements three editor customizations:
1. SQL keywords are available using content
assist.
2. Using syntax highlighting, SQL keywords
are colorized.
3. The formatter folds all SQL keywords to upper case.
Explore the steps required to implement this editor in four phases. A basic source editor is delivered in phase one. Phase two delivers content assist. Phase three adds syntax-color highlighting. Finally, phase 4 delivers content formatting
The implementaion phases begins with the creation of an editor with only the
basic text editing functions. Here are the highlights of the basic text editing
implementation.
SQLEditor
class extends AbstractTextEditor
. Look into the SQLEditor
constructor.SQLDocumentProvider
is a subclass of FileDocumentProvider
.SQLPartitionScanner
class extending the RuleBasedPartionScanner
. Look at the action contributor that extends
TextEditorActionContributor
.SQLEditorContributor
class, subclasses TextEditorActionContributor
.
createActions
method in the SQLEditor
. Also the class overrides the following
methods: contributeToMenu
- contributes actions to the menu contributeToToolBar
– contributes actions to the toolbarBasic Editor Classes
Class (All) | Description |
SQLEditor |
This class is responsible for configuring the SQL editor. |
SQLEditorContributor |
Manages the installation and deinstallation of actions for the SQL editor. |
SQLEditorDocumentProvider |
This DocumentProvider class, which implements IDocumentProvider, creates and manages the document content. |
SQLEditorPlugin |
The main plugin class. |
SQLEditorSourceViewerConfiguration |
This class defines the editor add-ons; content assist, content formatter, highlighting, auto-indent strategy, double click strategy. |
In this phase, a content assistant is implemented that provides completion proposals for SQL keywords. Here are the highlights of the contents assist implementation.
ISQLSyntax
implements an interface that encapsulates
the SQL syntax. IContentAssistProcessor
and implements the ISQLSyntax
interfaces.SQLDoubleClickStrategy
implements the double click handler.SQLCompletionProcessor
computes the content assist proposals in
the computeCompletionProposals
method.SQLSourceViewerConfiguration
class extends SourceViewerConfiguration
. The key method is getContentAssitant
, that returns an instance of the SQLCompletionProcessor
class.SQL Specific Implementations
Class (All) | Description |
ISQLSyntax |
Contains the SQL syntax words (upper and lower cases). |
SQLCodeScanner
|
The SQLCodeScanner is a RuleBaseScanner .This class finds SQL comments and keywords,
as the user edits the document. It is "programmed"
with a sequence of rules that evaluates and
returns the offset and the length of the
last found token. |
SQLCompletionProcessor |
The SQL content assist processor. This content assist processor proposes completions and computes context information for a SQL content type. |
SQLDoubleClickStrategy |
Process double clicks in the SQL content. |
SQLPartitionScanner |
The SQLPartitionScanner is a RulesBasedPartitionScanner . The SQL document partitions are computed
dynamically as events signal that the document
has changed. The document partitions are
based on tokens that represent comments and
SQL code sections. |
This phase adds the syntax highlighting of SQL keywords. Here are the highlights of this phase of development.
QLWordDetector
implements the ISQLSyntax (
a locally defined interface) and an IWordDetector
interfaces.QLWhitespaceDetector
implements the IWhitespaceDetector
interface.SQLCodeScanner
extends the RuleBasedScanner and implements
ISQLSyntax
.getPresentationReconciler
enables highlighting in the SQLSourceViewerConfiguration
class.SQL Plugin Utilities
Class (All) | Description |
ColorProvider |
Colors used in the SQL editor. |
SQLWhiteSpaceDetector |
A class that determines if character is a SQL white space character. |
SQLWordDetector |
Determines whether a given character is valid as part of a SQL keywords in the current context. |
WordPartDetector |
Scans aand detects parts of a word. |
This phase adds the content formatting of SQL keywords. Here are the highlights of this phase of development.
SQLWordStrategy
class that implements IFormattingStrategy
and ISQLSyntax
.getContentFormatter
method of the class SQLSourceViewerConfiguration
, returns the formatting strategy.Class (All) | Description |
SQLWordStrategy |
The formatting strategy that converts SQL keywords to upper case. |
The classes involved in the solution and their relationships are shown in the figure below. Only the key methods are illustrated.