Cédric Brun bio photo

Cédric Brun

Building kick-ass products in Eclipse and on Eclipse.

Email Twitter
If you've used EMF editors you probably already have seen this kind of dialog :

This happens when you did change your model and some external changes (aka somebody else changed your file) happened before you pressed "save".  This is not only an EMF problem, any editor has kind of problematic. Either way the end user have a very hard time undestanding why he has to pick one or the other version as most of the time these changes are not conflicting !

Is that the best we can do ?  Another option is to compare both versions, detect conflicts, and if there is no conflicts, just merge the changes.

Here I changed the number of pages in the EMF Book from the model, and changed the title through the textual editor. When going back on my editor, the comparison, conflict detection and then merge process happens and I get this :

And when I have conflicts?  Then the editor can't do much, right, at least it can helps you and show you the conflict :

How is it implemented ? That's fairly easy using emf and it's diff/merge support :

The general process is : the editor tells the WorkspaceSync class when it got saved (or freshly loaded) . This WorkspaceSync keep a copy of the state of the editor as "ancestor". When an event comes from the workspace, the editor version and the workspace versions are compared using the original copy as a common ancestor to detect conflicts. If there is no conflict, it merges, if there is at least one conflict it asks user.

  The drawback is clear with this implementation : you're keeping around - in memory - a copy of your model to be able to detect conflicts later on.  As such that solution is not for every case.

Other options are possible and might be great ways to exercise your EMF skills, if you try something, tell me !