See also GMF.

  1. EDataType Serializable
  2. Extending Ecore to define a new M3

I want to be able to go backwards through a reference

Also see Using EOpposite in GMF.

If you have a model like the right, which only has a one-directional link, it’s not possible to find out what element the connection link came from. For example, if you have an Action A with a Connection to another Action B, you cannot ask the Connection of the source (Action A).

The solution is to make the link bi-directional, by:

  1. Adding another reference attribute to each backwards reference so we can keep track of the back reference (“from” and “in” attributes)
  2. Setting the eOpposite reference to the opposite attribute, that is, the eOpposite of “from” is “connection”, and “to” is “in”.

Once you reload the .genmodel and re-create the model/edit code, you will now be able to go Connection.getFrom() and Action.getIn().

It will also change the generated model XML from:

<component name="Home Page">
  <component name="Link to About Page">
    <operation name="click">
      <connection name="onClick" to="//@component.1/@operation.0"/>
    </operation>
  </component>
</component>
<component name="About Page">
  <operation name="render"/>
</component>

To:

<component name="Home Page">
  <component name="Link to About Page">
    <operation name="click">
      <connection name="onClick" to="//@component.1/@operation.0"/>
    </operation>
  </component>
</component>
<component name="About Page">
  <operation name="render" in="//@component.0/@component.0/@operation.0/@connection.0" />
</component>

Adding comments to an EMF model

The easiest way to do this is to add an EAnnotation like so:

- EAnnotation source: http://foo.com/comment
  - DetailsEntry key: comment, details: (enter in your comment here)

EMF/GMF will ignore the EAnnotation and the comment will remain. Another option is to add it to the ecore_diagram visual editor as a note.