Describes how to embed the yFiles graph view within the Eclipse workbench.
| Note |
|
There is another article which describes how to use only the yFiles layout algorithms with Eclipse and GEF, the Graphical Editing Framework.
|
Embedding the yFiles graph viewer component
Graph2DView
used to be complicated since Eclipse is based on the widget toolkit SWT and the graph view on the standard Java toolkits AWT and Swing. Fortunately, there is a SWT-AWT bridge since Eclipse 3.0 that makes it possible to embed Swing-based components in the Eclipse workbench. Since
the intergration using the bridge is quite low level, some tasks remain untackled. A recent Eclipse
project,
Albireo, aims at providing a higher-level integration.
The example below shows how to embed an editable Graph2DView as part control of an eclipse editor component using the
SwingControl class provided by Albireo.
public class GraphEditor extends EditorPart {
...
private SwingControl;
public void createPartControl(final Composite parent) {
swingControl = new SwingControl(parent, SWT.NONE) {
protected JComponent createSwingComponent() {
Graph2DView view = new Graph2DView();
view.addViewMode(new EditMode());
return view;
}
public Composite getLayoutAncestor() {
return parent;
}
};
}
public void setFocus() {
swingControl.setFocus();
}
} |
Graph Editor Plugin
We have prepared a comprehensive sample plugin that demonstrates how yFiles can be used to integrate
a diagram editor in the eclipse workbench. To try out the plugin and inspect its source code, please download the attached Zip archive and follow the instructions given below.
Technical Requirements
- Eclipse 3.3 (Europa) or 3.4 (Ganymede) with PDE and
Albireo 0.0.2
- JDK 1.5 or higher
- yFiles Complete 2.6 for Java
Installation Instructions
- Unzip the distributed zip file inside your eclipse directory (or the dropins
subdirectory in Eclipse 3.4). This will create a new directory
plugins/com.yworks.eclipse.sample2_<version>.
- Copy the jar-file y.jar that is part of your yFiles
distribution to the subdirectory
plugins/com.yworks.eclipse.sample2_<version>/lib.
- Start Eclipse.
Using the Plugin
- The creation wizard [File->New->Other...] can be used to create
a new yFiles diagram inside your project.
- Opening a yFiles diagram of type .gml, .graphml or .ygf will open the yFiles
graph editor for that diagram.
- A Properties View will allow you to
view and edit the properties of selected graph elements.
Choose [Window->Show View->Other...->Basic->Properties] from
the menu bar.
- Standard operations like undo/redo and clipboard can be used from
the eclipse edit menu when the graph editor is active.
- When the graph editor has focus, the menu item
"Layout Diagram" provides access to some of the yFiles layout algorithms.
Setting up an Eclipse Project for the Plugin
- Once the graph editor has been installed in the eclipse
plugin directory as described above, the plugin including
its source code can be imported as an eclipse plugin project.
- Choose [File->Import...] from the menu bar. Next, choose
"Plug-Ins and Fragments" from the list. On the next page
choose Import As "Projects with source folders". On the next page
"Add" the yFiles plugin name com.yworks.eclipse.sample2 from the list
and "Finish" the dialog.