The example has been implemented with only a few changes to generated code: In Xtext, the following modifications were applied:
- A Formatter to define where to use what kind of whitespace, when the textual representation is derived from the semantic model.
- An IFragmentProvider that generates name-based fragments (IDs) for elements in an Xtext resource. That way, the correspondence of graphical nodes to semantic elements is preserved even if you delete a preceeding entity.
- An AbstractEntitiesJavaValidator has been implemented for Java based validation
On the GMF side:
- In the mapping model, I had to use feature initializers to make sure names are initialized properly on creation, to always have serializable models.
- In the generator model, I had to manually set the domain genmodel and the file extension.
- In the generator model, I enabled validation decorators and printing, and added the plug-in de.itemis.gmf.runtime.extensions from the GMFTools project containing a more sophisticated layout.
Additionally, I added a bit of glue code:
- An action to navigate from an EditPart to the textual representation, using Xtext's NodeAdapter.
- A listener that warns the user if (s)he's about to change a file that has already been changed in another dirty editor, and allows to abandon the changes.
The editor are synchronizing on save, to avoid GMF's canonical edit policies pruning nodes/edges belonging to temporarily lost elements.
Xtext plays well with EMF. It registers
- A resource factory for a specific XtextResource implementation that encapsulates the parser (text->model) as well as the serializer (model->text).
- An EValidator with a declarative Java implementation