Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagehtml/xml
<extension point="de.cau.cs.kieler.kiml.layoutProviders">
    <layoutOption
        id="de.cau.cs.kieler.nodeLabelPlacement"
        name="Node Label Placement"
        description="Hints for where node labels are to be placed; if empty, the node label's position is not modified."
        advanced="true"
        appliesTo="nodes"
        type="enumset"
        class="de.cau.cs.kieler.kiml.options.NodeLabelPlacement"
        default="">
    </layoutOption>
</extension>

Such declarations are provided by layout algorithm developers, but not by tool developers who merely want to connect the layout infrastructure to their diagram viewers. Let's walk through the attributes available for layout options (not every available attribute appears in the example above):

...

By now, we have an idea of what layout options do and why they are important in the first place. However, we haven't looked at how layout options end up on KGraph elements yet. This is where the LayoutOptionManager comes in. If you are not interested in the internal details, but want to configure automatic layout for your diagram viewer or editor, you may skip this section and proceed to programmatically setting layout options.

After a diagram layout manager has finished turning a given diagram into its KGraph representation, the layout option manager is asked to enrich the KGraph elements with layout options. The option values can come from different sources: the user might have set some using the layout view; there might be some defaults for certain kinds of diagrams; or the programmer might have decided to attach some layout options to certain elements for just this one layout run. Whatever the source, the options manager is in charge of collecting all these layout option values and making sure they find their way to the correct KGraph element. To start off with a clean plate, it first makes sure there are no layout options attached to the KGraph elements. It then does two things: collect every eligible source of layout options, and transfer values of layout options to the associated KGraph elements. Sounds easy enough.

...

Programmatically Setting Layout Options

Anchor
programmatic-config
programmatic-config

So with all these layout configurators available, how do you actually go about setting values for layout options programmatically? Well, as always: it depends.

...

Here class refers to a domain model class, in this case the EReference class from the Ecore meta model defined by EMF, and option refers to a layout option through its identifier. The meaning of this declaration is that whenever automatic layout is requested for an Ecore class diagram, the edgeType option is set to ASSOCIATION for all edges linked to instances of EReference. Since the domain model (abstract syntax) is independent of the specific diagram viewer (concrete syntax), this configuration is applied to all diagram viewers that use the Ecore meta model.

Alternatively to domain model elements, staticConfig may also reference concrete syntax elements:

Code Block
languagexml
      <staticConfig
            class="org.eclipse.emf.ecoretools.diagram.edit.parts.EClassESuperTypesEditPart"
            option="de.cau.cs.kieler.edgeType"
            value="GENERALIZATION">
      </staticConfig>

This layout option value is applied only to edges linked to instances of EClassESuperTypesEditPart, which is a concrete syntax element of the Ecore Tools class diagram editor. Other Ecore meta model editors are not affected by this declaration. This distinction is particularly useful for meta models that are accessed with multiple different editors, as is often the case for UML tools.

A third variant is the use of diagram types, as in this example:

Code Block
languagexml
      <diagramType
            id="de.cau.cs.kieler.layout.diagrams.classDiagram"
            name="Class Diagram">
      </diagramType>
      <staticConfig
            class="org.eclipse.emf.ecore.EPackage"
            option="de.cau.cs.kieler.diagramType"
            value="de.cau.cs.kieler.layout.diagrams.classDiagram">
      </staticConfig>
      <staticConfig
            class="de.cau.cs.kieler.layout.diagrams.classDiagram"
            option="de.cau.cs.kieler.edgeRouting"
            value="SPLINES">
      </staticConfig>

A diagram type can be declared with a diagramType element and can be associated with an abstract syntax or concrete syntax class using the diagramType option, as shown in the first staticConfig declaration in the example above. The second staticConfig sets an option for the declared diagram type by using its identifier in the class attribute. This kind of indirection is very useful when you have n model classes and you want to set m layout options for each of those classes. Instead of writing n × m static declarations, you assign a diagram type t to each of the n classes and then declare the m layout options for t, resulting in n + m option declarations (in many cases n + m < n × m).

A further use of diagram types is for the selection of layout algorithms: a layout algorithm may declare that is is especially suited to process diagrams of certain type t. If the diagram type t is assigned to a diagram viewer, the most suitable layout algorithm is chosen automatically for that viewer.