Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-04-12 08:55:35 -0400
committervlorenzo2012-04-12 08:55:35 -0400
commit7a9044cf8492817494515197e2aebcafb3332059 (patch)
tree04f6626d836da0ef8efa440f5a2d564aff680662 /sandbox/UMLCompareMergerExample
parent23d6f75f7e9b6c7c1b3dbf2c3aedb9098138b73f (diff)
downloadorg.eclipse.papyrus-7a9044cf8492817494515197e2aebcafb3332059.tar.gz
org.eclipse.papyrus-7a9044cf8492817494515197e2aebcafb3332059.tar.xz
org.eclipse.papyrus-7a9044cf8492817494515197e2aebcafb3332059.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/CAttributeChangeLeftTargetMerger.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/CAttributeChangeLeftTargetMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeLeftTargetMerger.java
index 2adca83ec58..56b936745d4 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeLeftTargetMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeLeftTargetMerger.java
@@ -1,26 +1,95 @@
package org.eclipse.papyrus.uml.merger.provider;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+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.AttributeChangeLeftTargetMerger;
+import org.eclipse.emf.compare.diff.metamodel.AttributeChangeLeftTarget;
+import org.eclipse.emf.compare.util.EFactory;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.InternalEList;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils;
public class CAttributeChangeLeftTargetMerger extends AttributeChangeLeftTargetMerger {
+
@Override
- public void doUndoInTarget() {
+ public void doApplyInOrigin() {
if(MergerUtils.usePapyrusMerger()) {
- throw new UnsupportedOperationException();
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ Command cmd = null;
+ final AttributeChangeLeftTarget theDiff = (AttributeChangeLeftTarget)this.diff;
+ final EObject origin = theDiff.getLeftElement();
+ final Object value = theDiff.getLeftTarget();
+ final EAttribute attr = theDiff.getAttribute();
+
+ final Object list = origin.eGet(attr);
+ if(list instanceof List) {
+ if(value != null) {
+ final List<Object> newValue = new ArrayList<Object>((List<?>)list);
+// Collections.copy(newValue, (List<?>)list);
+ newValue.remove(value);
+ cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, origin, attr, newValue);
+ }
+ } else {
+ cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, origin, attr, null);
+ }
+ if(cmd != null) {
+ 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;
+ final AttributeChangeLeftTarget theDiff = (AttributeChangeLeftTarget)this.diff;
+ final EObject target = theDiff.getRightElement();
+ final Object value = theDiff.getLeftTarget();
+ final EAttribute attr = theDiff.getAttribute();
+
+ int valueIndex = -1;
+ if(attr.isMany()) {
+ final EObject leftElement = theDiff.getLeftElement();
+ final Object leftValues = leftElement.eGet(attr);
+ if(leftValues instanceof List) {
+ final List leftValuesList = (List)leftValues;
+ valueIndex = leftValuesList.indexOf(value);
+ }
+ final Object manyValue = target.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, target, attr, newValue);
+ } else {
+ // EFactory.eAdd(target, attr.getName(), value, valueIndex);
+ cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, target, attr, value);
+ }
+
+ domain.getCommandStack().execute(cmd);
} else {
- super.doApplyInOrigin();
+ super.doUndoInTarget();
}
}

Back to the top