![]() | The Java Developer's Guide to Eclipse |
In Chapter 26, Building a Custom Text Editor with JFace Text, you learned how JFace Text provides a framework for creating, displaying, and editing text documents. The framework is domain-independent, extensible and rich with support for building editors of syntax-oriented text, such as programming language source, XML, HTML, and SQL. It is not surprising, then, that Eclipse’s default text editor and Java editor are built using this framework.
To begin, import the example project, com.ibm.jdg2e.editor.jfacetext.sql. It
demonstrates key features of the JFace Text framework, as shown below.

test.sql file from the
com.ibm.jdg2e.editor.jfacetext.sql project in the
development (host) workspace into
the new project in the runtime workspace.test.sql file.SELECT keyword
("sel") and then Ctrl+Space, and the content proposals will
appear.

where in lower case. Notice the color syntax highlighting:

where"
is turned to uppercase "WHERE".
in the left vertical ruler.

The SQL Editor implements three editor customizations:
The implementation 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
AbstractDecoratedTextEditor. Look into the SQLEditor constructor.SQLEditorDocumentParticipant is a subclass of FileDocumentProvider.SQLPartitionScanner class extending the RuleBasedPartionScanner.
Look at the action contributor that extends TextEditorActionContributor.SQLEditorContributor class, implements
IDocumentSetupParticipant.
createActions method in the SQLEditor.
Also the class overrides the following methods: contributeToMenu – contributes actions to the menu contributeToToolBar – contributes actions to the toolbar| 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. |
SQLEditorDocumentParticipant |
This is the expected class for extensions provided for the org.eclipse.core.filebuffers.documentSetup
extension point. |
SQLEditorPlugin |
The main plug-in class. |
SQLEditorSourceViewerConfiguration |
This class defines the editor add-ons; content assist, content formatter, highlighting, auto-indent strategy, double click strategy. |
In this part of the implementation, a content assistant 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, which returns an instance
of the SQLCompletionProcessor class.
| 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 part of the implementation adds the syntax highlighting of SQL keywords. Here are the highlights of this phase of development.
SQLWordDetector
implements ISQLSyntax (a locally defined interface) and an
IWordDetector interfaces.SQLWhitespaceDetector
implements the IWhitespaceDetector interface.SQLCodeScanner extends the RuleBasedScanner and implements
ISQLSyntax.getPresentationReconciler enables highlighting in
the SQLSourceViewerConfiguration class.
| 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 and detects parts of a word. |
This part of the implementation 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 (click a class to see more information).
© Copyright International Business Machines Corporation, 2003, 2004, 2006. All Rights Reserved.
Code or samples provided herein are provided without warranty of any kind.