Versions Compared

Key

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

...

Eclipse usually uses 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)

...