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/GMF_Tutorial_Part_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](/wiki/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.