Graphical Editing Framework (GEF) Directed Graph Example (Digraph2)

Getting the source for the example

A team project set file for the digraph2 example is here. Download the team project set file and do the following to import the plug-in project into your workspace.

  • From the File menu, choose Import. This will open the Import dialog.
  • In the Import dialog, choose Team > Team Project Set and click Next.
  • Browse for or type in the name of the project set file and click Finish.
  • The digraph2 project contained in the project set will be fetched from the CVS repository on Eclipse.org.

The example was created with Eclipse 3.3 and GEF 3.3


Basic Graphical Editor with Connections

The objective of the digraph2 example is to add connections to the digraph1 example.

digraph2_editor

Model

We add edges (Digraph2Edge) to our domain model.

Figure

Each edge figure is a PolylineConnection. We also add Digraph2ConnectionAnchor to anchor the edges to the nodes. The edges are anchored to the bottom center and top center of the nodes.

EditPart

We add an EditPart for edges (Digraph2EdgeEditPart). We also need to make Digraph2NodeEditPart implement NodeEditPart to add source and target connections to the nodes in our directed graph. We finally added a ManhattanConnectionRouter to the ConnectionLayer in the refreshVisuals() method in our Digraph2GraphEditPart.

Factory

We add Digraph2EdgeEditPart to Digraph2EditPartFactory.

Policy

We make use of a ConnectionEditPolicy to place the edges on the graph (Digraph2ConnectionEditPolicy).

Editor

We did not need to make any additional changes to our Digraph2GraphicalEditor.

Opening the Example Editor

The graph example editor opens for any file with the digraph2 file extension. So we need a project and file in the workspace to open the editor. First, create a new project resource File > New > Project. Then a new file resource, such as file.digraph2 using File > New > File. After creating the file, the Directed Graph Example Editor will open.


By Anthony Hunter, IBM Rational Software
: /cvsroot/org.eclipse/www/gef/reference/digraph2.php,v 1.3 2007/11/16 04:37:12 ahunter Exp $

    Please send comments about this example document to the eclipse.tools.gef newsgroup.