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
|
package org.eclipse.papyrus.infra.emf.compare.merger;
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.UpdateAttributeMerger;
import org.eclipse.emf.compare.diff.metamodel.UpdateAttribute;
import org.eclipse.emf.compare.util.EFactory;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.infra.emf.compare.merger.provider.PapyrusMergeCommandProvider;
import org.eclipse.papyrus.infra.emf.compare.utils.Utils;
public class PapyrusUpdateAttributeMerger extends UpdateAttributeMerger {
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.diff.merge.api.AbstractMerger#doApplyInOrigin()
*/
@Override
public void doApplyInOrigin() {
final UpdateAttribute theDiff = (UpdateAttribute)this.diff;
final EObject element = theDiff.getRightElement();
final EObject origin = theDiff.getLeftElement();
final EAttribute attr = theDiff.getAttribute();
if(Utils.useEditService()) {
final TransactionalEditingDomain domain = Utils.getConfiguration().getEditingDomain();
Command cmd = null;
try {
cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, origin, origin.eClass().getEStructuralFeature(attr.getName()), EFactory.eGet(element, attr.getName()));
} catch (final FactoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
domain.getCommandStack().execute(cmd);
} else {
try {
EFactory.eSet(origin, attr.getName(), EFactory.eGet(element, attr.getName()));
} catch (final FactoryException e) {
EMFComparePlugin.log(e, true);
}
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.diff.merge.api.AbstractMerger#doUndoInTarget()
*/
@Override
public void doUndoInTarget() {
final UpdateAttribute theDiff = (UpdateAttribute)this.diff;
final EObject element = theDiff.getRightElement();
final EObject origin = theDiff.getLeftElement();
final EAttribute attr = theDiff.getAttribute();
if(Utils.useEditService()) {
final TransactionalEditingDomain domain = Utils.getConfiguration().getEditingDomain();
Command cmd = null;
try {
cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, element, element.eClass().getEStructuralFeature(attr.getName()), EFactory.eGet(origin, attr.getName()));
} catch (final FactoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
domain.getCommandStack().execute(cmd);
} else {
try {
EFactory.eSet(element, attr.getName(), EFactory.eGet(origin, attr.getName()));
} catch (final FactoryException e) {
EMFComparePlugin.log(e, true);
}
}
}
}
|