Using yFiles Viewer within Eclipse
Tips & TricksSummary
Description
Embedding the yFiles graph viewer component Graph2DViewused 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. 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 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 com.yworks.eclipse.sample3.zip
and follow the
instructions given below.
Technical Requirements
- Eclipse 3.4 (Ganymede), 3.5 (Galileo), 3.6 (Helios), 3.7 (Indigo), or 3.8/4.2 (Juno) with PDE and Albireo 0.0.3 (attached)
- JDK 1.5 or higher
- yFiles for Java Complete 2.7, 2.8, 2.9, or 2.10
Installation Instructions
- Unzip the attached Albireo archive into the
dropins
directory of your eclipse installation directory. - Unzip the attached Graph Editor Plugin archive into the
dropins
directory of your eclipse installation directory. This will create a new directory
com.yworks.eclipse.sample3
. - Copy the jar-file y.jar that is part of your yFiles
distribution to the subdirectory
com.yworks.eclipse.sample3/plugins/com.yworks.eclipse.sample3_<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.sample3
from the list and "Finish" the dialog.
Troubleshooting
- If eclipse reports the error Plug-in com.yworks.eclipse.sample3 was unable to load class com.yworks.eclipse.sample.GraphEditorPart.,
make sure y.jar is located in the
lib
mentioned above.