![]() | The Java Developer's Guide to Eclipse |
In Chapter 33, Swing Interoperability, you learned how to extend Eclipse using an internal launch editor and how to make a Swing editor interact with the Eclipse Platform. Most specifically, you learned how to use the resources framework to keep your editor synchronized with the Eclipse workspace.
Two examples complement Chapter 33:
com.ibm.jdg2e.swt_swing.embed.converter).
That plug-in defines a "Volume Converter" that demonstrates
how to embed an AWT/Swing application.
com.ibm.jdg2e.swing.external.launch.
It is a hybrid application
that incorporates a Swing editor in a launch-and-edit scenario, which keeps
the Eclipse workspace synchronized with the file system changes made by the
editor. The launch-and-edit example is provided as an alternative implementation
for those platforms where embedding is not yet supported.
The Swing program in this example is launched in a separate window
for files of type .abc. The application has a menu bar, toolbar,
and an area for editing text. It can open an .abc file, edit, and
save the file. The plugin.xml file registers this editor as an
external editor on .abc files. After the Swing application saves
the file, it calls the plug-in to update the Eclipse workspace.
This example demonstrates :
.abc files along with other project artifacts.To run the example, import the com.ibm.jdg2e.swing.external.launch
into your workpace and then
launch the run-time instance of Eclipse (Run >
Run As > Eclipse Application).
Create a simple project by selecting File > New > Project. Then select Simple and Project. Choose any project name you want.
abc" type file in the project by
selecting File > New > File. Name the file something
like "file.abc". When you select Finish, Eclipse
creates and opens the Swing ABC Editor on the file in a separate window.

IPath
input. In this in-process example, the class ABCEditorLauncher launches
the ABCEditor.ABCEditorLauncher class overrides the open method of the
IEditorLauncher interface. The expression
SwingEditorPlugin.getDefault().getAbcEditor
resolves to an instance of the ABCEditor. The ABCEditor.openOnEclipseFile
method is called with an IPath instance that represents
this editor's input.ABCEditor saves the instance in a variable that is referenced
later when the ABCEditor communicates changes on the file to
the editor plug-in.ABCEditor informs the Eclipse workspace whenever it makes
updates to the file system.SwingEditorPlugin implements a static method, getDefault,
which returns a singleton plug-in instance. The ABCEditor uses
the singleton instance to call the method updateWorkspace. The
updateWorkspace method requires an IPath input parameter.
| Class (All) | Description |
ABCEditor |
The ABCEditor is a simple example of a Swing application that provides
a text editor for files of type .abc. |
ABCEditorLauncher |
The editor launcher is used to launch external editors on an IPath
input with the file extension *.abc. |
SwingEditorPlugin |
The plug-in proxy maintains and synchronizes the ABCEditor tool
updates with Eclipse workspace resources. |
The classes involved in the example and their relationships are shown in the figure below. Only the key methods are illustrated.
© Copyright International Business Machines Corporation, 2003, 2004, 2006. All
Rights Reserved.
Code or samples provided herein are provided without warranty of any kind.