Skip to content

Directed Graph Example (Digraph2)

Patrick Ziegler edited this page Oct 29, 2024 · 2 revisions

Getting the source for the example

A team project set file for the digraph1 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.