In the Building a Custom Text Editor with JFace Text lecture 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`.

## Running the Solution

1. In the PDE perspective, launch and run a runtime workbench (Run > Run As > Run-time Workbench).
2. Create a new project in the workspace of the run-time workbench..
3. Copy the `test.sql` file from the host/build-time workspace into the new project in the runtime-workspace.
4. Open the `test.sql` file.
5. Use the the content assist; type in part of the select, type the letters, "s e l", and then CTL+Space bar, and the content proposals will appear.
6. Type in the word where in lower case. Notice the color syntax highlighting.
7. Select Edit > Content Format and notice that "where" is turned to upper case "WHERE".

## Roadmap of the Solution

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

### Phase 1

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.

- The `SQLEditor` class extends `AbstractTextEditor`. Look into the `SQLEditor` constructor.
- The `SQLDocumentProvider` is a subclass of `FileDocumentProvider`.
- The `SQLPartitionScanner` class extending the `RuleBasedPartionScanner`. Look at the action contributor that extends `TextEditorActionContributor`.
- The `SQLEditorContributor` class, subclasses `TextEditorActionContributor`.
- Look for the menu item string resources in the plug-in properties files.
- Look at the method `createActions` method in the `SQLEditor`. Also the class overrides the following methods:
  `contributeToMenu` - contributes actions to the menu
  `contributeToToolBar` – contributes actions to the toolbar
- See the SQL editor extension in the plug-in manifest file.

  Basic 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.

### Phase 2

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.
- The content processor class implements the`IContentAssistProcessor` and implements the`ISQLSyntax` interfaces.
- The `SQLDoubleClickStrategy` implements the double click handler.
- The `SQLCompletionProcessor` computes the content assist proposals in the `computeCompletionProposals` method.
- The `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.

  ###

  ###

### Phase 3

This phase adds the syntax highlighting of SQL keywords. Here are the highlights of this phase of development.

- The S`QLWordDetector` implements the`ISQLSyntax (`a locally defined interface) and an `IWordDetector` interfaces.
- The S`QLWhitespaceDetector` implements the `IWhitespaceDetector` interface.
- The `SQLCodeScanner` extends the RuleBasedScanner and implements `ISQLSyntax`.
- The method `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.

### Phase 4

This phase adds the content formatting of SQL keywords. Here are the highlights of this phase of development.

- The `SQLWordStrategy` class that implements `IFormattingStrategy` and `ISQLSyntax`.
- The `getContentFormatter` method of the class `SQLSourceViewerConfiguration`, returns the formatting strategy.

###

### Formatting Specific Implementation

Class (All) | Description
`SQLWordStrategy` | The formatting strategy that converts SQL keywords to upper case.

## Class Diagrams

The classes involved in the solution and their relationships are shown in the figure below. Only the key methods are illustrated.

###

###