If you build a graphical editor with Graphiti normally you have to do the layout by your own. But you can use KIELER (The Kiel Integrated Environment for Layout). It provides an automatic layout for graphical editors built with Graphiti or GMF.
The following figure shows the class diagram editor, which is one of the shipped Graphiti examples. I just draw four classes and some relationships and as you can see, I intentionally placed them very badly. Now it’s time to use KIELER, just press the marked icon in the Eclipse toolbar or press Ctrl+R, L. You can also use the KIELER menu or the KIELER context menu in the Graphiti editor, but they will be removed in one of the next versions.
The next figure shows the diagram after the diagram is layouted with KIELER. The default values are used. You can e.g. change the Spacing of the diagram to 100.0 and let KIELER layout the diagram again. Therefore click in the editing area to change the
layout properties for the diagram. You can also change the layout properties for EClasses, EReferences and the Connection Decorators.
Now you can see the result after another layout with Spacing 100.
Take your time to discover all the properties of the different Layout Algorithms. It’s
very interesting to see the different Layout Algorithms in action!
Many thanks to the KIELER team, great work!
In a future article I will describe how to use KIELER for containment hierachies and
how to use KIELER programmatically to layout more complicated diagrams.
Be aware that KIELER is mostly EPL and the OGDF layout is under GPL. But it’s in an optional feature and can be omitted when using KIELER in your product.
I used the following versions:
|KIELER Layout for Graphiti||0.7.0.201208310315|
|Graphiti Tools (Incubation)||0.9.1.v20120919-0732|
Table 1. Plugin version info