Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF Diff/Merge » Override the default behavior of a merge action
Override the default behavior of a merge action [message #1412229] Mon, 25 August 2014 16:00 Go to next message
Stephane Bouchet is currently offline Stephane BouchetFriend
Messages: 280
Registered: July 2009
Senior Member
Hi,

i would like to customize the merge action on a specific diff.

An Eobject on my metamodel has an attribute 0..*.

Actually, if i select the feature content diff and do a merge, the merge result on an addition of the content and eventually a remove on the other side. (expected by design)

But i would like to merge the whole EObject content and not only the selected feature content on my case.

Is it possible to do such a thing ?


Regards,
Re: Override the default behavior of a merge action [message #1412574 is a reply to message #1412229] Tue, 26 August 2014 13:45 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 106
Registered: January 2012
Senior Member
Yes, it is possible. This kind of customization is normally handled by the merge policy, but this request goes a bit beyond the current capabilities of merge policies. So you are going to have to dig a bit more.

You have to subclass DiffOperation. The DiffOperation is in charge of computing differences according to the diff policy, and setting merge dependencies between them according to the merge policy.

A merge dependency from a difference A to a difference B for a given direction (left or right, to simplify) can be of two kinds:
- "implies": the merging of A automatically implies the merging of B without doing anything specific - for example, corresponding values on opposite references;
- "requires": the proper merging of A requires that B be merged first - for example, a reference from element E1 to element E2 requires that E2 be present.

In your case, you want to specify that the merge of a value presence on your specific attribute requires the merge of all other value presence differences on that attribute on the same element.

Have a look at DiffOperation::createAttributeValueDifference(...). At the beginning of the method body, you can see how "symmetrical value differences" - different values on the same attribute of multiplicity [1] - are handled. A call is made to method setSymmetricalValuePresenceDependencies(...) which sets up interdependencies between the two "symmetrical" differences.

You would need to do something similar for your differences on attribute values. You can call getAttributeDifferences(EAttribute) on your IMatch to get the other differences on the same matching elements for the same attribute, then use method markRequires(...) to specify the interdependencies.

Once you have defined your specialization of DiffOperation, you can use it by subclassing EComparisonImpl and redefining method getDiffOperation(...). Then if you are using the standard editor initialization mechanism, you can use your subclass of EComparisonImpl in method EMFDiffMergeEditorInput::prepareInput(...).

Hope that helps.

Olivier
Re: Override the default behavior of a merge action [message #1412851 is a reply to message #1412574] Wed, 27 August 2014 08:22 Go to previous messageGo to next message
Stephane Bouchet is currently offline Stephane BouchetFriend
Messages: 280
Registered: July 2009
Senior Member
Hi olivier,

Thanks, your solution is exactly what i was looking for ! you saved me some days Smile

Just a remark, i filled an enhancement for the subclass of EcomparisonImpl, because the instanciation in EMFDiffMergeEditorInput needs a lot of copy/paste.
see https://bugs.eclipse.org/bugs/show_bug.cgi?id=442664

Regards,
Re: Override the default behavior of a merge action [message #1412860 is a reply to message #1412851] Wed, 27 August 2014 08:43 Go to previous message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 106
Registered: January 2012
Senior Member
Thanks for the suggestion. And... done. Smile
Previous Topic:Compare with previous revision
Next Topic:Merge at a specific index
Goto Forum:
  


Current Time: Thu Apr 25 22:45:42 GMT 2024

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

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

Back to the top