Using yFiles Viewer within Eclipse
Applies to: yFiles 2.6 print article email article

Type: Tips & Tricks

Categories this article belongs to:
yFiles for Java > Deployment
yFiles for Java > yFiles Viewer

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 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. 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

  1. 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>.
  2. Copy the jar-file y.jar that is part of your yFiles distribution to the subdirectory
    plugins/com.yworks.eclipse.sample2_<version>/lib.
  3. Start Eclipse.

Using the Plugin

  1. The creation wizard [File->New->Other...] can be used to create a new yFiles diagram inside your project.
  2. Opening a yFiles diagram of type .gml, .graphml or .ygf will open the yFiles graph editor for that diagram.
  3. 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.
  4. Standard operations like undo/redo and clipboard can be used from the eclipse edit menu when the graph editor is active.
  5. 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

  1. 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.
  2. 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.

Keywords: Eclipse - SWT - Graph2DView

Provide feedback:
How useful was this article?    less 1 2 3 4 5 more
Email address (optional):
COPYRIGHT © 2008 yWorks · ALL RIGHTS RESERVED imprint | top | home