Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b077a0872b0ff6b2a686b2364ec376791633283c (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
package org.eclipse.papyrus.uml.merger.provider;

import java.util.Collection;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.compare.EMFComparePlugin;
import org.eclipse.emf.compare.FactoryException;
import org.eclipse.emf.compare.diff.internal.merge.impl.ReferenceOrderChangeMerger;
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;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;

public class CReferenceOrderChangeMerger extends ReferenceOrderChangeMerger {
	
	@Override
	public void doUndoInTarget() {
		if(MergerUtils.usePapyrusMerger()) {
			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());
						}
					}));

			TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
//			try {
//				EFactory.eSet(rightElement, theDiff.getReference().getName(), target);
			
			Command command = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, rightElement, theDiff.getReference(), target);
			domain.getCommandStack().execute(command );
//			} catch (final FactoryException e) {
//				EMFComparePlugin.log(e, true);
//			}
		} else {
			super.doUndoInTarget();
		}
	}

	@Override
	public void doApplyInOrigin() {
		if(MergerUtils.usePapyrusMerger()) {
			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());
						}
					}));
			TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
//			try {
//				EFactory.eSet(leftElement, theDiff.getReference().getName(), target);
			Command command = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, leftElement, theDiff.getReference(), target);
			domain.getCommandStack().execute(command );
//			} catch (final FactoryException e) {
//				EMFComparePlugin.log(e, true);
//			}
		} else {
			super.doApplyInOrigin();
		}
	}
}

Back to the top