Versions Compared

Key

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

One of the great advantages of modeling data with a language like Ecore, is that the model facilitates making generic tools for manipulating data, including editing it in a user interface. E.g. the type of attributes allows you to automatically select appropriate editing widget in a property sheet and the containment references allows you to add child creation menus containing only the relevant types and support drag & drop which the proper checks for validity.

Creating the

...

instance

In Eclipse, you usually uses use wizards to create files, and after creation an appropriate editor is opened. However, while modelling there is no wizard or installed editor, so to create model instances we must use a different mechanism. Both the Sample Ecore Model Editor (default editor for Ecore files) and the Ecore Editor allows you to right-click on an EClass and select Create Dynamic Instance... This will prompt you for the file name, and then it create will create a file with an instance of that EClass in the XMI serialisation format. Finally, the default editor is opened, and you can start building a model instance, i.e. an EObject graph.

The term dynamic instance relates to the fact that the mechanism doesn't rely on generated Java classes, but instead uses a special EObject subclass that supports all aspects of Ecore including EAttributes and EReferences. Hence, they have the same behaviour as instances of generated Java classes.

Note that to be able to open the file without having the model installed into Eclipse, the file includes a reference to the Ecore model location. This allows the loading mechanism to also load the model and be able to make sense of the contents. Note that if the (newly create) file is re-opened with the model installed, it will use the Java classes and can support validation that uses Java code.

The generic Ecore instance editor (Sample Ecore Model Editor)

...