Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-04-30 09:05:17 +0000
committervlorenzo2012-04-30 09:05:17 +0000
commit9e9f96c3ded021a4a89d683dcc67c4de5bb6bb1e (patch)
tree41ad6be8faffa887af82adb331ac65d9118c42d7 /sandbox/UMLCompareMergerExample
parentd8526d072f0a90bbfa548f411d5569e52c27566e (diff)
downloadorg.eclipse.papyrus-9e9f96c3ded021a4a89d683dcc67c4de5bb6bb1e.tar.gz
org.eclipse.papyrus-9e9f96c3ded021a4a89d683dcc67c4de5bb6bb1e.tar.xz
org.eclipse.papyrus-9e9f96c3ded021a4a89d683dcc67c4de5bb6bb1e.zip
342163: [Usability] Papyrus merge should use the service edit of Papyrus
https://bugs.eclipse.org/bugs/show_bug.cgi?id=342163 A save of my work
Diffstat (limited to 'sandbox/UMLCompareMergerExample')
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeLeftTargetMerger.java172
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeRightTargetMerger.java180
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeOrderChangeMerger.java302
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDefaultExtensionMerger.java21
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffExtensionMerger.java21
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffGroupMerger.java124
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java236
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java237
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java234
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/ICommandMerger.java41
10 files changed, 1121 insertions, 447 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 56b936745d4..75d095aa8e1 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,96 +1,156 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
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.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
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.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.compare.merger.Activator;
import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils;
+import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusEFactory;
-public class CAttributeChangeLeftTargetMerger extends AttributeChangeLeftTargetMerger {
-
+public class CAttributeChangeLeftTargetMerger extends AttributeChangeLeftTargetMerger implements ICommandMerger {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.diff.merge.IMerger#applyInOrigin()
+ */
@Override
- public void doApplyInOrigin() {
+ public void applyInOrigin() {
if(MergerUtils.usePapyrusMerger()) {
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) {
+ final Command cmd = getApplyInOriginCommand(domain);
+ if(cmd.canExecute()) {
domain.getCommandStack().execute(cmd);
}
} else {
- super.doApplyInOrigin();
+ super.applyInOrigin();
}
}
@Override
- public void doUndoInTarget() {
+ public void undoInTarget() {
if(MergerUtils.usePapyrusMerger()) {
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();
+ final Command cmd = getUndoInTargetCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.undoInTarget();
+ }
+ }
+
+
+ public Command getApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(true);
+ // doApplyInOrigin();
+ // postProcess();
+ CompoundCommand cmd = new CompoundCommand("Apply in Origin Command for AttributeChangeLeftTargetMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, true));
+ cmd.append(getDoApplyInOriginCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(false);
+ // doUndoInTarget();
+ // postProcess();
+
+ CompoundCommand cmd = new CompoundCommand("Undo In Target Command for AttributeChangeLeftTargetMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, false));
+ cmd.append(getDoUndoInTargetCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ Command cmd = null;
+ final AttributeChangeLeftTarget theDiff = (AttributeChangeLeftTarget)this.diff;
+ final EObject origin = theDiff.getLeftElement();
+ final Object value = theDiff.getLeftTarget();
+ final EAttribute attr = theDiff.getAttribute();
+ try {
+ cmd = PapyrusEFactory.getERemoveCommand(domain, origin, attr.getName(), value);
+ } catch (FactoryException e) {
+ EMFComparePlugin.log(e, true);
+ }
+ return cmd;
+ }
+
+ public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ Command cmd = null;
+ final AttributeChangeLeftTarget theDiff = (AttributeChangeLeftTarget)this.diff;
+ final EObject target = theDiff.getRightElement();
+ final Object value = theDiff.getLeftTarget();
+ final EAttribute attr = theDiff.getAttribute();
+ try {
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;
+ 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.doUndoInTarget();
+ }
+ cmd = PapyrusEFactory.getEAddCommand(domain, target, attr.getName(), value, valueIndex);
+ } catch (FactoryException e) {
+ Activator.log.error(e);
}
+ return cmd;
+
}
+ public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin) {
+ // TODO the super method mergeRequiredDifferences should be rewritten to use cmd too
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CAttributeChangeLeftTargetMerger.this.mergeRequiredDifferences(applyInOrigin);
+ return null;
+ }
+ });
+ }
+
+ public Command getPostProcessCommand(final TransactionalEditingDomain domain) {
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CAttributeChangeLeftTargetMerger.this.postProcess();
+ return null;
+ }
+ });
+ }
}
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 5f86988b543..7760518dbd1 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,95 +1,157 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
package org.eclipse.papyrus.uml.merger.provider;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.compare.EMFComparePlugin;
+import org.eclipse.emf.common.command.CompoundCommand;
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.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.compare.merger.Activator;
import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils;
+import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusEFactory;
-public class CAttributeChangeRightTargetMerger extends AttributeChangeRightTargetMerger {
-
+public class CAttributeChangeRightTargetMerger extends AttributeChangeRightTargetMerger implements ICommandMerger {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.diff.merge.IMerger#applyInOrigin()
+ */
+ @Override
+ public void applyInOrigin() {
+ if(MergerUtils.usePapyrusMerger()) {
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getApplyInOriginCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.applyInOrigin();
+ }
+ }
+ /**
+ *
+ * @see org.eclipse.emf.compare.diff.merge.DefaultMerger#undoInTarget()
+ *
+ */
@Override
- public void doApplyInOrigin() {
+ public void undoInTarget() {
if(MergerUtils.usePapyrusMerger()) {
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();
+ final Command cmd = getUndoInTargetCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.undoInTarget();
+ }
+ }
+
+ public Command getApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(true);
+ // doApplyInOrigin();
+ // postProcess();
+ CompoundCommand cmd = new CompoundCommand("Apply in Origin Command for AttributeChangeRightTargetMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, true));
+ cmd.append(getDoApplyInOriginCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+ public Command getUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(false);
+ // doUndoInTarget();
+ // postProcess();
- // try {
+ CompoundCommand cmd = new CompoundCommand("Undo In Target Command for AttributeChangeRightTargetMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, false));
+ cmd.append(getDoUndoInTargetCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ Command cmd = null;
+ 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()) {
+ if (attr.isMany()) {
final EObject rightElement = theDiff.getRightElement();
final Object rightValues = rightElement.eGet(attr);
- if(rightValues instanceof List) {
- final List rightValuesList = (List)rightValues;
+ 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.doApplyInOrigin();
+ cmd = PapyrusEFactory.getEAddCommand(domain, origin, attr.getName(), value, valueIndex);
+ } catch (FactoryException e) {
+ Activator.log.error(e);
}
+ return cmd;
}
- @Override
- public void doUndoInTarget() {
- if(MergerUtils.usePapyrusMerger()) {
- 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();
+ public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ Command cmd = null;
+ final AttributeChangeRightTarget theDiff = (AttributeChangeRightTarget)this.diff;
+ final EObject target = theDiff.getRightElement();
+ final Object value = theDiff.getRightTarget();
+ final EAttribute attr = theDiff.getAttribute();
+ try {
+ cmd = PapyrusEFactory.getERemoveCommand(domain, target, attr.getName(), value);
+ } catch (FactoryException e) {
+ Activator.log.error(e);
+ }
+ return cmd;
+ }
- final Object list = target.eGet(attr);
+ public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin) {
+ // TODO the super method mergeRequiredDifferences should be rewritten to use cmd too
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
- 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);
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CAttributeChangeRightTargetMerger.this.mergeRequiredDifferences(applyInOrigin);
+ return null;
}
+ });
+ }
- } else {
- super.doUndoInTarget();
- }
+ public Command getPostProcessCommand(final TransactionalEditingDomain domain) {
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CAttributeChangeRightTargetMerger.this.postProcess();
+ return null;
+ }
+ });
}
}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeOrderChangeMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeOrderChangeMerger.java
index 13bc32f196c..1519e1f4435 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeOrderChangeMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeOrderChangeMerger.java
@@ -1,3 +1,16 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
package org.eclipse.papyrus.uml.merger.provider;
import java.lang.reflect.InvocationTargetException;
@@ -5,135 +18,210 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.compare.diff.internal.merge.impl.AttributeOrderChangeMerger;
import org.eclipse.emf.compare.diff.metamodel.AttributeOrderChange;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.tools.util.ReflectHelper;
import org.eclipse.papyrus.uml.compare.merger.Activator;
import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils;
-public class CAttributeOrderChangeMerger extends AttributeOrderChangeMerger {
+public class CAttributeOrderChangeMerger extends AttributeOrderChangeMerger implements ICommandMerger {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.diff.merge.IMerger#applyInOrigin()
+ */
+ @Override
+ public void applyInOrigin() {
+ if(MergerUtils.usePapyrusMerger()) {
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getApplyInOriginCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.applyInOrigin();
+ }
+ }
+ /**
+ *
+ * @see org.eclipse.emf.compare.diff.merge.DefaultMerger#undoInTarget()
+ *
+ */
@Override
- public void doApplyInOrigin() {
+ public void undoInTarget() {
if(MergerUtils.usePapyrusMerger()) {
- TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
- final AttributeOrderChange theDiff = (AttributeOrderChange)this.diff;
- final EAttribute attribute = theDiff.getAttribute();
- final EObject leftElement = theDiff.getLeftElement();
- final EObject rightElement = theDiff.getRightElement();
-
- final List<Object> leftList = (List<Object>)leftElement.eGet(attribute);
- final List<Object> rightList = (List<Object>)rightElement.eGet(attribute);
-
- /*
- * We need to transform the "left" list into the "right" list, modulo missing values. In practical
- * terms, this means that we'll simply leave untouched any element that has no match in the "right"
- * list (elements that were deleted) while reordering the others in the order they have in the "right"
- * list.
- */
- final List<Object> leftCopy = new ArrayList<Object>(leftList);
- final List<Object> result = new ArrayList<Object>(leftList.size());
- // Add all unmatched values in the result list
- for(int i = 0; i < leftList.size(); i++) {
- final Object left = leftList.get(i);
-
- boolean hasMatch = false;
- for(int j = 0; !hasMatch && j < rightList.size(); j++) {
- hasMatch = !areDistinctValues(left, rightList.get(j));
- }
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getUndoInTargetCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.undoInTarget();
+ }
+ }
- if(!hasMatch) {
- leftCopy.remove(left);
- result.add(left);
- }
+ public Command getApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(true);
+ // doApplyInOrigin();
+ // postProcess();
+ CompoundCommand cmd = new CompoundCommand("Apply in Origin Command for AttributeOrderChangeMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, true));
+ cmd.append(getDoApplyInOriginCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(false);
+ // doUndoInTarget();
+ // postProcess();
+
+ CompoundCommand cmd = new CompoundCommand("Undo In Target Command for AttributeOrderChangeMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, false));
+ cmd.append(getDoUndoInTargetCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ final AttributeOrderChange theDiff = (AttributeOrderChange)this.diff;
+ final EAttribute attribute = theDiff.getAttribute();
+ final EObject leftElement = theDiff.getLeftElement();
+ final EObject rightElement = theDiff.getRightElement();
+
+ final List<Object> leftList = (List<Object>)leftElement.eGet(attribute);
+ final List<Object> rightList = (List<Object>)rightElement.eGet(attribute);
+
+ /*
+ * We need to transform the "left" list into the "right" list, modulo missing values. In practical
+ * terms, this means that we'll simply leave untouched any element that has no match in the "right"
+ * list (elements that were deleted) while reordering the others in the order they have in the "right"
+ * list.
+ */
+ final List<Object> leftCopy = new ArrayList<Object>(leftList);
+ final List<Object> result = new ArrayList<Object>(leftList.size());
+ // Add all unmatched values in the result list
+ for(int i = 0; i < leftList.size(); i++) {
+ final Object left = leftList.get(i);
+
+ boolean hasMatch = false;
+ for(int j = 0; !hasMatch && j < rightList.size(); j++) {
+ hasMatch = !areDistinctValues(left, rightList.get(j));
}
- // Then reorder according to the right list's order
- for(int i = 0; i < rightList.size(); i++) {
- final Object right = rightList.get(i);
-
- Object leftMatch = null;
- for(int j = 0; leftMatch == null && j < leftCopy.size(); j++) {
- if(!areDistinctValues(right, leftCopy.get(j))) {
- leftMatch = leftCopy.get(j);
- }
- }
- if(leftMatch != null) {
- leftCopy.remove(leftMatch);
- result.add(leftMatch);
+ if(!hasMatch) {
+ leftCopy.remove(left);
+ result.add(left);
+ }
+ }
+ // Then reorder according to the right list's order
+ for(int i = 0; i < rightList.size(); i++) {
+ final Object right = rightList.get(i);
+
+ Object leftMatch = null;
+ for(int j = 0; leftMatch == null && j < leftCopy.size(); j++) {
+ if(!areDistinctValues(right, leftCopy.get(j))) {
+ leftMatch = leftCopy.get(j);
}
}
- // Finally, set the value of our attribute to this new list
- // leftElement.eSet(attribute, result);
- Command command = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, leftElement, attribute, result);
- domain.getCommandStack().execute(command);
- } else {
- super.doApplyInOrigin();
+
+ if(leftMatch != null) {
+ leftCopy.remove(leftMatch);
+ result.add(leftMatch);
+ }
}
+ // Finally, set the value of our attribute to this new list
+ // leftElement.eSet(attribute, result);
+ return PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, leftElement, attribute, result);
}
- @Override
- public void doUndoInTarget() {
- if(MergerUtils.usePapyrusMerger()) {
- TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
- final AttributeOrderChange theDiff = (AttributeOrderChange)this.diff;
- final EAttribute attribute = theDiff.getAttribute();
- final EObject leftElement = theDiff.getLeftElement();
- final EObject rightElement = theDiff.getRightElement();
-
- final List<Object> leftList = (List<Object>)leftElement.eGet(attribute);
- final List<Object> rightList = (List<Object>)rightElement.eGet(attribute);
-
- /*
- * We need to transform the "right" list into the "left" list, modulo missing values. In practical
- * terms, this means that we'll simply leave untouched any element that has no match in the "left"
- * list (elements that were added) while reordering the others in the order they have in the "left"
- * list.
- */
- final List<Object> rightCopy = new ArrayList<Object>(rightList);
- final List<Object> result = new ArrayList<Object>(rightList.size());
- // Add all unmatched values in the result list
- for(int i = 0; i < rightList.size(); i++) {
- final Object right = rightList.get(i);
-
- boolean hasMatch = false;
- for(int j = 0; !hasMatch && j < leftList.size(); j++) {
- hasMatch = !areDistinctValues(right, leftList.get(j));
- }
+ public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ final AttributeOrderChange theDiff = (AttributeOrderChange)this.diff;
+ final EAttribute attribute = theDiff.getAttribute();
+ final EObject leftElement = theDiff.getLeftElement();
+ final EObject rightElement = theDiff.getRightElement();
- if(!hasMatch) {
- rightCopy.remove(right);
- result.add(right);
- }
+ final List<Object> leftList = (List<Object>)leftElement.eGet(attribute);
+ final List<Object> rightList = (List<Object>)rightElement.eGet(attribute);
+
+ /*
+ * We need to transform the "right" list into the "left" list, modulo missing values. In practical
+ * terms, this means that we'll simply leave untouched any element that has no match in the "left"
+ * list (elements that were added) while reordering the others in the order they have in the "left"
+ * list.
+ */
+ final List<Object> rightCopy = new ArrayList<Object>(rightList);
+ final List<Object> result = new ArrayList<Object>(rightList.size());
+ // Add all unmatched values in the result list
+ for(int i = 0; i < rightList.size(); i++) {
+ final Object right = rightList.get(i);
+
+ boolean hasMatch = false;
+ for(int j = 0; !hasMatch && j < leftList.size(); j++) {
+ hasMatch = !areDistinctValues(right, leftList.get(j));
}
- // Then reorder according to the left list's order
- for(int i = 0; i < leftList.size(); i++) {
- final Object left = leftList.get(i);
-
- Object rightMatch = null;
- for(int j = 0; rightMatch == null && j < rightCopy.size(); j++) {
- if(!areDistinctValues(left, rightCopy.get(j))) {
- rightMatch = rightCopy.get(j);
- }
- }
- if(rightMatch != null) {
- rightCopy.remove(rightMatch);
- result.add(rightMatch);
+ if(!hasMatch) {
+ rightCopy.remove(right);
+ result.add(right);
+ }
+ }
+ // Then reorder according to the left list's order
+ for(int i = 0; i < leftList.size(); i++) {
+ final Object left = leftList.get(i);
+
+ Object rightMatch = null;
+ for(int j = 0; rightMatch == null && j < rightCopy.size(); j++) {
+ if(!areDistinctValues(left, rightCopy.get(j))) {
+ rightMatch = rightCopy.get(j);
}
}
- // Finally, set the value of our attribute to this new list
- // rightElement.eSet(attribute, result);
- Command command = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, rightElement, attribute, result);
- domain.getCommandStack().execute(command);
- } else {
- super.doUndoInTarget();
+
+ if(rightMatch != null) {
+ rightCopy.remove(rightMatch);
+ result.add(rightMatch);
+ }
}
+ // Finally, set the value of our attribute to this new list
+ // rightElement.eSet(attribute, result);
+ return PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, rightElement, attribute, result);
+ }
+
+ public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin) {
+ // TODO the super method mergeRequiredDifferences should be rewritten to use cmd too
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CAttributeOrderChangeMerger.this.mergeRequiredDifferences(applyInOrigin);
+ return null;
+ }
+ });
+ }
+
+ public Command getPostProcessCommand(final TransactionalEditingDomain domain) {
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CAttributeOrderChangeMerger.this.postProcess();
+ return null;
+ }
+ });
}
/**
@@ -146,20 +234,20 @@ public class CAttributeOrderChangeMerger extends AttributeOrderChangeMerger {
* @return
* <code>true</code> if the 2 objects are dictinct.
*/
+ //TODO write a JUnit test to be sure that this methods is always accessible
protected boolean areDistinctValues(final Object left, final Object right) {
- AttributeOrderChangeMerger myClass = new AttributeOrderChangeMerger();
- Class[] parameterTypes = new Class[2];
+
+ final Class<?>[] parameterTypes = new Class[2];
parameterTypes[0] = java.lang.Object.class;
parameterTypes[1] = java.lang.Object.class;
Method m = null;
try {
- m = myClass.getClass().getDeclaredMethod("areDistinctValues", parameterTypes);
+ m = ReflectHelper.getMethod(AttributeOrderChangeMerger.class, "areDistinctValues", parameterTypes);
} catch (SecurityException e) {
Activator.log.error(e);
} catch (NoSuchMethodException e) {
Activator.log.error(e);
}
- m.setAccessible(true);
Object[] parameters = new Object[2];
parameters[0] = left;
@@ -167,7 +255,7 @@ public class CAttributeOrderChangeMerger extends AttributeOrderChangeMerger {
Object result = null;
try {
- result = (Object)m.invoke(myClass, parameters);
+ result = m.invoke(AttributeOrderChangeMerger.class, parameters);
} catch (IllegalArgumentException e) {
Activator.log.error(e);
} catch (IllegalAccessException e) {
@@ -178,6 +266,4 @@ public class CAttributeOrderChangeMerger extends AttributeOrderChangeMerger {
assert (result instanceof Boolean);
return ((Boolean)result).booleanValue();
}
-
-
}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDefaultExtensionMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDefaultExtensionMerger.java
new file mode 100644
index 00000000000..da5e03eda80
--- /dev/null
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDefaultExtensionMerger.java
@@ -0,0 +1,21 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.merger.provider;
+
+import org.eclipse.emf.compare.diff.merge.DefaultExtensionMerger;
+
+
+public class CDefaultExtensionMerger extends DefaultExtensionMerger {
+ //TODO
+}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffExtensionMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffExtensionMerger.java
new file mode 100644
index 00000000000..8906d858844
--- /dev/null
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffExtensionMerger.java
@@ -0,0 +1,21 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.merger.provider;
+
+import org.eclipse.emf.compare.diff.internal.merge.impl.DiffExtensionMerger;
+
+
+public class CDiffExtensionMerger extends DiffExtensionMerger {
+ //TODO ?
+}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffGroupMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffGroupMerger.java
new file mode 100644
index 00000000000..614da73ce31
--- /dev/null
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffGroupMerger.java
@@ -0,0 +1,124 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.merger.provider;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.compare.diff.internal.merge.impl.DiffGroupMerger;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils;
+
+
+public class CDiffGroupMerger extends DiffGroupMerger implements ICommandMerger {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.diff.merge.IMerger#applyInOrigin()
+ */
+ @Override
+ public void applyInOrigin() {
+ if(MergerUtils.usePapyrusMerger()) {
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getApplyInOriginCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.applyInOrigin();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.diff.merge.DefaultMerger#undoInTarget()
+ *
+ */
+ @Override
+ public void undoInTarget() {
+ if(MergerUtils.usePapyrusMerger()) {
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getUndoInTargetCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.undoInTarget();
+ }
+ }
+
+ public Command getApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(true);
+ // doApplyInOrigin();
+ // postProcess();
+ CompoundCommand cmd = new CompoundCommand("Apply in Origin Command for CDiffGroupMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, true));
+ cmd.append(getDoApplyInOriginCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(false);
+ // doUndoInTarget();
+ // postProcess();
+
+ CompoundCommand cmd = new CompoundCommand("Undo In Target Command for CDiffGroupMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, false));
+ cmd.append(getDoUndoInTargetCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+
+ public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ //TODO
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ //TODO
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin) {
+ // TODO the super method mergeRequiredDifferences should be rewritten to use cmd too
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CDiffGroupMerger.this.mergeRequiredDifferences(applyInOrigin);
+ return null;
+ }
+ });
+ }
+
+ public Command getPostProcessCommand(final TransactionalEditingDomain domain) {
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CDiffGroupMerger.this.postProcess();
+ return null;
+ }
+ });
+ }
+}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java
index 54163a98ae8..6f659c3a222 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java
@@ -1,120 +1,204 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
package org.eclipse.papyrus.uml.merger.provider;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.compare.EMFComparePlugin;
import org.eclipse.emf.compare.FactoryException;
import org.eclipse.emf.compare.diff.internal.merge.impl.ModelElementChangeLeftTargetMerger;
import org.eclipse.emf.compare.diff.metamodel.ModelElementChangeLeftTarget;
import org.eclipse.emf.compare.diff.metamodel.ReferenceChangeLeftTarget;
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.EReference;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.osgi.util.NLS;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.compare.merger.Activator;
import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils;
import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusEFactory;
-//TODO : should be redone, to re-implements Efactory.eAdd, ...aso
-public class CModelElementChangeLeftTargetMerger extends ModelElementChangeLeftTargetMerger {
+public class CModelElementChangeLeftTargetMerger extends ModelElementChangeLeftTargetMerger implements ICommandMerger {
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.diff.merge.api.AbstractMerger#doApplyInOrigin()
+ * @see org.eclipse.emf.compare.diff.merge.IMerger#applyInOrigin()
*/
@Override
- protected void doApplyInOrigin() {
-
+ public void applyInOrigin() {
if(MergerUtils.usePapyrusMerger()) {
- final ModelElementChangeLeftTarget theDiff = (ModelElementChangeLeftTarget)this.diff;
- final EObject element = theDiff.getLeftElement();
- TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
- Command cmd = PapyrusMergeCommandProvider.INSTANCE.getDestroyCommand(domain, element);
- domain.getCommandStack().execute(cmd);
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getApplyInOriginCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
} else {
- super.doApplyInOrigin();
+ super.applyInOrigin();
}
}
+ /**
+ *
+ * @see org.eclipse.emf.compare.diff.merge.DefaultMerger#undoInTarget()
+ *
+ */
@Override
- protected void doUndoInTarget() {
+ public void undoInTarget() {
if(MergerUtils.usePapyrusMerger()) {
- TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
- CompoundCommand cmd = new CompoundCommand("ModelElementChangeLeftTargetCommand#doUndoInTarget");
- final ModelElementChangeLeftTarget theDiff = (ModelElementChangeLeftTarget)this.diff;
- // we should copy the element to the Origin one.
- final EObject origin = theDiff.getRightParent();
- final EObject element = theDiff.getLeftElement();
- final EObject newOne = copy(element);
- final EReference ref = element.eContainmentFeature();
- if (ref != null) {
- try {
- int elementIndex = -1;
- if (ref.isMany()) {
- final Object containmentRefVal = element.eContainer().eGet(ref);
- if (containmentRefVal instanceof List<?>) {
- @SuppressWarnings("unchecked")
- final List<EObject> listVal = (List<EObject>)containmentRefVal;
- elementIndex = listVal.indexOf(element);
- }
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getUndoInTargetCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.undoInTarget();
+ }
+ }
+
+ public Command getApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(true);
+ // doApplyInOrigin();
+ // postProcess();
+ CompoundCommand cmd = new CompoundCommand("Apply in Origin Command for CModelElementChangeLeftTargetMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, true));
+ cmd.append(getDoApplyInOriginCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(false);
+ // doUndoInTarget();
+ // postProcess();
+
+ CompoundCommand cmd = new CompoundCommand("Undo In Target Command for CModelElementChangeLeftTargetMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, false));
+ cmd.append(getDoUndoInTargetCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ final ModelElementChangeLeftTarget theDiff = (ModelElementChangeLeftTarget)this.diff;
+ final EObject element = theDiff.getLeftElement();
+ return PapyrusMergeCommandProvider.INSTANCE.getDestroyCommand(domain, element);
+ //removeDanglingReferences(parent); not used
+ }
+
+ public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ CompoundCommand cmd = new CompoundCommand("Command CModelElementChangeLeftTargetMerger#getDoUndoInTargetCommand");
+ final ModelElementChangeLeftTarget theDiff = (ModelElementChangeLeftTarget)this.diff;
+ // we should copy the element to the Origin one.
+ final EObject origin = theDiff.getRightParent();
+ final EObject element = theDiff.getLeftElement();
+ final EObject newOne = copy(element);
+ final EReference ref = element.eContainmentFeature();
+ if(ref != null) {
+ try {
+ int elementIndex = -1;
+ if(ref.isMany()) {
+ final Object containmentRefVal = element.eContainer().eGet(ref);
+ if(containmentRefVal instanceof List<?>) {
+ @SuppressWarnings("unchecked")
+ final List<EObject> listVal = (List<EObject>)containmentRefVal;
+ elementIndex = listVal.indexOf(element);
}
-// EFactory.eAdd(origin, ref.getName(), newOne, elementIndex, true);
-// setXMIID(newOne, getXMIID(element));
- cmd.append(PapyrusEFactory.getEAddCommand(origin, ref.getName(),newOne,elementIndex,true));
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, newOne, getXMIID(element)));
- } catch (final FactoryException e) {
- EMFComparePlugin.log(e, true);
}
- } else if (origin == null && getDiffModel().getRightRoots().size() > 0) {
-// getDiffModel().getRightRoots().get(0).eResource().getContents().add(newOne);
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getAddToResourceCommand(domain, getDiffModel().getRightRoots().get(0).eResource(), newOne));
- } else if (origin != null) {
-// origin.eResource().getContents().add(newOne);
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getAddToResourceCommand(domain, origin.eResource(), newOne));
- } else {
- throw new UnsupportedOperationException(NLS.bind("We can't merge this diff : {0}", theDiff));
+ // EFactory.eAdd(origin, ref.getName(), newOne, elementIndex, true);
+ // setXMIID(newOne, getXMIID(element));
+ cmd.append(PapyrusEFactory.getEAddCommand(domain, origin, ref.getName(), newOne, elementIndex, true));
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, newOne, getXMIID(element)));
+ } catch (final FactoryException e) {
+ Activator.log.error(e);
}
- // we should now have a look for RemovedReferencesLinks needing elements to apply
- final Iterator<EObject> siblings = getDiffModel().eAllContents();
- while (siblings.hasNext()) {
- final Object op = siblings.next();
- if (op instanceof ReferenceChangeLeftTarget) {
- final ReferenceChangeLeftTarget link = (ReferenceChangeLeftTarget)op;
- // now if I'm in the target References I should put my copy in the origin
- if (link.getRightTarget() != null && link.getRightTarget() == element) {
- link.setLeftTarget(newOne);
- }
- } else if (op instanceof ReferenceOrderChange) {
- final ReferenceOrderChange link = (ReferenceOrderChange)op;
- if (link.getRightElement() == origin && link.getReference() == ref) {
- final ListIterator<EObject> targetIterator = link.getRightTarget().listIterator();
- boolean replaced = false;
- while (!replaced && targetIterator.hasNext()) {
- final EObject target = targetIterator.next();
- if (target.eIsProxy()
- && equalProxyURIs(((InternalEObject)target).eProxyURI(),
- EcoreUtil.getURI(element))) {
- targetIterator.set(newOne);
- replaced = true;
+ } else if(origin == null && getDiffModel().getRightRoots().size() > 0) {
+ // getDiffModel().getRightRoots().get(0).eResource().getContents().add(newOne);
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getAddToResourceCommand(domain, getDiffModel().getRightRoots().get(0).eResource(), newOne));
+ } else if(origin != null) {
+ // origin.eResource().getContents().add(newOne);
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getAddToResourceCommand(domain, origin.eResource(), newOne));
+ } else {
+ // FIXME throw exception : couldn't merge this
+ }
+ cmd.append(new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ // we should now have a look for RemovedReferencesLinks needing elements to apply
+ final Iterator<EObject> siblings = getDiffModel().eAllContents();
+ while(siblings.hasNext()) {
+ final Object op = siblings.next();
+ if(op instanceof ReferenceChangeLeftTarget) {
+ final ReferenceChangeLeftTarget link = (ReferenceChangeLeftTarget)op;
+ // now if I'm in the target References I should put my copy in the origin
+ if(link.getRightTarget() != null && link.getRightTarget() == element) {
+ link.setLeftTarget(newOne);
+ }
+ } else if(op instanceof ReferenceOrderChange) {
+ final ReferenceOrderChange link = (ReferenceOrderChange)op;
+ if(link.getRightElement() == origin && link.getReference() == ref) {
+ final ListIterator<EObject> targetIterator = link.getRightTarget().listIterator();
+ boolean replaced = false;
+ while(!replaced && targetIterator.hasNext()) {
+ final EObject target = targetIterator.next();
+ if(target.eIsProxy() && equalProxyURIs(((InternalEObject)target).eProxyURI(), EcoreUtil.getURI(element))) {
+ targetIterator.set(newOne);
+ replaced = true;
+ }
}
}
}
}
+ return CommandResult.newOKCommandResult();
}
- domain.getCommandStack().execute(cmd);
- } else {
- super.doUndoInTarget();
- }
+ }));
+
+ return cmd;
+ }
+
+
+ public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin) {
+ // TODO the super method mergeRequiredDifferences should be rewritten to use cmd too
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CModelElementChangeLeftTargetMerger.this.mergeRequiredDifferences(applyInOrigin);
+ return null;
+ }
+ });
+ }
+
+ public Command getPostProcessCommand(final TransactionalEditingDomain domain) {
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CModelElementChangeLeftTargetMerger.this.postProcess();
+ return null;
+ }
+ });
}
}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java
index 661f4d5fd7f..df75b31945c 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java
@@ -1,116 +1,201 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
package org.eclipse.papyrus.uml.merger.provider;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.compare.EMFComparePlugin;
import org.eclipse.emf.compare.FactoryException;
import org.eclipse.emf.compare.diff.internal.merge.impl.ModelElementChangeRightTargetMerger;
import org.eclipse.emf.compare.diff.metamodel.DiffElement;
import org.eclipse.emf.compare.diff.metamodel.ModelElementChangeRightTarget;
import org.eclipse.emf.compare.diff.metamodel.ReferenceChangeRightTarget;
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.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.osgi.util.NLS;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.compare.merger.Activator;
import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils;
import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusEFactory;
-public class CModelElementChangeRightTargetMerger extends ModelElementChangeRightTargetMerger {
+public class CModelElementChangeRightTargetMerger extends ModelElementChangeRightTargetMerger implements ICommandMerger {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.diff.merge.IMerger#applyInOrigin()
+ */
@Override
- public void doApplyInOrigin() {
+ public void applyInOrigin() {
if(MergerUtils.usePapyrusMerger()) {
- TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
- CompoundCommand cmd = new CompoundCommand("ModelElementChangeRightTargetCommand#doApplyInOrigin");
- final ModelElementChangeRightTarget theDiff = (ModelElementChangeRightTarget)this.diff;
- final EObject origin = theDiff.getLeftParent();
- final EObject element = theDiff.getRightElement();
- final EObject newOne = copy(element);
- final EReference ref = element.eContainmentFeature();
- if(ref != null) {
- try {
- int expectedIndex = -1;
- if(ref.isMany()) {
- final Object containmentRefVal = element.eContainer().eGet(ref);
- if(containmentRefVal instanceof List<?>) {
- @SuppressWarnings("unchecked")
- final List<EObject> listVal = (List<EObject>)containmentRefVal;
- expectedIndex = listVal.indexOf(element);
- }
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getApplyInOriginCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.applyInOrigin();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.diff.merge.DefaultMerger#undoInTarget()
+ *
+ */
+ @Override
+ public void undoInTarget() {
+ if(MergerUtils.usePapyrusMerger()) {
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getUndoInTargetCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.undoInTarget();
+ }
+ }
+
+ public Command getApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(true);
+ // doApplyInOrigin();
+ // postProcess();
+ CompoundCommand cmd = new CompoundCommand("Apply in Origin Command for CModelElementChangeRightTargetMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, true));
+ cmd.append(getDoApplyInOriginCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(false);
+ // doUndoInTarget();
+ // postProcess();
+
+ CompoundCommand cmd = new CompoundCommand("Undo In Target Command for CModelElementChangeRightTargetMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, false));
+ cmd.append(getDoUndoInTargetCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ final CompoundCommand cmd = new CompoundCommand("Command CModelElementChangeRightTargetMerger#getDoApplyInOriginCommand");
+ final ModelElementChangeRightTarget theDiff = (ModelElementChangeRightTarget)this.diff;
+ final EObject origin = theDiff.getLeftParent();
+ final EObject element = theDiff.getRightElement();
+ final EObject newOne = copy(element);
+ final EReference ref = element.eContainmentFeature();
+ if(ref != null) {
+ try {
+ int expectedIndex = -1;
+ if(ref.isMany()) {
+ final Object containmentRefVal = element.eContainer().eGet(ref);
+ if(containmentRefVal instanceof List<?>) {
+ @SuppressWarnings("unchecked")
+ final List<EObject> listVal = (List<EObject>)containmentRefVal;
+ expectedIndex = listVal.indexOf(element);
}
- // EFactory.eAdd(origin, ref.getName(), newOne, expectedIndex, true);
- // setXMIID(newOne, getXMIID(element));
- cmd.append(PapyrusEFactory.getEAddCommand(origin, ref.getName(), newOne, expectedIndex, true));
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, newOne, getXMIID(element)));
- } catch (final FactoryException e) {
- EMFComparePlugin.log(e, true);
}
- } else if(origin == null && getDiffModel().getLeftRoots().size() > 0) {
- // getDiffModel().getLeftRoots().get(0).eResource().getContents().add(newOne);
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getAddToResourceCommand(domain, getDiffModel().getLeftRoots().get(0).eResource(), newOne));
- } else if(origin != null) {
- // origin.eResource().getContents().add(newOne);
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getAddToResourceCommand(domain, origin.eResource(), newOne));
- } else {
- throw new UnsupportedOperationException(NLS.bind("We can't merge this diff : {0}", theDiff));
+ // EFactory.eAdd(origin, ref.getName(), newOne, expectedIndex, true);
+ // setXMIID(newOne, getXMIID(element));
+ cmd.append(PapyrusEFactory.getEAddCommand(domain, origin, ref.getName(), newOne, expectedIndex, true));
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, newOne, getXMIID(element)));
+ } catch (final FactoryException e) {
+ Activator.log.error(e);
}
- // we should now have a look for AddReferencesLinks needing this object
- final Iterator<EObject> siblings = getDiffModel().eAllContents();
- while(siblings.hasNext()) {
- final DiffElement op = (DiffElement)siblings.next();
- if(op instanceof ReferenceChangeRightTarget) {
- final ReferenceChangeRightTarget link = (ReferenceChangeRightTarget)op;
- // now if I'm in the target References I should put my copy in the origin
- if(link.getLeftTarget() != null && link.getLeftTarget() == element) {
- link.setRightTarget(newOne);
- }
- } else if(op instanceof ReferenceOrderChange) {
- final ReferenceOrderChange link = (ReferenceOrderChange)op;
- if(link.getLeftElement() == origin && link.getReference() == ref) {
- final ListIterator<EObject> targetIterator = link.getLeftTarget().listIterator();
- boolean replaced = false;
- while(!replaced && targetIterator.hasNext()) {
- final EObject target = targetIterator.next();
- if(target.eIsProxy() && equalProxyURIs(((InternalEObject)target).eProxyURI(), EcoreUtil.getURI(element))) {
- targetIterator.set(newOne);
- replaced = true;
+ } else if(origin == null && getDiffModel().getLeftRoots().size() > 0) {
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getAddToResourceCommand(domain, getDiffModel().getLeftRoots().get(0).eResource(), newOne));
+ } else if(origin != null) {
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getAddToResourceCommand(domain, origin.eResource(), newOne));
+ } else {
+ // FIXME Throw exception : couldn't merge this
+ }
+ cmd.append(new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, null, null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ // we should now have a look for AddReferencesLinks needing this object
+ final Iterator<EObject> siblings = getDiffModel().eAllContents();
+ while(siblings.hasNext()) {
+ final DiffElement op = (DiffElement)siblings.next();
+ if(op instanceof ReferenceChangeRightTarget) {
+ final ReferenceChangeRightTarget link = (ReferenceChangeRightTarget)op;
+ // now if I'm in the target References I should put my copy in the origin
+ if(link.getLeftTarget() != null && link.getLeftTarget() == element) {
+ link.setRightTarget(newOne);
+ }
+ } else if(op instanceof ReferenceOrderChange) {
+ final ReferenceOrderChange link = (ReferenceOrderChange)op;
+ if(link.getLeftElement() == origin && link.getReference() == ref) {
+ final ListIterator<EObject> targetIterator = link.getLeftTarget().listIterator();
+ boolean replaced = false;
+ while(!replaced && targetIterator.hasNext()) {
+ final EObject target = targetIterator.next();
+ if(target.eIsProxy() && equalProxyURIs(((InternalEObject)target).eProxyURI(), EcoreUtil.getURI(element))) {
+ targetIterator.set(newOne);
+ replaced = true;
+ }
}
}
}
}
+ return CommandResult.newOKCommandResult();
}
- domain.getCommandStack().execute(cmd);
- } else {
- super.doApplyInOrigin();
- }
+ }));
+ return cmd;
+ }
+ public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ final ModelElementChangeRightTarget theDiff = (ModelElementChangeRightTarget)this.diff;
+ final EObject element = theDiff.getRightElement();
+ return PapyrusMergeCommandProvider.INSTANCE.getDestroyCommand(domain, element);
}
- @Override
- public void doUndoInTarget() {
- if(MergerUtils.usePapyrusMerger()) {
- final ModelElementChangeRightTarget theDiff = (ModelElementChangeRightTarget)this.diff;
- final EObject element = theDiff.getRightElement();
- // final EObject parent = theDiff.getRightElement().eContainer();
- // EcoreUtil.remove(element);
- final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
- final Command cmd = PapyrusMergeCommandProvider.INSTANCE.getDestroyCommand(domain, element);
- domain.getCommandStack().execute(cmd);
- } else {
- super.doUndoInTarget();
- }
+ public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin) {
+ // TODO the super method mergeRequiredDifferences should be rewritten to use cmd too
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CModelElementChangeRightTargetMerger.this.mergeRequiredDifferences(applyInOrigin);
+ return null;
+ }
+ });
+ }
+
+ public Command getPostProcessCommand(final TransactionalEditingDomain domain) {
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CModelElementChangeRightTargetMerger.this.postProcess();
+ return null;
+ }
+ });
}
}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java
index 10d6fe6c078..a3454ca68b4 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java
@@ -1,106 +1,196 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
package org.eclipse.papyrus.uml.merger.provider;
import java.util.List;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.compare.diff.internal.merge.impl.MoveModelElementMerger;
import org.eclipse.emf.compare.diff.metamodel.MoveModelElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils;
/**
*
* Created for EMF-Compare, for MoveModelElementMerger
- *
+ *
*/
-public class CMoveModelElementMerger extends MoveModelElementMerger {
+public class CMoveModelElementMerger extends MoveModelElementMerger implements ICommandMerger {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.diff.merge.IMerger#applyInOrigin()
+ */
@Override
- public void doUndoInTarget() {
+ public void applyInOrigin() {
if(MergerUtils.usePapyrusMerger()) {
- final MoveModelElement theDiff = (MoveModelElement)this.diff;
- final EObject rightTarget = theDiff.getRightTarget();
- final EObject rightElement = theDiff.getRightElement();
- final EReference ref = theDiff.getLeftElement().eContainmentFeature();
- CompoundCommand cmd = new CompoundCommand("doUndoInTarget for MoveModelElementCommand");
- TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
- if(ref != null) {
- // ordering handling:
- int index = -1;
- final EObject leftElementParent = theDiff.getLeftElement().eContainer();
- final Object leftRefValue = leftElementParent.eGet(ref);
- if(leftRefValue instanceof List) {
- final List<Object> refLeftValueList = (List<Object>)leftRefValue;
- index = refLeftValueList.indexOf(theDiff.getLeftElement());
- //testable with MoveModelElementExample1
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveWithIndexCommand(domain, rightTarget, rightTarget, ref, rightElement, index));
- }else{
- // EcoreUtil.remove(rightElement);
- // EFactory.eAdd(rightTarget, ref.getName(), rightElement, index, true);
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveCommand(domain, rightTarget, rightTarget, ref, rightElement));
- }
- // try {
- final String elementID = getXMIID(rightElement);
-
- // setXMIID(rightElement, elementID);
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, rightElement, elementID));
- // } catch (FactoryException e) {
- // EMFComparePlugin.log(e, true);
- // }
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getApplyInOriginCommand(domain);
+ if(cmd.canExecute()) {
domain.getCommandStack().execute(cmd);
- } else {
- // shouldn't be here
- assert false;
}
} else {
- super.doUndoInTarget();
+ super.applyInOrigin();
}
}
+ /**
+ *
+ * @see org.eclipse.emf.compare.diff.merge.DefaultMerger#undoInTarget()
+ *
+ */
@Override
- public void doApplyInOrigin() {
+ public void undoInTarget() {
if(MergerUtils.usePapyrusMerger()) {
- final MoveModelElement theDiff = (MoveModelElement)this.diff;
- final EObject leftTarget = theDiff.getLeftTarget();
- final EObject leftElement = theDiff.getLeftElement();
- final EReference ref = theDiff.getRightElement().eContainmentFeature();
- CompoundCommand cmd = new CompoundCommand("doApplyInOrigin for MoveModelElementCommand");
- TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
- if(ref != null) {
- // ordering handling:
- int index = -1;
- final EObject rightElementParent = theDiff.getRightElement().eContainer();
- final Object rightRefValue = rightElementParent.eGet(ref);
- if(rightRefValue instanceof List) {
- final List<Object> refRightValueList = (List<Object>)rightRefValue;
- index = refRightValueList.indexOf(theDiff.getRightElement());
- //testable with MoveModelElementExample1
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveWithIndexCommand(domain, leftTarget, leftTarget, ref, leftElement, index));
- }else{
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveCommand(domain, leftTarget, leftTarget, ref, leftElement));
- }
-
- // try {
- // We'll store the element's ID because moving an element deletes its XMI ID
- final String elementID = getXMIID(leftElement);
- // EcoreUtil.remove(leftElement);
- // EFactory.eAdd(leftTarget, ref.getName(), leftElement, index, true);
-
- // Sets anew the element's ID
- // setXMIID(leftElement, elementID);
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, leftElement, elementID));
- // } catch (FactoryException e) {
- // EMFComparePlugin.log(e, true);
- // }
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getUndoInTargetCommand(domain);
+ if(cmd.canExecute()) {
domain.getCommandStack().execute(cmd);
+ }
+ } else {
+ super.undoInTarget();
+ }
+ }
+
+ public Command getApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(true);
+ // doApplyInOrigin();
+ // postProcess();
+ CompoundCommand cmd = new CompoundCommand("Apply in Origin Command for CMoveModelElementMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, true));
+ cmd.append(getDoApplyInOriginCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ // mergeRequiredDifferences(false);
+ // doUndoInTarget();
+ // postProcess();
+
+ CompoundCommand cmd = new CompoundCommand("Undo In Target Command for CMoveModelElementMerger");
+ cmd.append(getMergeRequiredDifferencesCommand(domain, false));
+ cmd.append(getDoUndoInTargetCommand(domain));
+ cmd.append(getPostProcessCommand(domain));
+ return cmd;
+ }
+
+ public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain) {
+ final CompoundCommand cmd = new CompoundCommand("CMoveModelElementMerger#getDoApplyInOriginCommand");
+ final MoveModelElement theDiff = (MoveModelElement)this.diff;
+ final EObject leftTarget = theDiff.getLeftTarget();
+ final EObject leftElement = theDiff.getLeftElement();
+ final EReference ref = theDiff.getRightElement().eContainmentFeature();
+ if(ref != null) {
+ // ordering handling:
+ int index = -1;
+ final EObject rightElementParent = theDiff.getRightElement().eContainer();
+ final Object rightRefValue = rightElementParent.eGet(ref);
+ if(rightRefValue instanceof List) {
+ final List<Object> refRightValueList = (List<Object>)rightRefValue;
+ index = refRightValueList.indexOf(theDiff.getRightElement());
+ }
+
+
+ // We'll store the element's ID because moving an element deletes its XMI ID
+ final String elementID = getXMIID(leftElement);
+
+ if(rightRefValue instanceof List<?>) {
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveWithIndexCommand(domain, leftTarget, leftTarget, ref, leftElement, index));
+ } else {
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveCommand(domain, leftTarget, leftTarget, ref, leftElement));
+ }
+ //TODO : verify this merge action : I replace remove and eAdd by a move : it seems coorect, but it should be more tested
+ // EcoreUtil.remove(leftElement);
+ // EFactory.eAdd(leftTarget, ref.getName(), leftElement, index, true);
+ // // Sets anew the element's ID
+ // setXMIID(leftElement, elementID);
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, leftElement, elementID));
+
+ } else {
+ // shouldn't be here
+ cmd.append(UnexecutableCommand.INSTANCE);
+ }
+ return cmd;
+ }
+
+ public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
+ final CompoundCommand cmd = new CompoundCommand("CMoveModelElementMerger#getDoUndoInTargetCommand");
+ final MoveModelElement theDiff = (MoveModelElement)this.diff;
+ final EObject rightTarget = theDiff.getRightTarget();
+ final EObject rightElement = theDiff.getRightElement();
+ final EReference ref = theDiff.getLeftElement().eContainmentFeature();
+ if(ref != null) {
+ // ordering handling:
+ int index = -1;
+ final EObject leftElementParent = theDiff.getLeftElement().eContainer();
+ final Object leftRefValue = leftElementParent.eGet(ref);
+ if(leftRefValue instanceof List) {
+ final List<Object> refLeftValueList = (List<Object>)leftRefValue;
+ index = refLeftValueList.indexOf(theDiff.getLeftElement());
+ }
+ if(leftRefValue instanceof List<?>) {
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveWithIndexCommand(domain, rightTarget, rightTarget, ref, rightElement, index));
} else {
- // shouldn't be here
- assert false;
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveCommand(domain, rightTarget, rightTarget, ref, rightElement));
}
+ final String elementID = getXMIID(rightElement);
+ //TODO : verify this merge action : I replace remove and eAdd by a move : it seems coorect, but it should be more tested
+ // EcoreUtil.remove(rightElement);
+ // EFactory.eAdd(rightTarget, ref.getName(), rightElement, index, true);
+ // setXMIID(rightElement, elementID);
+
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, rightElement, elementID));
} else {
- super.doApplyInOrigin();
+ // shouldn't be here
+ cmd.append(UnexecutableCommand.INSTANCE);
}
+ return cmd;
+ }
+
+
+ public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin) {
+ // TODO the super method mergeRequiredDifferences should be rewritten to use cmd too
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CMoveModelElementMerger.this.mergeRequiredDifferences(applyInOrigin);
+ return null;
+ }
+ });
+ }
+
+ public Command getPostProcessCommand(final TransactionalEditingDomain domain) {
+ return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ CMoveModelElementMerger.this.postProcess();
+ return null;
+ }
+ });
}
}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/ICommandMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/ICommandMerger.java
new file mode 100644
index 00000000000..2b83a4ebf1b
--- /dev/null
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/ICommandMerger.java
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.merger.provider;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.compare.diff.merge.IMerger;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+
+
+public interface ICommandMerger extends IMerger {
+
+ /**
+ *
+ * @return
+ * the command to do the action ApplyInOrigin
+ */
+ public Command getApplyInOriginCommand(final TransactionalEditingDomain domain);
+
+
+ public Command getUndoInTargetCommand(final TransactionalEditingDomain domain);
+
+ public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain);
+
+ public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain);
+
+ public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin);
+
+ public Command getPostProcessCommand(final TransactionalEditingDomain domain);
+
+}

Back to the top