Introducing DLTK and the DLTK editor
Eclipse offers many capabilities for building custom development tools,
but they're not easy to use or understand. Many of the classes, such
as TextEditor, require significant
configuration to work properly. In contrast, the DLTK provides a
prepackaged development environment that requires only minor tweaking
to be operational. Building a development tool with the DLTK is like
baking a cake from a mix: The output isn't completely original, but
you get a maximum of quality and reliability with a minimum of effort.
A second important difference between DLTK and Eclipse involves the
supported languages. Eclipse's build capabilities are based on
compiled languages like Java, C, and
C++. The DLTK is geared toward dynamic
languages, which include scripting languages like PHP, Ruby,
and Tcl. Ideally, a development tool for these languages supports easy
integration of script interpreters, command evaluation on a
line-by-line basis, and the ability to enter commands at a console.
Eclipse doesn't provide these features, but the DLTK supports them
all.
If you haven't installed the DLTK, do so now. Perform the following steps:
- Open Eclipse, then click Help > Install New Software.
- Select Indigo - http://download.eclipse.org/releases/indigo from the Work with list.
- Select the General Purpose Tools > Dynamic Languages Toolkit - Core Frameworks check box, then click Next.
- Click Next after reviewing the prerequisites that will also be installed.
- If you accept the license agreements, click Finish to install the plug-in.
- After installing the files, restart Eclipse.
The DLTK-based plug-in project: The Octave IDE
This tutorial does more than just discuss the DLTK and its features. It walks you through the steps of creating an DLTK-based IDE for the Octave scripting language. Octave is a GPL-licensed toolset for performing mathematical computation, particularly with matrices. Octave commands are easy to understand, and the language closely resembles that of the popular proprietary Matlab tool. You can download the example code from Download.
The Octave IDE you'll be building won't have all of Eclipse's bells and whistles, but you will be able to create Octave scripts (*.m files), edit them in a multifeatured text editor, run the Octave interpreter with the click of a button, and see the result displayed in the IDE's console. Figure 1 shows what the editor and console look like.
Figure 1. The Octave IDE
This tutorial explains the process of building the Octave IDE in four steps:
- Create the Octave editor and add features.
- Store and respond to user preferences.
- Integrate the Octave interpreter.
- Display the interpreter's output in the console.
The first task deals with the Octave script editor. There's a lot to learn about this subject, but before you start coding, let's take a step back and look at how DLTK editors work. Much of this discussion applies to all Eclipse text editors.
A high-level introduction to the DLTK text editor
At its most basic level, the DLTK text editor is just a regular SWT
StyledText widget with a lot of additional
capabilities. These capabilities fall into one of two categories:
- Responding to user events. Changing the editor's display according to the user's keystrokes
- File I/O. Transferring character data between the IDE and files on the user's system
In DLTK editors, event handling is managed by a
ScriptSourceViewer object. This object,
created by the ScriptEditor, wraps around
the StyledText widget and manages its
response to user keystrokes. Typically, this response involves
modifying the widget's presentation or updating the editor's internal
data. This data is embodied in an IDocument
object, which not only stores text but also information related to
line numbers, positions, and regions, called partitions.
The ScriptSourceViewer updates the
IDocument by accessing an object called a
SourceModuleDocumentProvider. In addition
to providing access to the IDocument, this
object handles file operations. DLTK handles all the editor's file
interactions for you, but if you're interested in learning more, read
the documentation on the object's superclass:
TextFileDocumentProvider.
If you're familiar with the MVC pattern, the relationship between the
ScriptSourceViewer,
IDocument, and
StyledText widget should be clear. The
IDocument serves as the editor's Model
aspect, containing data independent of its presentation. The
StyledText widget represents the editor's
View aspect, and the ScriptSourceViewer
serves as the Controller, managing communication among the Model, the
View, and the user. Figure 2 shows this
relationship.
Figure 2. Primary elements of the DLTK editor
If the explanation thus far makes sense and Figure 2 seems reasonable, you should have no difficulty understanding the technical discussion that follows. In the next section, you start creating the Octave plug-in.





