![]() |
In the Swing Interoperability lecture you learned how to extend Eclipse using
an internal launch editor and how to make
a Swing editor interact with the foundation
of the Eclipse Platform. Most importantly,
you learned how to use the resources framework
to keep the Eclipse workspace in sync when
file changes file are made in the editor.
The solution presents a practical examples that demonstrates
how you can implement such a hybrid application.
This solution is located in the project com.ibm.lab.soln.swing.interlaunch.extras
.
The example swing program is launched in
a separate window on a file of type .abc
. The application has a menu bar, toolbar,
and a area for editing text. It can open
a .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
file along with other project artifacts.Note:
To run the example, launch the run-time instance of Eclipse (Run > Run As > Run-time Workbench).
Create a simple project. Select File > New > Project... Then select Simple and Project. Give the project any name you want.
abc
" type file in the project.
Select File > New > File. Name the file something like "file.abc
". When you push Finish, Eclipse creates and opens the Swing ABC
Editor on the file in it's own window.
IFile
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 IFile
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 IFile
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 IFile 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 solution and their relationships are shown in the figure below. Only the key methods are illustrated.