edit this page - page history - about editing

GMF Diagram Partitioning

The goal of this tutorial is to be able to create a GMF editor, where you can expand certain boxes to edit their contents, like so:




This tutorial was based on an excellent Eclipse news posting (reposted) and another discussion. Also see GMF, GMF Troubleshooting and Creating a new GMF Editor.

If you want to add nodes within a node itself, try the second part of the GMF tutorial: http://wiki.eclipse.org/GMFTutorialPart_2

  • Create your source.ecore
    • We are using the following example .ecore:
  • Create your source.genmodel
    • Make sure you set the package
    • Right click .genmodel and generate model code
    • Right click .genmodel and generate edit code

Now we create the super diagramming code.

  • Generate super.gmfgraph from source.genmodel
    • Right click source.genmodel and select New > GMF > Simple Graphical Definition Model
    • Select the root container object
    • Only specify the creation of nodes that will actually exist
      • In our case:
      • WebApplication as the root
      • DataTable as a node
      • DataTable.name as a label
  • Generate super.gmftool from super.gmfgraph
    • Right click super.gmfgraph and select New > GMF > Simple Tooling Definition Model
    • Select the root container object
    • Only specify the creation of nodes that will actually exist
      • In our case:
      • WebApplication as the root
      • DataTable as a node
  • Generate super.gmfmap from super.gmftool
    • Right click super.gmftool and select New > GMF > Guide Mapping Model Creation
    • Select the root container object
    • Remove invalid links and nodes
      • In our case we remove DataColumn, because WebApplication cannot contain them
  • Generate super.gmfgen from super.gmfmap
    • Right click super.gmfmap and select Create Generator
    • Generate the diagram code to test everything is working OK (see GMF Troubleshooting)

We have created the super diagramming code, now we want to generate the sub-diagramming code.

  • Generate sub.gmfgraph from source.genmodel
    • Select the sub container object
    • Only specify the creation of nodes that will actually exist
      • In our case:
      • DataTable as the root
      • DataColumn as a node
      • DataColumn.name as a label
      • DataColumn.type as a label
  • Generate sub.gmftool from sub.gmfgraph
    • Select the sub container object
    • Only specify the creation of nodes that will actually exist
      • In our case:
      • DataTable as the root
      • DataColumn as a node
  • Generate sub.gmfmap from sub.gmftool
    • Select the sub container object
    • Remove invalid links and nodes
  • Generate sub.gmfgen from sub.gmfmap
    • Right click super.gmfmap and select Create Generator

We now need to do some configuration to link the two diagram codes together.

  • First, we need to make sub.gmfgen unique:
    • Change sub.gmfgen > Gen Editor Generator > Domain File Extension
    • Change sub.gmfgen > Gen Editor Generator > ModelID [1]
    • Change sub.gmfgen > Gen Editor Generator > Package Name Prefix
    • Change sub.gmfgen > Gen Editor Generator > Plugin Diagram > ID
    • Change sub.gmfgen > Gen Editor Generator > Plugin Diagram > Name
    • Look at the value for sub.gmfgen > Gen Editor Generator > Gen Editor View > ID
  • Now, link them together:
    • Open super.gmfgen
    • Go to the corresponding super.gmfgen > Gen Editor Generator > Gen Diagram > Gen Top Level Node for the sub element
    • Right click the node and create a new Open Diagram Behaviour
    • On the new node, set the following properties:
      • Change Diagram Kind to sub.gmfgen > Gen Editor Generator > ModelID [1]
      • Change Editor ID to sub.gmfgen > Gen Editor Generator > Gen Editor View > ID
      • If you have more than one diagram editor for super.gmfgen, make sure you also make Edit Policy Class Name unique in sub.gmfgen > Gen Editor Generator > Gen Editor View > ID

Finally we can get everything working:

  • Generate the diagram code from BOTH super.gmfgen and sub.gmfgen
  • You now need to start a new Eclipse application which includes BOTH of these new packages

This setup will allow users to create the following type of ecore XML:

<?xml version="1.0" encoding="UTF-8"?>
<org.openiaml.test.two:WebApplication xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:org.openiaml.test.two="http://openiaml.org/two">
  <tables name="my table">
    <columns name="my column"/>
  </tables>
</org.openiaml.test.two:WebApplication>

If you have any issues, look into GMF Troubleshooting.
Categories: GMF | Article | Technology
edit this page - what links to here? - page history - top
Last edited by jevon jevon 106 months ago