Pages

Friday, April 25, 2014

GMF Partitioning

GMF allows the creation of diagram models by partitioning some of its components. It means, one diagram model can expand certain components (by double clicking) in order to visualize better those components.

For this purpose, next metamodel is used. The objective is creating one diagram that allows creating only containers. Double clicking on one container, a new diagram allows creating elements and relations

It is very important to set values to the package. In this case, the name is "partitioning"

EMF Editor Generation

The EMF Editor contains all necesary implentation for creating models. It can be created by the following steps

  1. Create genmodel
    • Select the metamodel. In this case model.ecore
    • Right click > Generate EMF GenModel
  2. Create Editor code
    • Select the metamodel. In this case model.ecore
    • Right click > Generate EMF editor

The genmodel file is created. In addition the projects edit, editor, and test are created as well

Model editor (main diagram)

This process allows creating the main diagram. In this case the main diagram is used for creating containers This diagram is based on the EClass Model

Generate Simple Graphical Definition Model (.gmfgraph)
  1. Select the metamodel. In this case model.ecore
  2. Right click > New > Other > Graphical Modeling Framework > Simple Graphical Definition Model
  3. Select the root EClass. In this case Model
  4. Only specify the EClasses of the nodes that will exist. In this case Container
Generate Simple Tooling Definition Model (.gmftool)
  1. Select the metamodel. In this case model.ecore
  2. Right click > New > Other > Graphical Modeling Framework > Simple Tooling Definition Model
  3. Select the root EClass. In this case Model
  4. Only specify the EClasses of the nodes that will exist. In this case Container
Generate Guide Mapping Model Creation (.gmfmap)
  1. Select the metamodel. In this case model.ecore
  2. Right click > New > Other > Graphical Modeling Framework > Guide Mapping Model Creation
  3. Select Diagram Palette
  4. Select Diagram Canvas
  5. Select the nodes. In this case Container. Delete other nodes and links
Create Generator Model (.gmfgen) and Model Diagram Code
  1. Select Mapping Model. In this case model.gmfmap
  2. Right click > Create generator model
  3. Select Generator Model. In this case model.gmfgen
  4. Right click > Create diagram code
Container editor (sub diagram)

This process allows creating the diagram for creating elements and relations. This diagram is based on the EClass Container. This diagram will be open by double clicking on one container from the Model diagram

Generate Simple Graphical Definition Model (.gmfgraph)
  1. Select the metamodel. In this case model.ecore
  2. Right click > New > Other > Graphical Modeling Framework > Simple Graphical Definition Model
  3. Give a different name (e.g. container.gmfgraph)
  4. Select the root EClass. In this case Container
  5. Only specify the EClasses of the nodes that will exist. In this case Element and Relation
Generate Simple Tooling Definition Model (.gmftool)
  1. Select the metamodel. In this case model.ecore
  2. Right click > New > Other > Graphical Modeling Framework > Simple Tooling Definition Model
  3. Give a different name (e.g. container.gmftool)
  4. Select the root EClass. In this case Container
  5. Only specify the EClasses of the nodes that will exist. In this case Element and Relation
Generate Guide Mapping Model Creation (.gmfmap)
  1. Select the metamodel. In this case model.ecore
  2. Right click > New > Other > Graphical Modeling Framework > Guide Mapping Model Creation
  3. Give a different name (e.g. container.gmfmap)
  4. Select Diagram Palette
  5. Select Diagram Canvas
  6. Select the nodes. In this case Element. Select the links. In this case Relation. Delete other nodes and links
Verify Guide Mapping Model
  1. Open the mapping model. In this case container.gmfmap
  2. Select Mapping > Top Node Reference > Node Mapping. Check the correct information for Element, Diagram Node, and Tool
  3. Select Mapping > Top Node Reference > Link Mapping. Check the correct information for Containment Feature, Element, Source Feature, Target Feature, Diagram Node, and Tool
Create Generator Model (.gmfgen)
  1. Select Mapping Model. In this case container.gmfmap
  2. Right click > Create generator model
Linking Diagrams
Configure container.gmfgen
  1. Open the generator model. In this case container.gmfgen
  2. Select Gen Editor Generator
    • Change Domain File Extension (e.g. partitioningcontainer)
    • Change ModelID (e.g. PartitioningContainer)
    • Change Package Name Prefix (e.g. partitioning.diagram.container)
  3. Select Gen Editor Generator > Gen Plugin
    • Change ID (e.g. emf.examples.partitioning.diagram.container)
    • Change Name (e.g. Partitioning Container Plugin)
  4. Select Gen Editor Generator > Gen Editor View
    • Get the Editor View ID (It will be used in the next configuration). In this case
      partitioning.diagram.container.part.PartitioningDiagramEditorID
Configure model.gmfgen
  1. Open the generator model. In this case model.gmfgen
  2. Select Gen Editor Generator > Gen Diagram > Gen Top Level
  3. Right click > New Child > Open Diagram Behaviour
  4. Select Gen Editor Generator > Gen Diagram > Gen Top Level > Open Diagram Behaviour
    • Set Diagram Kind with the Gen Editor Generator ModelID value of the container.gmfgen. In this case
      PartitioningContainer
    • Set Editor ID with the Gen Editor View ID value of the container.gmfgen. In this case
      partitioning.diagram.container.part.PartitioningDiagramEditorID
    • Change Edit Policy Class Name Editor. It has a default value. (e.g. OpenDiagramContainerEditPolicy)
      • NOTE 1: This step is optional.
      • NOTE 2: This step is necessary if the main editor (in this case, the one generated by partitioning.gmfgen) has concepts that contain other concepts.
      • NOTE 3: If the main editor has concepts that contain other concepts, the other containing elements have by default the instance "Open Diagram Behaviour". I suggest to remove those instances; otherwise, the next exception can be presented when double clicking:
org.eclipse.core.commands.ExecutionException: Can't open diagram
  at iArchimate.diagram.edit.policies.OpenDiagramEditPolicy$OpenDiagramCommand. doExecuteWithResult(OpenDiagramEditPolicy.java:106)
  at org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand. doExecute(AbstractTransactionalCommand.java:247)
  at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
  at org.eclipse.core.commands.operations.DefaultOperationHistory.execute (DefaultOperationHistory.java:513)
Create Diagram Projects

Create both diagram projects

  1. Select Generator Model of the main diagram. In this case model.gmfgen
  2. Right click > Create diagram code
  3. Select Generator Model of the sub diagram. In this case container.gmfgen
  4. Right click > Create diagram code
Test
  1. Launch an eclipse application
  2. Create a Project
  3. Create a Diagram. In this case Partitioning Diagram
  4. Open the diagram
  5. Draw containers
  6. Select one created container and double click. The container editor will be opened.
  7. Draw elements and relations.
  8. Select other created container and double click. The container editor will be opened.
  9. Draw elements and relations.
  10. Open the model.

5 comments: