Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-04-12 13:49:51 +0000
committervlorenzo2012-04-12 13:49:51 +0000
commit17a816d5649ea533dc57233450eb97f2f66bcb51 (patch)
tree9ba474dcd2d8f01626a423c414911d99400b9378 /sandbox/UMLCompareMergerExample
parent7a9044cf8492817494515197e2aebcafb3332059 (diff)
downloadorg.eclipse.papyrus-17a816d5649ea533dc57233450eb97f2f66bcb51.tar.gz
org.eclipse.papyrus-17a816d5649ea533dc57233450eb97f2f66bcb51.tar.xz
org.eclipse.papyrus-17a816d5649ea533dc57233450eb97f2f66bcb51.zip
342163: [Usability] Papyrus merge should use the service edit of Papyrus
https://bugs.eclipse.org/bugs/show_bug.cgi?id=342163
Diffstat (limited to 'sandbox/UMLCompareMergerExample')
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeRightTargetMerger.java81
1 files changed, 75 insertions, 6 deletions
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeRightTargetMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeRightTargetMerger.java
index bb039574c37..5f86988b543 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeRightTargetMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeRightTargetMerger.java
@@ -1,26 +1,95 @@
package org.eclipse.papyrus.uml.merger.provider;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+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.AttributeChangeRightTargetMerger;
+import org.eclipse.emf.compare.diff.metamodel.AttributeChangeRightTarget;
+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.uml.compare.merger.utils.MergerUtils;
public class CAttributeChangeRightTargetMerger extends AttributeChangeRightTargetMerger {
+
+
@Override
- public void doUndoInTarget() {
+ public void doApplyInOrigin() {
if(MergerUtils.usePapyrusMerger()) {
- throw new UnsupportedOperationException();
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ Command cmd;
+ final AttributeChangeRightTarget theDiff = (AttributeChangeRightTarget)this.diff;
+ final EObject origin = theDiff.getLeftElement();
+ final Object value = theDiff.getRightTarget();
+ final EAttribute attr = theDiff.getAttribute();
+
+
+ // try {
+ int valueIndex = -1;
+ if(attr.isMany()) {
+ final EObject rightElement = theDiff.getRightElement();
+ final Object rightValues = rightElement.eGet(attr);
+ if(rightValues instanceof List) {
+ final List rightValuesList = (List)rightValues;
+ valueIndex = rightValuesList.indexOf(value);
+ }
+ final Object manyValue = origin.eGet(attr);
+ final List<Object> newValue = new ArrayList<Object>((Collection<?>)manyValue);
+ if(manyValue instanceof List<?>) {//code adapted from EFactory.eAdd
+ final List<Object> list = (List<Object>)manyValue;
+ final int listSize = list.size();
+ if(valueIndex > -1 && valueIndex < listSize) {
+ newValue.add(valueIndex, value);
+ } else {
+ newValue.add(value);
+ }
+ } else if(manyValue instanceof Collection<?>) {
+ newValue.add(value);
+ }
+ cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, origin, attr, newValue);
+ } else {
+ cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, origin, attr, value);
+ }
+ domain.getCommandStack().execute(cmd);
} else {
- super.doUndoInTarget();
+ super.doApplyInOrigin();
}
}
@Override
- public void doApplyInOrigin() {
+ public void doUndoInTarget() {
if(MergerUtils.usePapyrusMerger()) {
- throw new UnsupportedOperationException();
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ Command cmd = null;
+ final AttributeChangeRightTarget theDiff = (AttributeChangeRightTarget)this.diff;
+ final EObject target = theDiff.getRightElement();
+ final Object value = theDiff.getRightTarget();
+ final EAttribute attr = theDiff.getAttribute();
+
+ final Object list = target.eGet(attr);
+
+ if(list instanceof List) {
+ if(value != null) {
+ final List<Object> newValue = new ArrayList<Object>((List<?>)list);
+ newValue.remove(value);
+ cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, target, attr, newValue);
+ }
+ } else {
+ cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, target, attr, null);
+ }
+ if(cmd != null) {
+ domain.getCommandStack().execute(cmd);
+ }
+
} else {
- super.doApplyInOrigin();
+ super.doUndoInTarget();
}
}
}

Back to the top