blob: ad7cfed18a83edf0579b0eb502733a96a5c63bb4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*******************************************************************************
* Copyright (c) 2009, 2012 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.compare.diff.internal.merge.impl;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import java.util.Collection;
import org.eclipse.emf.compare.EMFComparePlugin;
import org.eclipse.emf.compare.FactoryException;
import org.eclipse.emf.compare.diff.merge.DefaultMerger;
import org.eclipse.emf.compare.diff.metamodel.ReferenceOrderChange;
import org.eclipse.emf.compare.util.EFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
/**
* Merger for a {@link ReferenceOrderChange} operation.
*
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
*/
public class ReferenceOrderChangeMerger extends DefaultMerger {
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.diff.merge.DefaultMerger#doApplyInOrigin()
*/
@Override
public void doApplyInOrigin() {
final ReferenceOrderChange theDiff = (ReferenceOrderChange)this.diff;
final EObject leftElement = theDiff.getLeftElement();
final Collection<EObject> target = Lists.newArrayList(Collections2.filter(theDiff.getLeftTarget(),
new Predicate<EObject>() {
public boolean apply(EObject input) {
return !input.eIsProxy()
|| !DefaultMerger.isEMFCompareProxy(((InternalEObject)input).eProxyURI());
}
}));
try {
EFactory.eSet(leftElement, theDiff.getReference().getName(), target);
} catch (final FactoryException e) {
EMFComparePlugin.log(e, true);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.diff.merge.DefaultMerger#doUndoInTarget()
*/
@Override
public void doUndoInTarget() {
final ReferenceOrderChange theDiff = (ReferenceOrderChange)this.diff;
final EObject rightElement = theDiff.getRightElement();
final Collection<EObject> target = Lists.newArrayList(Collections2.filter(theDiff.getRightTarget(),
new Predicate<EObject>() {
public boolean apply(EObject input) {
return !input.eIsProxy()
|| !DefaultMerger.isEMFCompareProxy(((InternalEObject)input).eProxyURI());
}
}));
try {
EFactory.eSet(rightElement, theDiff.getReference().getName(), target);
} catch (final FactoryException e) {
EMFComparePlugin.log(e, true);
}
}
}
|