Showing posts with label GMFTools. Show all posts
Showing posts with label GMFTools. Show all posts

Sunday, October 25, 2009

GMFTools Part 2: Sharing an EditingDomain

In this blog, I will elaborate on how GMFTools facilitates to share the same instance of an EditingDomain across multiple diagram editors.

What is an EditingDomain?

In GMF, each diagram editor works on its own instance of a so called TransactionalEditingDomain. TransactionalEditingDomain is a concept from EMF Transaction. In GMF, it contains an EMF ResourceSet holding the diagram model, its semantic model and all referenced models as well as a command stack for undo/redo support. In addition, each editor registers a WorkspaceSynchronizer to its resource files, making sure external changes are synchronized with the editor's content.

Why share the EditingDomain?

In the default setup, problems occur if two editors operate on the same resources: If both editors change the same resource, saving one will overwrite the changes of the other. This situation already happens when you're using the Related Diagrams feature in the gmfmap model: On double click, it will open a new diagram that is saved in the same resource but in a different editing domain. As the original editor is still open, conflicts can arise quickly.

Another reason for sharing the editing domain is to save memory and performance, especially if you're working on big models with a couple of editors.

In many cases you might want to see changes immediately in all editors without having to save first, e.g. when your editors show different parts or aspects of the same model. GMF has already built-in support for that as it uses EMF's notification mechanism to synchronize the notation (diagram) model with the semantic model.

Consequences of sharing an EditingDomain

Sharing the editing domain across several editors has a number of consequences
  • The editors will also share the same command stack. Undo/redo becomes a global operation and can therefore affect other editors than the currently active one.
  • For reasons of simplicity, all editors should be saved synchronously, and they will all be either dirty or clean at the same time.
  • You should no longer dispose the editing domain when closing an editor. That means, to avoid memory leaks you need strategy for unloading unneeded resources.
  • The command stack will keep references to unloaded model elements, too, so you might want to have an garbage collecting strategy here as well or at least keep the command history short.
Solution in GMFTools

The solution in GMFTools is based on a WiKi page of GMF and a couple of newsgroup entries combined with our own experiences. It has been recently refactored to reenable the WorkspaceSynchronizer.

It comes in a number of aspectual template changes for the GMF code generator, an additional runtime plug-in and tool support for fixing the type registry, such that it is rather easy to consume even if you're not too familiar with the GMF runtime. Note that so far we have only been using it to generate plain diagram plug-ins, i.e. not for GMF's RCP generator.

The major changes are
  • Redirect all creation statements of an editing domain to a new utility class and the dispose statements to an unloading tool.
  • Make sure to use consistent element types.
  • The common behavior of all XXDocumentProvider.ResourceSetInfo has been extracted to avoid synchronization feedback loops.
If you're interested in the details have a look at the WiKi-page.

Friday, October 9, 2009

GMFTools Part 1: UI Extensions

This is the first of a short series of posts on GMFTools.

The Graphical Modeling Framework is a powerful framework for the development of graphical editors for EMF-based models. It's based on EMF and GEF and uses a model-driven approach for designing the editors.

Building graphical editors is a complex task. While GMF tries to facilitate that procedure, its abstractions are sometimes still a little hard to grasp, and the generated results often need manual fine-tunig to meet end-user expectations. I am a user, not a developer of GMF. Mymain concern is getting things done in the projects I am working on. That's why I sometimes bend GMF to do what I want it do, rather than use it the way it is meant to be used. That fact makes it somehow hard to contribute back to the GMF project. Still, me and my colleagues take a lot of benefit from using GMF.

GMFTools

As a long term user of GMF, I started to collect code, tools, samples and several tipps and tricks in the GMFTools project about a year ago. In the meantime, the project has attracted additional committers and it has become quite a useful collection of real-world solutions around GMF.

GMFTools roughly consists of three components
  • UI-Extensions making GMF easier to use.
  • Runtime extensions that add new functionality by means of additional classes and generator template changes.
  • Examples demonstrating the use of the runtime extensions.
The GMFTools Button

The first thing that may catch your attention after having installed GMFTools is a new GMF button in your button bar. It is meant to make GMF development easier and performs a bunch of actions on your GMF projects, including running the GMF code generator. To see what kind of actions, open the preference page for GMFTools. Each action can be enabled and disabled separately.

Most of the actions are self-explanatory. You may wonder why I want to delete the gmfgen model and the diagram code before re-generating. The reason is that by deleting the generated artifacts before re-generation, I circumvent all reconciliation steps (including JMerge). I have very bad experiences with reconcilers in general and so I prefer not to mix manually written and generated code. Some people have called me a "purist" for this attitude, but from my experience a clean separation will pay in the long run of a model-driven project.

As a consequence gmfgen model becomes a temporary artifact in the whole code generation procedure. To be able to modify the gmfgen model nevertheless, I have introduced a model-to-model transformation that is performed before generating the actual diagram code from the gmfgen model. This transformation is performed using an Xtend file (both oAW and M2T work) which is persisted next to your GMF design models.

The fix of the type registration will be covered in a post on shared editing domains.

In the middle of the preferences, you can manipulate your current set of GMF models (might not be the best name), i.e. the combinations of ecore, genmodel, gmfgraph, gmftool and gmfmap models you need to generate a GMF editor, as well as the Xtend transformation. These sets can also be provided by means of *.def files that can be stored in your workspace next to the design models.

By a single click on the GMF button, all enabled actions are executed on the currently / last selected models. In its drop-down menu you can access all your editor model individually. That really speeds up GMF development significantly, as you no longer have to find your way through the popup menus of different files. Nevertheless, individual actions can still be executed from the popup menus of the respective files.

That's all for today. Stay tuned for more.

Sunday, June 21, 2009

Synchronized editors with TMF/Xtext and GMF

Well, here it is, the screencast showing a textual TMF/Xtext and a graphical GMF editor synchronized on the same model.


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

Monday, October 20, 2008

Started GMFTools project

I've worked with GMF for several years now, and I've built quite a bunch of graphical editors using it.

On my way, I've come along several issues, problems and annoyances of the GMF framework. Some of these may be a matter of personal taste, others are just reoccurring topics and tasks, which unfortunately have never been really focused within the GMF project. As these are sometimes hard to separate, I've decided to collect my ideas, extract reusable solutions and share them by making them open-source. This way, I hope to share knowledge with other GMF users, get feedback (maybe even by the committers), provide examples for beginners, and of course make my own life easier.

Have a look at it at http://code.google.com/p/gmftools/, and, if you like it, feel free to use it. But please don't expect me to provide extensive support. Main topics covered are
  • Sharing an editing domain among several editors
  • Make GMF's development process easier, e.g. by bypassing unreliable reconcilers and provide a very simple UI to the code generator.
  • Additional layouts, e.g. make labels fit into ellipses.
  • How to implement non- or semi-canonical diagrams.
Of course your comments are very welcome.

Maybe there are even more people around willing to share GMF solutions...