Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Compare] How to perform one-way-merge
[Compare] How to perform one-way-merge [message #783222] Wed, 25 January 2012 10:04 Go to next message
Holger S is currently offline Holger SFriend
Messages: 4
Registered: January 2012
Junior Member
Hi,

I have a small question about a problem I initially thought to be trivial....

I modeled a metamodel mainly consisting of a root having several child classes where each of the child class has some properties or containments.

This metamodel is instantiated from two different places of my application where each place is responsible for a specific part of the metamodel. So, each place initiates a root object and adds its child classes to it.

Finally I would like to merge these two "submodels" together to an overall model containing all information.

Unfortunatly, using the "standard EMF compare code snippet" which can be found all over the forums doesn't lead to my expected solution as all the information from the second model is removed and the whole instances of the first model are copied to the second one. As a result, I receive two identical models.... Here is the snippet I am using:

Object model1 = ModelUtils.load(model1, resourceSet);
EObject model2 = ModelUtils.load(model2, resourceSet);
 
// Matching model elements
MatchModel match = MatchService.doMatch(model1, model2, Collections.<String, Object> emptyMap());
// Computing differences
DiffModel diff = DiffService.doDiff(match, false);
// Merges all differences from model1 to model2
List<DiffElement> differences = new ArrayList<DiffElement>(diff.getOwnedElements());
MergeService.merge(differences, true);


However, I am able to reach my goal if I use the Eclipse EMF Compare Plugin by comparing my submodels, selecting each instance of the left side and clicking on "Copy current change from left to right". In that way, I get a model on the right side with all instances included!

So, this leads to my final question: how can I reach that goal with code? Smile

Greetings and thanks in advance
Holger

Re: [Compare] How to perform one-way-merge [message #788022 is a reply to message #783222] Wed, 01 February 2012 08:54 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi Holger,

The difference between your two approaches is that from your code, you merge "all" difference (thus making the two models identical), while from the UI you select a specific set of differences to merge. You need to change this part of your code :
List<DiffElement> differences = new ArrayList<DiffElement>(diff.getOwnedElements());
MergeService.merge(differences, true);


in order to filter out of the "differences" list those diffs you do not want to merge. The semantics of "what you want to merge", however, are up to you. For example, if you wish to merge all model element that have been "added" to the left model (considering that the "right" one is the oldest), then you need to merge all differences that match

diff instanceof ModelElementChangeLeftTarget && !diff.isRemote()


Note that if you only consider two-way comparisons, you do not need to check for the "remote" boolean.

Laurent Goubet
Obeo
Re: [Compare] How to perform one-way-merge [message #788030 is a reply to message #788022] Wed, 01 February 2012 09:05 Go to previous message
Holger S is currently offline Holger SFriend
Messages: 4
Registered: January 2012
Junior Member
Hi Laurent,

thanks a lot for your answer! Actually, I discovered the same way right yesterday in the late evening, so I am glad to read a confirmation for my solution this morning Smile

I added a new LeftToRightMergeService class in which I iterate through the DiffElement tree and call the respective Merger for the DiffElement just in case of an instance of ModelElementChangeLeftTarget. Luckily, everything seems to work fine!

Greetings,
Holger
Previous Topic:How to observe the size of a EList with Databinding
Next Topic:Copy Commands from one Stack to antoher
Goto Forum:
  


Current Time: Fri Apr 19 13:17:58 GMT 2024

Powered by FUDForum. Page generated in 0.02025 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top