Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-05-03 05:10:02 -0400
committervlorenzo2012-05-03 05:10:02 -0400
commit0f6f240f9d936741a8c641c6f86b7927f2e55305 (patch)
tree1f1763a8f729ca4398a6ac6dbc6c22f622021a44
parent204bafd806c8828a2e914c7d9c2ea67888f639e4 (diff)
downloadorg.eclipse.papyrus-0f6f240f9d936741a8c641c6f86b7927f2e55305.tar.gz
org.eclipse.papyrus-0f6f240f9d936741a8c641c6f86b7927f2e55305.tar.xz
org.eclipse.papyrus-0f6f240f9d936741a8c641c6f86b7927f2e55305.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
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.xml2
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/EObjectComparator.java68
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/ITransactionalMerger.java (renamed from sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/ITransactionalMerger.java)5
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MergerUtils.java62
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MoveWithIndexCommand.java136
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MoveWithIndexRequest.java56
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusCompareEObjectCopier.java299
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusEFactory.java301
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PositionAdapter.java48
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/internal/provider/PapyrusMergeCommandProvider.java (renamed from sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/PapyrusMergeCommandProvider.java)6
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/internal/provider/PapyrusUMLMergeProvider.java (renamed from sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/PapyrusUMLMergeProvider.java)14
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeLeftTargetMerger.java156
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeRightTargetMerger.java157
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeOrderChangeMerger.java269
-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.java121
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java204
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java201
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java212
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceChangeLeftTargetMerger.java226
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceChangeRightTargetMerger.java223
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceOrderChangeMerger.java160
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateAttributeMerger.java145
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateReferenceMerger.java176
25 files changed, 19 insertions, 3270 deletions
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.xml b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.xml
index 5ac706ab66b..ccf04180b02 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.xml
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.xml
@@ -5,7 +5,7 @@
point="org.eclipse.emf.compare.diff.mergerprovider">
<mergerprovider
fileExtension="uml"
- mergerProviderClass="org.eclipse.papyrus.uml.merger.provider.PapyrusUMLMergeProvider"
+ mergerProviderClass="org.eclipse.papyrus.uml.merger.internal.provider.PapyrusUMLMergeProvider"
priority="low">
</mergerprovider>
</extension>
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/EObjectComparator.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/EObjectComparator.java
deleted file mode 100644
index 5223fa5bb0c..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/EObjectComparator.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*****************************************************************************
- * 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.compare.merger.utils;
-
-import java.util.Comparator;
-import java.util.Iterator;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.ecore.EObject;
-
-/**
- *
- * This class allows to compare EObject using the PositionAdapter.
- *
- *
- */
-public class EObjectComparator<T> implements Comparator<T> {
-
- /**
- *
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- *
- * @param o1
- * @param o2
- * @return
- */
- public int compare(final T o1, final T o2) {
- if(o1 instanceof EObject && o2 instanceof EObject) {
- final int position1 = getWantedPosition((EObject)o1);
- final int position2 = getWantedPosition((EObject)o2);
- if(position1 != -1 && position2 != -1) {
- return position1 - position2;
- }
- }
- return 0;
- }
-
- /**
- *
- * @param obj1
- * an EObject
- * @return
- * the wanted position for this object
- */
- private int getWantedPosition(final EObject obj1) {
- final Iterator<Adapter> adapters = obj1.eAdapters().iterator();
- int expectedIndex = -1;
- while(expectedIndex == -1 && adapters.hasNext()) {
- final Adapter adapter = adapters.next();
- if(adapter instanceof PositionAdapter) {
- expectedIndex = ((PositionAdapter)adapter).getExpectedIndex();
- }
- }
- return expectedIndex;
- }
-
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/ITransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/ITransactionalMerger.java
index 588a5d8faa6..eaaf5f44ec2 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/ITransactionalMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/ITransactionalMerger.java
@@ -11,12 +11,11 @@
* 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;
+package org.eclipse.papyrus.uml.compare.merger.utils; import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.compare.diff.merge.DefaultMerger;
import org.eclipse.emf.compare.diff.merge.IMerger;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+;
/**
*
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MergerUtils.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MergerUtils.java
deleted file mode 100644
index 8d140b80802..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MergerUtils.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*****************************************************************************
- * 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.compare.merger.utils;
-
-import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.core.sasheditor.editor.IMultiPageEditorPart;
-import org.eclipse.papyrus.infra.tools.util.EditorHelper;
-import org.eclipse.ui.IEditorPart;
-
-/**
- *
- * This class provides useful method for the mergers
- *
- */
-public final class MergerUtils {
-
- /**
- *
- * Constructor.
- *
- */
- private MergerUtils() {
- //nothing to do
- }
-
- /**
- *
- * @return
- * <code>true</code> if we can use the Papyrus Mergers
- */
- public static boolean usePapyrusMerger() {
- return getEditingDomain() != null;
- }
-
- /**
- *
- * @return
- * the {@link TransactionalEditingDomain} to use for the merge action, or <code>null</code> if not found
- */
- public static TransactionalEditingDomain getEditingDomain() {
- IEditorPart editor = EditorHelper.getCurrentEditor();
- if(editor instanceof IMultiPageEditorPart) {
- editor = ((IMultiPageEditorPart)editor).getActiveEditor();
- }
- if(editor instanceof IEditingDomainProvider) {
- return (TransactionalEditingDomain)((IEditingDomainProvider)editor).getEditingDomain();
- }
- return null;
- }
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MoveWithIndexCommand.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MoveWithIndexCommand.java
deleted file mode 100644
index f76f6502703..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MoveWithIndexCommand.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*****************************************************************************
- * 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.compare.merger.utils;
-
-import java.util.Collection;
-import java.util.Iterator;
-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.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.util.FeatureMapUtil;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand;
-import org.eclipse.gmf.runtime.emf.type.core.internal.l10n.EMFTypeCoreMessages;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
-
-//TODO move this class and create it in the service edit
-//TODO : breaks this class into 2 classes : 1 for the move and another one for the reorder?
-public class MoveWithIndexCommand extends MoveElementsCommand {
-
- /**
- *
- * Constructor.
- *
- * @param request
- */
- public MoveWithIndexCommand(final MoveRequest request) {
- super(request);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- *
- * @param monitor
- * @param info
- * @return
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
- final int index = getIndex();
- if(index != -1) {
- for(Iterator<?> i = getElementsToMove().keySet().iterator(); i.hasNext();) {
- final EObject element = (EObject)i.next();
- final EReference feature = getTargetFeature(element);
- if(feature != null) {
- if(FeatureMapUtil.isMany(getTargetContainer(), feature)) {
- if(shouldReorder()) {
- //we attach the real position to the object
- PapyrusEFactory.attachRealPositionEAdapter(element, index);
- }
- final Object value = getTargetContainer().eGet(feature);
- if(value instanceof List<?>) {
- final List<?> listValue = (List<?>)value;
- final int indexMax = listValue.size() - 1;
- if(indexMax < index) {
- //we add the element at the end of the list
- final List values = ((List<?>)getTargetContainer().eGet(feature));
- values.add(element);
- if(shouldReorder()) {
- PapyrusEFactory.reorderList(values);
- }
- } else {
- ((List)value).add(index, element);
- if(shouldReorder()) {
- PapyrusEFactory.reorderList((List)value);
- }
- }
-
- } else {
- ((Collection)getTargetContainer().eGet(feature)).add(element);
- if(shouldReorder()) {
- PapyrusEFactory.reorderList((List)((Collection)getTargetContainer().eGet(feature)));
- }
- }
- } else {
- getTargetContainer().eSet(feature, element);
- }
- } else {
- return CommandResult.newErrorCommandResult(EMFTypeCoreMessages.moveElementsCommand_noTargetFeature);
- }
- }
- return CommandResult.newOKCommandResult();
- }
- return super.doExecuteWithResult(monitor, info);
- }
-
- @Override
- public boolean canExecute() {
- super.canExecute();
- return true;
- }
- /**
- *
- * @return
- * the index for the move command
- */
- protected int getIndex() {
- IEditCommandRequest req = getRequest();
- if(req instanceof MoveWithIndexRequest) {
- return ((MoveWithIndexRequest)req).getIndex();
- }
- return -1;
- }
-
- /**
- *
- * @return
- * <code>true</code> when the list should be reorderded
- */
- protected boolean shouldReorder() {
- final IEditCommandRequest req = getRequest();
- boolean shouldReoder = false;
- if(req instanceof MoveWithIndexRequest) {
- shouldReoder = ((MoveWithIndexRequest)req).shouldReoder();
- }
- return shouldReoder;
- }
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MoveWithIndexRequest.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MoveWithIndexRequest.java
deleted file mode 100644
index 0bc4a3d3b3a..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/MoveWithIndexRequest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*****************************************************************************
- * 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.compare.merger.utils;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
-
-//TODO : move this class
-/**
- *
- * Created for EMF-Compare, for MoveModelElementMerger
- *
- *
- */
-public class MoveWithIndexRequest extends MoveRequest {
-
- /**
- * the wanted index for the moved element
- */
- private final int index;
-
- /**
- * indicates if the list should be reordered after the move
- */
- private final boolean reorder;
-
- //TODO : and the other constructor?
- public MoveWithIndexRequest(final TransactionalEditingDomain editingDomain, final EObject targetContainer, final EReference targetFeature, final EObject elementToMove, final int index, final boolean reorder) {
- super(editingDomain, targetContainer, targetFeature, elementToMove);
- this.index = index;
- this.reorder = reorder;
- }
-
-
- public int getIndex() {
- return this.index;
- }
-
- public boolean shouldReoder() {
- return this.reorder;
- }
-
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusCompareEObjectCopier.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusCompareEObjectCopier.java
deleted file mode 100644
index c72cccc4bd1..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusCompareEObjectCopier.java
+++ /dev/null
@@ -1,299 +0,0 @@
-/*****************************************************************************
- * 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.compare.merger.utils;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-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.notify.impl.AdapterImpl;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.compare.diff.merge.EMFCompareEObjectCopier;
-import org.eclipse.emf.compare.diff.merge.service.MergeService;
-import org.eclipse.emf.compare.diff.metamodel.DiffElement;
-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.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.merger.provider.PapyrusMergeCommandProvider;
-
-/**
- *
- * This class copies the code of {@link EMFCompareEObjectCopier}, to do the actions with EMFCommands
- *
- */
-public class PapyrusCompareEObjectCopier {
-
- /**
- * we encapsulate the "standard" implementation of {@link EMFCompareEObjectCopier}
- */
- private EMFCompareEObjectCopier copier = null;
-
- /**
- *
- * Constructor.
- *
- * @param diff
- * a diff element
- */
- public PapyrusCompareEObjectCopier(final DiffElement diff) {
- copier = MergeService.getCopier(diff);
- }
-
- /**
- * Adapted from copyReferenceValue(EReference targetReference, EObject target, EObject value,
- * EObject matchedValue, int index)
- *
- * @param targetReference
- * @param target
- * @param value
- * @param matchedValue
- * @param index
- * @return
- */
- public Command getCopyReferenceValueCommand(final TransactionalEditingDomain domain, final EReference targetReference, final EObject target, final EObject value, final EObject matchedValue, final int index) {
- EObject actualValue = value;
- if(value == null && matchedValue != null) {
- // handleLinkedResourceDependencyChange(matchedValue);
- // actualValue = get(matchedValue);
- //TODO
- throw new UnsupportedOperationException("Not yet supported");
- }
- if(matchedValue != null) {
- this.copier.put(actualValue, matchedValue);
-
- final Object referenceValue = target.eGet(targetReference);
- if(referenceValue instanceof Collection<?>) {
- //tested with ReferenceChangeLefttargetExample
- return getAddAtIndexCommand(domain, target, targetReference, (Collection<EObject>)referenceValue, matchedValue, index);
-
- } else {
- //target.eSet(targetReference, matchedValue);
- //tested with the project UpdateReferenceExample2
- return PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, target, targetReference, targetReference);
- }
- }
- //tested with ReferenceChangeLefttargetExample2
- return getCopyValueReferenceCommand(domain, targetReference, target, actualValue, index);
- }
-
- private Command getCopyValueReferenceCommand(final TransactionalEditingDomain domain, final EReference targetReference, final EObject target, final EObject value, final int index) {
- final Command copyValueCommand = new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
- final EObject copy;
- final EObject targetValue = PapyrusCompareEObjectCopier.this.copier.get(value);
- if(targetValue != null) {
- copy = targetValue;
- } else {
- if(value.eResource() == null || value.eResource().getURI().isPlatformPlugin()) {
- // We can't copy that object
- copy = value;
- } else {
- copy = PapyrusCompareEObjectCopier.this.copier.copy(value);
- }
- }
- Command cmd = null;
- final Object referenceValue = target.eGet(targetReference);
- if(referenceValue instanceof List && targetReference.isMany()) {
- if(copy.eIsProxy() && copy instanceof InternalEObject) {
- // only add if the element is not already there.
- final URI proxURI = ((InternalEObject)copy).eProxyURI();
- boolean found = false;
- final Iterator<EObject> it = ((List<EObject>)referenceValue).iterator();
- while(!found && it.hasNext()) {
- final EObject obj = it.next();
- if(obj instanceof InternalEObject) {
- found = proxURI.equals(((InternalEObject)obj).eProxyURI());
- }
- }
- if(!found) {
- final List<EObject> targetList = (List<EObject>)referenceValue;
- //addAtIndex(targetList, copy, index);
- //not tested
- cmd = getAddAtIndexCommand(domain, target, targetReference, targetList, copy, index);
- }
- } else {
- final List<EObject> targetList = (List<EObject>)referenceValue;
- final int currentIndex = targetList.indexOf(copy);
- if(currentIndex == -1) {
- //addAtIndex(targetList, copy, index);
- //not tested
- cmd = getAddAtIndexCommand(domain, target, targetReference, targetList, copy, index);
- } else {
- // The order could be wrong in case of eOpposites
- // movetoIndex(targetList, currentIndex, index);
- cmd = getMoveAtIndexCommand(domain, target, targetList, targetReference, copy, currentIndex, index);
- // throw new UnsupportedOperationException("Not yet supported");
- }
- }
- } else {
- if(copy.eIsProxy() && copy instanceof InternalEObject) {
- // only change value if the URI changes
- final URI proxURI = ((InternalEObject)copy).eProxyURI();
- if(referenceValue instanceof InternalEObject) {
- if(!proxURI.equals(((InternalEObject)referenceValue).eProxyURI())) {
- //not tested
- //target.eSet(targetReference, copy);
- cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, target, targetReference, copy);
- }
- }
- } else {
- //not tested
- //target.eSet(targetReference, copy);
- cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, target, targetReference, copy);
- }
- }
-
- if(cmd != null) {
- cmd.execute();
- }
- return CommandResult.newOKCommandResult();
- }
-
- });
- return copyValueCommand;
- }
-
- /**
- *
- * @param key
- * @return
- * the copied object
- */
- public EObject getCopiedValue(final EObject key) {
- return this.copier.get(key);
- }
-
-
- private Command getMoveAtIndexCommand(final TransactionalEditingDomain domain, final EObject target, final List<EObject> targetList, final EReference targetReference, final EObject copy, final int currentIndex, final int expectedIndex) {
- final List<EObject> newColl = new ArrayList<EObject>(targetList);
- final int size = targetList.size();
- if(size <= 1 || currentIndex < 0 || currentIndex >= size) {
- // return;
- //do nothing
- } else if(expectedIndex != -1 && expectedIndex != currentIndex && expectedIndex <= size - 1) {
- newColl.add(expectedIndex, newColl.remove(currentIndex));
- }
-
- return PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, target, targetReference, newColl);
- }
-
- /**
- * Returns the command to set the wanted object at the wanted index
- *
- * @param domain
- * @param editedElement
- * @param feature
- * @param collection
- * @param newValue
- * @param index
- * @return
- */
- private Command getAddAtIndexCommand(final TransactionalEditingDomain domain, final EObject editedElement, final EStructuralFeature feature, final Collection<EObject> collection, final EObject newValue, final int index) {
- final List<EObject> newColl = new ArrayList<EObject>(collection);
- final int listSize = collection.size();
- if(index > -1 && index < listSize) {
- newColl.add(index, newValue);
- } else {
- newColl.add(newValue);
- }
- attachRealPositionEAdapter(newValue, index);
- reorderList(newColl);
- return PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, editedElement, feature, newColl);
- }
-
- /**
- * Duplicate code from EFactory
- * If we could not merge a given object at its expected position in a list, we'll attach an Adapter to it
- * in order to "remember" that "expected" position. That will allow us to reorder the list later on if
- * need be.
- *
- * @param object
- * The object on which to attach an Adapter.
- * @param expectedPosition
- * The expected position of <code>object</code> in its list.
- */
- private void attachRealPositionEAdapter(final Object object, final int expectedPosition) {
- if(object instanceof EObject) {
- ((EObject)object).eAdapters().add(new PositionAdapter(expectedPosition));
- }
- }
-
- /**
- * Duplicate code from EFactory
- * Reorders the given list if it contains EObjects associated with a PositionAdapter which are not located
- * at their expected positions.
- *
- * @param list
- * The list that is to be reordered.
- * @param <T>
- * type of the list's elements.
- */
- private <T> void reorderList(final List<T> list) {
- final List<T> newList = new ArrayList<T>(list);
- Collections.sort(newList, new EObjectComparator());
- for(int i = 0; i < list.size(); i++) {
- int oldIndex = list.indexOf(newList.get(i));
- list.add(i, list.remove(oldIndex));
- }
- return;
- }
-
-
- /**
- * This class exists in several classes of this plugin. It is not an error : the same obejct can be referenced by different
- * feature and different position at the same time. So we need to have a class PositionAdapter for each context!
- * duplicate code from Efactory
- * This adapter will be used to remember the accurate position of an EObject in its target list.
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
- private class PositionAdapter extends AdapterImpl {
-
- /** The index at which we expect to find this object. */
- private final int expectedIndex;
-
- /**
- * Creates our adapter.
- *
- * @param index
- * The index at which we expect to find this object.
- */
- public PositionAdapter(final int index) {
- this.expectedIndex = index;
- }
-
- /**
- * Returns the index at which we expect to find this object.
- *
- * @return The index at which we expect to find this object.
- */
- public int getExpectedIndex() {
- return expectedIndex;
- }
- }
-
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusEFactory.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusEFactory.java
deleted file mode 100644
index 16a6dd1591b..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusEFactory.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/*****************************************************************************
- * 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.compare.merger.utils;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-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.EMFCompareMessages;
-import org.eclipse.emf.compare.FactoryException;
-import org.eclipse.emf.compare.util.EFactory;
-import org.eclipse.emf.ecore.EEnum;
-import org.eclipse.emf.ecore.EEnumLiteral;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.papyrus.uml.compare.merger.Activator;
-import org.eclipse.papyrus.uml.merger.provider.PapyrusMergeCommandProvider;
-//TODO : merge with thepapyrus table command factory?
-/**
- *
- * This class is adapted from {@link EFactory}
- *
- */
-public class PapyrusEFactory {
-
-
- private PapyrusEFactory() {
- //nothing to do
- }
-
- public static final <T> Command getEAddCommand(final TransactionalEditingDomain domain, final EObject object, final String name, final T arg) throws FactoryException {
- return getEAddCommand(domain, object, name, arg, -1);
- }
-
- public static final <T> Command getEAddCommand(final TransactionalEditingDomain domain, final EObject object, final String name, final T arg, final int elementIndex) throws FactoryException {
- return getEAddCommand(domain, object, name, arg, elementIndex, false);
- }
-
- public static final <T> Command getEAddCommand(final TransactionalEditingDomain domain, final EObject object, final String name, final T arg, final int elementIndex, final boolean reorder) throws FactoryException {
- Command returnedCommand = null;
- final EStructuralFeature feature = eStructuralFeature(object, name);
- if(feature.isMany() && arg != null) {
- final Object manyValue = object.eGet(feature);
- // if (manyValue instanceof InternalEList<?>) {
- // final InternalEList<? super T> internalEList = (InternalEList<? super T>)manyValue;
- // final int listSize = internalEList.size();
- // if (elementIndex > -1 && elementIndex < listSize) {
- // internalEList.addUnique(elementIndex, arg);
- // } else {
- // internalEList.addUnique(arg);
- // }
- // if (reorder) {
- // attachRealPositionEAdapter(arg, elementIndex);
- // reorderList(internalEList);
- // }
- // } else if (manyValue instanceof List<?>) {
- // final List<? super T> list = (List<? super T>)manyValue;
- // final int listSize = list.size();
- // if (elementIndex > -1 && elementIndex < listSize) {
- // list.add(elementIndex, arg);
- // } else {
- // list.add(arg);
- // }
- // if (reorder) {
- // attachRealPositionEAdapter(arg, elementIndex);
- // reorderList(list);
- // }
- // } else if (manyValue instanceof Collection<?>) {
- // ((Collection<? super T>)manyValue).add(arg);
- // }
-
- if(manyValue instanceof Collection<?>) {
- List<Object> newValue = new ArrayList<Object>((Collection<?>)manyValue);
- final int listSize = newValue.size();
- if(manyValue instanceof List<?>) {
- if(elementIndex > -1 && elementIndex < listSize) {
- newValue.add(elementIndex, arg);
- } else {
- newValue.add(arg);
- }
- if(reorder) {
- attachRealPositionEAdapter(arg, elementIndex);
- reorderList((List<?>)newValue);
- }
- } else if(manyValue instanceof Collection<?>) {
- newValue.add(arg);
- }
- returnedCommand = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, object, feature, newValue);
- }
- } else if(!feature.isMany()) {
- // eSet(object, name, arg);
- returnedCommand = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, object, feature, arg);
- }
- return returnedCommand;
- }
-
- //TODO not tested
- public static final Command getERemoveCommand(final TransactionalEditingDomain domain, final EObject object, final String name, final Object arg) throws FactoryException {
- // final Object list = object.eGet(eStructuralFeature(object, name));
- // if (list instanceof List) {
- // if (arg != null) {
- // ((List<?>)list).remove(arg);
- // }
- // } else {
- // eSet(object, name, null);
- // }
- final Object list = object.eGet(eStructuralFeature(object, name));
- if(list instanceof List) {
- if(arg != null) {
- List<?> newValue = new ArrayList((List<?>)list);
- ((List<?>)newValue).remove(arg);
- return getESetCommand(domain, object, name, newValue);
- }
- } else {
- return getESetCommand(domain, object, name, null);
- }
- return null;
- }
-
- /**
- *
- * @param object
- * @param name
- * @param arg
- * @return
- * @throws FactoryException
- */
- public static final Command getESetCommand(final TransactionalEditingDomain domain, final EObject object, final String name, final Object arg) throws FactoryException {
- Command returnedCommand;
- final EStructuralFeature feature = eStructuralFeature(object, name);
- if(!feature.isChangeable())
- throw new FactoryException(EMFCompareMessages.getString("EFactory.UnSettableFeature", name)); //$NON-NLS-1$
-
- if(feature.getEType() instanceof EEnum && arg instanceof String) {
- final EEnumLiteral literal = ((EEnum)feature.getEType()).getEEnumLiteral((String)arg);
- //object.eSet(feature, literal);
- returnedCommand = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, object, feature, literal);
- } else {
- if(arg == null && feature.isMany()) {
- //object.eSet(feature, Collections.EMPTY_LIST);
- returnedCommand = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, object, feature, Collections.EMPTY_LIST);
- } else if(arg == null) {
- //object.eSet(feature, feature.getDefaultValue());
- returnedCommand = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, object, feature, feature.getDefaultValue());
- } else {
- //object.eSet(feature, arg);
- returnedCommand = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, object, feature, arg);
- }
- }
- return returnedCommand;
- }
-
-
- public static EStructuralFeature eStructuralFeature(final EObject object, final String name) throws FactoryException {
- return EFactory.eStructuralFeature(object, name);
- }
-
-
-
- // /**
- // * If we could not merge a given object at its expected position in a list, we'll attach an Adapter to it
- // * in order to "remember" that "expected" position. That will allow us to reorder the list later on if
- // * need be.
- // *
- // * @param object
- // * The object on which to attach an Adapter.
- // * @param expectedPosition
- // * The expected position of <code>object</code> in its list.
- // */
- // public static void attachRealPositionEAdapter(final Object object, final int expectedPosition) {
- // Class<?> myClass = null;
- // try {
- // myClass = Class.forName("org.eclipse.emf.compare.util.EFactory");
- // } catch (ClassNotFoundException e2) {
- // // TODO Auto-generated catch block
- // e2.printStackTrace();
- // }
- // Class[] parameterTypes = new Class[2];
- // parameterTypes[0] = java.lang.Object.class;
- // parameterTypes[1] = Integer.TYPE;
- // Method m = null;
- //
- // try {
- // m = myClass.getDeclaredMethod("attachRealPositionEAdapter", parameterTypes);
- // } catch (SecurityException e1) {
- // // TODO Auto-generated catch block
- // e1.printStackTrace();
- // } catch (NoSuchMethodException e1) {
- // // TODO Auto-generated catch block
- // e1.printStackTrace();
- // }
- // m.setAccessible(true);
- // Object[] parameters = new Object[2];
- // parameters[0] = object;
- // parameters[1] = expectedPosition;
- //
- // Object result = null;
- // try {
- // result = m.invoke(myClass, parameters);
- // } catch (IllegalArgumentException e) {
- // Activator.log.error(e);
- // } catch (IllegalAccessException e) {
- // Activator.log.error(e);
- // } catch (InvocationTargetException e) {
- // Activator.log.error(e);
- // }
- // }
-
- /**
- * Duplicate code from EFactory
- * If we could not merge a given object at its expected position in a list, we'll attach an Adapter to it
- * in order to "remember" that "expected" position. That will allow us to reorder the list later on if
- * need be.
- *
- * @param object
- * The object on which to attach an Adapter.
- * @param expectedPosition
- * The expected position of <code>object</code> in its list.
- */
- public static void attachRealPositionEAdapter(final Object object, final int expectedPosition) {
- if(object instanceof EObject) {
- ((EObject)object).eAdapters().add(new PositionAdapter(expectedPosition));
- }
- }
-
- /**
- * Reorders the given list if it contains EObjects associated with a PositionAdapter which are not located
- * at their expected positions.
- *
- * @param list
- * The list that is to be reordered.
- * @param <T>
- * type of the list's elements.
- */
- public static <T> void reorderList(final List<T> list) {
- List<T> newList = new ArrayList<T>(list);
- Collections.sort(newList, new EObjectComparator());
- for(int i=0;i<list.size();i++){
- int oldIndex = list.indexOf(newList.get(i));
- list.add(i, list.remove(oldIndex));
- }
- return;
- }
-
-
- /**
- * This method should never been called, except by copyCollection;
- * This method allows to invoke the clone method on Cloneable object.
- *
- * @param cloneable
- * a cloneable object
- * @return
- * a copy of the cloned object
- * @throws UnsupportedOperationException
- * used when the object is {@link Cloneable}, but not implemented (like LinkedList...)
- */
- private static Object clone(final Cloneable cloneable) throws UnsupportedOperationException {
- Class<?> cloneableClass = cloneable.getClass();
- Method cloneMethod = null;
- Object newValue = null;
- try {
- cloneMethod = cloneableClass.getMethod("clone", new Class[0]);
- } catch (SecurityException e) {
- Activator.log.error(e);
- } catch (NoSuchMethodException e) {
- Activator.log.error(e);
- }
- cloneMethod.setAccessible(true);
- try {
- newValue = cloneMethod.invoke(cloneable, new Object[0]);
- } catch (IllegalArgumentException e) {
- Activator.log.error(e);
- } catch (IllegalAccessException e) {
- Activator.log.error(e);
- } catch (InvocationTargetException e) {
- Activator.log.error(e);
- } catch (UnsupportedOperationException e) {
- Activator.log.error(NLS.bind("I can't clone this object : {0}", cloneableClass), e);
- throw e;
- }
- return newValue;
- }
-
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PositionAdapter.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PositionAdapter.java
deleted file mode 100644
index d95ee07f40d..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PositionAdapter.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*****************************************************************************
- * 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.compare.merger.utils;
-
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-
-
- /**
- * duplicate code from Efactory
- * This adapter will be used to remember the accurate position of an EObject in its target list.
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
-public class PositionAdapter extends AdapterImpl {
-
- /** The index at which we expect to find this object. */
- private final int expectedIndex;
-
- /**
- * Creates our adapter.
- *
- * @param index
- * The index at which we expect to find this object.
- */
- public PositionAdapter(final int index) {
- this.expectedIndex = index;
- }
-
- /**
- * Returns the index at which we expect to find this object.
- *
- * @return The index at which we expect to find this object.
- */
- public int getExpectedIndex() {
- return expectedIndex;
- }
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/PapyrusMergeCommandProvider.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/internal/provider/PapyrusMergeCommandProvider.java
index 86ea40aa0ee..f09c9874891 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/PapyrusMergeCommandProvider.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/internal/provider/PapyrusMergeCommandProvider.java
@@ -11,7 +11,7 @@
* Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
-package org.eclipse.papyrus.uml.merger.provider;
+package org.eclipse.papyrus.uml.merger.internal.provider;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
@@ -34,8 +34,8 @@ import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.uml.compare.merger.utils.MoveWithIndexCommand;
-import org.eclipse.papyrus.uml.compare.merger.utils.MoveWithIndexRequest;
+import org.eclipse.papyrus.uml.compare.merger.internal.utils.MoveWithIndexCommand;
+import org.eclipse.papyrus.uml.compare.merger.internal.utils.MoveWithIndexRequest;
//TODO : try to merge with the PapyrusTableCommandFactory?
public class PapyrusMergeCommandProvider {
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/PapyrusUMLMergeProvider.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/internal/provider/PapyrusUMLMergeProvider.java
index a80630364b5..878a6ddce82 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/PapyrusUMLMergeProvider.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/internal/provider/PapyrusUMLMergeProvider.java
@@ -11,7 +11,7 @@
* Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
-package org.eclipse.papyrus.uml.merger.provider;
+package org.eclipse.papyrus.uml.merger.internal.provider;
import java.util.Map;
@@ -30,6 +30,18 @@ import org.eclipse.emf.compare.diff.metamodel.ReferenceChangeRightTarget;
import org.eclipse.emf.compare.diff.metamodel.ReferenceOrderChange;
import org.eclipse.emf.compare.diff.metamodel.UpdateAttribute;
import org.eclipse.emf.compare.diff.metamodel.UpdateReference;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CAttributeChangeLeftTargetMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CAttributeChangeRightTargetMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CAttributeOrderChangeMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CDiffGroupMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CModelElementChangeLeftTargetMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CModelElementChangeRightTargetMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CMoveModelElementMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CReferenceChangeLeftTargetMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CReferenceChangeRightTargetMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CReferenceOrderChangeMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CUpdateAttributeMerger;
+import org.eclipse.papyrus.uml.compare.merger.internal.merger.CUpdateReferenceMerger;
import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusMap;
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
deleted file mode 100644
index ab6f4be1104..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeLeftTargetMerger.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*****************************************************************************
- * 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.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.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 CAttributeChangeLeftTargetMerger extends AttributeChangeLeftTargetMerger implements ITransactionalMerger {
-
- /**
- * {@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();
- }
- }
-
- @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 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;
- valueIndex = leftValuesList.indexOf(value);
- }
- }
- 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
deleted file mode 100644
index 6f28a60dedb..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeChangeRightTargetMerger.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*****************************************************************************
- * 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.compare.FactoryException;
-import org.eclipse.emf.compare.diff.internal.merge.impl.AttributeChangeRightTargetMerger;
-import org.eclipse.emf.compare.diff.metamodel.AttributeChangeRightTarget;
-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 implements ITransactionalMerger {
-
- /**
- * {@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 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();
-
- 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()) {
- final EObject rightElement = theDiff.getRightElement();
- final Object rightValues = rightElement.eGet(attr);
- if (rightValues instanceof List) {
- final List<?> rightValuesList = (List<?>)rightValues;
- valueIndex = rightValuesList.indexOf(value);
- }
- }
- cmd = PapyrusEFactory.getEAddCommand(domain, origin, attr.getName(), value, valueIndex);
- } catch (FactoryException e) {
- Activator.log.error(e);
- }
- return cmd;
- }
-
- 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;
- }
-
- 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 {
- CAttributeChangeRightTargetMerger.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 {
- 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
deleted file mode 100644
index 48e297478a6..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CAttributeOrderChangeMerger.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*****************************************************************************
- * 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;
-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 implements ITransactionalMerger {
-
- /**
- * {@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 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));
- }
-
- 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);
- }
- }
-
- 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);
- }
-
- 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();
-
- 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));
- }
-
- 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);
- }
- }
-
- 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;
- }
- });
- }
-
- /**
- * This method uses the reflexive way to call the static method of the super class
- *
- * @param left
- * the left object
- * @param right
- * the right object
- * @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) {
-
- final Class<?>[] parameterTypes = new Class[2];
- parameterTypes[0] = java.lang.Object.class;
- parameterTypes[1] = java.lang.Object.class;
- Method m = null;
- try {
- m = ReflectHelper.getMethod(AttributeOrderChangeMerger.class, "areDistinctValues", parameterTypes);
- } catch (SecurityException e) {
- Activator.log.error(e);
- } catch (NoSuchMethodException e) {
- Activator.log.error(e);
- }
-
- Object[] parameters = new Object[2];
- parameters[0] = left;
- parameters[1] = right;
-
- Object result = null;
- try {
- result = m.invoke(AttributeOrderChangeMerger.class, parameters);
- } catch (IllegalArgumentException e) {
- Activator.log.error(e);
- } catch (IllegalAccessException e) {
- Activator.log.error(e);
- } catch (InvocationTargetException e) {
- Activator.log.error(e);
- }
- 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
deleted file mode 100644
index da5e03eda80..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDefaultExtensionMerger.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*****************************************************************************
- * 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
deleted file mode 100644
index 8906d858844..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffExtensionMerger.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*****************************************************************************
- * 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
deleted file mode 100644
index 471bb6fd00d..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CDiffGroupMerger.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*****************************************************************************
- * 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.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 ITransactionalMerger {
-
- /**
- * {@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) {
- throw new UnsupportedOperationException("Not yet supported");
- }
-
- public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
- throw new UnsupportedOperationException("Not yet supported");
- }
-
- 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
deleted file mode 100644
index e394d4c2b05..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*****************************************************************************
- * 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.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.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.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.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 CModelElementChangeLeftTargetMerger extends ModelElementChangeLeftTargetMerger implements ITransactionalMerger {
-
- /**
- * {@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 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(domain, origin, ref.getName(), newOne, elementIndex, true));
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, element, newOne));
- } catch (final FactoryException e) {
- Activator.log.error(e);
- }
- } 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();
- }
- }));
-
- 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
deleted file mode 100644
index 20babf3a4f9..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*****************************************************************************
- * 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.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.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.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.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 CModelElementChangeRightTargetMerger extends ModelElementChangeRightTargetMerger implements ITransactionalMerger {
-
- /**
- * {@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 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(domain, origin, ref.getName(), newOne, expectedIndex, true));
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, element, newOne));
- } catch (final FactoryException e) {
- Activator.log.error(e);
- }
- } 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();
- }
- }));
- 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);
- }
-
-
- 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
deleted file mode 100644
index 4e1f687cc8a..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*****************************************************************************
- * 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.ecore.xmi.XMIResource;
-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 implements ITransactionalMerger {
-
- /**
- * {@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 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, true));
- } else {
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveCommand(domain, leftTarget, leftTarget, ref, leftElement));
- }
- cmd.append(getPreserveXMIIDCommand(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, true));
- } else {
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveCommand(domain, rightTarget, rightTarget, ref, rightElement));
- }
- final String elementID = getXMIID(rightElement);
- cmd.append(getPreserveXMIIDCommand(domain, rightElement, elementID));
- } else {
- // 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;
- }
- });
- }
-
- /**
- * This command is not the the class PapyrusUMLMergeProvider because it only should be used to preserve the xmi_id after a move,
- * but not to change the id
- *
- * @param domain
- * @param element
- * @param id
- * @return
- * the command to set the ID
- */
- private Command getPreserveXMIIDCommand(final TransactionalEditingDomain domain, final EObject element, final String id) {
- //TODO change for an EMFCommand
- return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Set XMI Command", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
- if(element != null && element.eResource() instanceof XMIResource) {
- ((XMIResource)element.eResource()).setID(element, id);
- }
- return CommandResult.newOKCommandResult();
- }
- });
-
- }
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceChangeLeftTargetMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceChangeLeftTargetMerger.java
deleted file mode 100644
index 329cdaaab62..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceChangeLeftTargetMerger.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*****************************************************************************
- * 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.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.FactoryException;
-import org.eclipse.emf.compare.diff.internal.merge.impl.ReferenceChangeLeftTargetMerger;
-import org.eclipse.emf.compare.diff.metamodel.DiffElement;
-import org.eclipse.emf.compare.diff.metamodel.ReferenceChangeLeftTarget;
-import org.eclipse.emf.compare.diff.metamodel.ReferenceOrderChange;
-import org.eclipse.emf.compare.diff.metamodel.ResourceDependencyChange;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-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.PapyrusCompareEObjectCopier;
-import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusEFactory;
-
-
-public class CReferenceChangeLeftTargetMerger extends ReferenceChangeLeftTargetMerger implements ITransactionalMerger {
-
- /**
- * {@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 CReferenceChangeLeftTargetMerger");
- 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 CReferenceChangeLeftTargetMerger");
- 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("CReferenceChangeLeftTargetMerger#getDoApplyInOriginCommand");
- final ReferenceChangeLeftTarget theDiff = (ReferenceChangeLeftTarget)this.diff;
- final EObject element = theDiff.getLeftElement();
- final EObject leftTarget = theDiff.getLeftTarget();
- try {
- cmd.append(PapyrusEFactory.getERemoveCommand(domain, element, theDiff.getReference().getName(), leftTarget));
- } catch (final FactoryException e) {
- Activator.log.error(e);
- }
- 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 ReferenceChangeLeftTarget) {
- final ReferenceChangeLeftTarget link = (ReferenceChangeLeftTarget)op;
- // now if I'm in the target References I should put my copy in the origin
- if(link.getReference().equals(theDiff.getReference().getEOpposite()) && link.getLeftTarget().equals(element)) {
- removeFromContainer(link);
- }
- } else if(op instanceof ResourceDependencyChange) {
- final ResourceDependencyChange link = (ResourceDependencyChange)op;
- final Resource res = link.getRoots().get(0).eResource();
- if(res == leftTarget.eResource()) {
- EcoreUtil.remove(link);
- res.unload();
- }
- }
- }
- return CommandResult.newOKCommandResult();
- }
- }));
- return cmd;
- }
-
- public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
- final CompoundCommand cmd = new CompoundCommand();
- final ReferenceChangeLeftTarget theDiff = (ReferenceChangeLeftTarget)this.diff;
- final EReference reference = theDiff.getReference();
- final EObject element = theDiff.getRightElement();
- final EObject leftTarget = theDiff.getLeftTarget();
- final EObject rightTarget = theDiff.getRightTarget();
-
- int index = -1;
- if(reference.isMany()) {
- final EObject leftElement = theDiff.getLeftElement();
- final Object leftRefValue = leftElement.eGet(reference);
- if(leftRefValue instanceof List) {
- final List<?> refLeftValueList = (List<?>)leftRefValue;
- index = refLeftValueList.indexOf(leftTarget);
- }
- }
- final PapyrusCompareEObjectCopier copier = new PapyrusCompareEObjectCopier(diff);
- Command copierCommand = copier.getCopyReferenceValueCommand(domain, reference, element, leftTarget, rightTarget, index);
- cmd.append(copierCommand);
- final AbstractTransactionalCommand updateDiffModelCommand = new AbstractTransactionalCommand(domain, "Update Diff Model", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
- final EObject copiedValue = copier.getCopiedValue(leftTarget);
- final Iterator<EObject> siblings = getDiffModel().eAllContents();
- while(siblings.hasNext()) {
- final DiffElement op = (DiffElement)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.getReference().equals(reference.getEOpposite()) && link.getLeftTarget().equals(element)) {
- removeFromContainer(link);
- }
- } else if(op instanceof ReferenceOrderChange) {
- final ReferenceOrderChange link = (ReferenceOrderChange)op;
- if(link.getLeftElement() == element && link.getReference() == reference) {
- 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(leftTarget))) {
- targetIterator.set(copiedValue);
- replaced = true;
- }
- }
- }
- }
- }
- return CommandResult.newOKCommandResult();
- }
- };
- cmd.append(new GMFtoEMFCommandWrapper(updateDiffModelCommand));
- return cmd;
- }
-
- public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin) {
- return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
- CReferenceChangeLeftTargetMerger.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 {
- CReferenceChangeLeftTargetMerger.this.postProcess();
- return null;
- }
- });
- }
-
-
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceChangeRightTargetMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceChangeRightTargetMerger.java
deleted file mode 100644
index d9cd17b383a..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceChangeRightTargetMerger.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*****************************************************************************
- * 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.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.FactoryException;
-import org.eclipse.emf.compare.diff.internal.merge.impl.ReferenceChangeRightTargetMerger;
-import org.eclipse.emf.compare.diff.metamodel.DiffElement;
-import org.eclipse.emf.compare.diff.metamodel.ReferenceChangeRightTarget;
-import org.eclipse.emf.compare.diff.metamodel.ReferenceOrderChange;
-import org.eclipse.emf.compare.diff.metamodel.ResourceDependencyChange;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-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.PapyrusCompareEObjectCopier;
-import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusEFactory;
-
-
-public class CReferenceChangeRightTargetMerger extends ReferenceChangeRightTargetMerger implements ITransactionalMerger {
-
- /**
- * {@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();
- }
- }
-
- @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 CReferenceChangeRightTargetMerger");
- 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 CReferenceChangeRightTargetMerger");
- cmd.append(getMergeRequiredDifferencesCommand(domain, false));
- cmd.append(getDoUndoInTargetCommand(domain));
- cmd.append(getPostProcessCommand(domain));
- return cmd;
- }
-
- public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain) {
- CompoundCommand cmd = new CompoundCommand("Undo In Target Command for CReferenceChangeRightTargetMerger#getDoApplyInOriginCommand");
- final ReferenceChangeRightTarget theDiff = (ReferenceChangeRightTarget)this.diff;
- final EReference reference = theDiff.getReference();
- final EObject element = theDiff.getLeftElement();
- final EObject rightTarget = theDiff.getRightTarget();
- final EObject leftTarget = theDiff.getLeftTarget();
-
- // ordering handling:
- int index = -1;
- if(reference.isMany()) {
- final EObject rightElement = theDiff.getRightElement();
- final Object rightRefValue = rightElement.eGet(reference);
- if(rightRefValue instanceof List) {
- final List<?> refRightValueList = (List<?>)rightRefValue;
- index = refRightValueList.indexOf(rightTarget);
- }
- }
- final PapyrusCompareEObjectCopier copier = new PapyrusCompareEObjectCopier(diff);
- cmd.append(copier.getCopyReferenceValueCommand(domain, reference, element, rightTarget, leftTarget, index));
-
- cmd.append(new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
- final EObject copiedValue = copier.getCopiedValue(rightTarget);
- // We'll now look through this reference's eOpposite as they are already taken care of
- final Iterator<EObject> related = getDiffModel().eAllContents();
- while(related.hasNext()) {
- final DiffElement op = (DiffElement)related.next();
- if(op instanceof ReferenceChangeRightTarget) {
- final ReferenceChangeRightTarget link = (ReferenceChangeRightTarget)op;
- // If this is my eOpposite, delete it from the DiffModel (merged along with this one)
- if(link.getReference().equals(theDiff.getReference().getEOpposite()) && link.getRightTarget().equals(element)) {
- removeFromContainer(link);
- }
- } else if(op instanceof ReferenceOrderChange) {
- final ReferenceOrderChange link = (ReferenceOrderChange)op;
- if(link.getLeftElement() == element && link.getReference() == reference) {
- 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(rightTarget))) {
- targetIterator.set(copiedValue);
- replaced = true;
- }
- }
- }
- }
- }
- return CommandResult.newOKCommandResult();
- }
- }));
-
- return cmd;
- }
-
- public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
- CompoundCommand cmd = new CompoundCommand("Undo In Target Command for CReferenceChangeRightTargetMerger#getDoUndoInTargetCommand");
- final ReferenceChangeRightTarget theDiff = (ReferenceChangeRightTarget)this.diff;
- final EObject element = theDiff.getRightElement();
- final EObject rightTarget = theDiff.getRightTarget();
- try {
- cmd.append(PapyrusEFactory.getERemoveCommand(domain, element, theDiff.getReference().getName(), rightTarget));
- } catch (final FactoryException e) {
- Activator.log.error(e);
- }
- 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> related = getDiffModel().eAllContents();
- while(related.hasNext()) {
- final DiffElement op = (DiffElement)related.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.getReference().equals(theDiff.getReference().getEOpposite()) && link.getRightTarget().equals(element)) {
- removeFromContainer(link);
- }
- } else if(op instanceof ResourceDependencyChange) {
- final ResourceDependencyChange link = (ResourceDependencyChange)op;
- final Resource res = link.getRoots().get(0).eResource();
- if(res == rightTarget.eResource()) {
- EcoreUtil.remove(link);
- res.unload();
- }
- }
- }
- return CommandResult.newOKCommandResult();
- }
- }));
-
- 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 {
- CReferenceChangeRightTargetMerger.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 {
- CReferenceChangeRightTargetMerger.this.postProcess();
- return null;
- }
- });
- }
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceOrderChangeMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceOrderChangeMerger.java
deleted file mode 100644
index d060a14b674..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceOrderChangeMerger.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*****************************************************************************
- * 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 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.FactoryException;
-import org.eclipse.emf.compare.diff.internal.merge.impl.ReferenceOrderChangeMerger;
-import org.eclipse.emf.compare.diff.merge.DefaultMerger;
-import org.eclipse.emf.compare.diff.metamodel.ReferenceOrderChange;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.InternalEObject;
-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;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-
-public class CReferenceOrderChangeMerger extends ReferenceOrderChangeMerger implements ITransactionalMerger {
-
- /**
- * {@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();
- }
- }
-
- @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 CReferenceOrderChangeMerger");
- 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 CReferenceOrderChangeMerger");
- 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 ReferenceOrderChange theDiff = (ReferenceOrderChange)this.diff;
- final EObject leftElement = theDiff.getLeftElement();
-
- final Collection<EObject> target = Lists.newArrayList(Collections2.filter(theDiff.getLeftTarget(), new Predicate<EObject>() {
-
- public boolean apply(final EObject input) {
- return !input.eIsProxy() || !DefaultMerger.isEMFCompareProxy(((InternalEObject)input).eProxyURI());
- }
- }));
-
- try {
- cmd = PapyrusEFactory.getESetCommand(domain, leftElement, theDiff.getReference().getName(), target);
- } catch (final FactoryException e) {
- Activator.log.error(e);
- }
- return cmd;
- }
-
- public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
- Command cmd = null;
- final ReferenceOrderChange theDiff = (ReferenceOrderChange)this.diff;
- final EObject rightElement = theDiff.getRightElement();
-
- final Collection<EObject> target = Lists.newArrayList(Collections2.filter(theDiff.getRightTarget(), new Predicate<EObject>() {
-
- public boolean apply(final EObject input) {
- return !input.eIsProxy() || !DefaultMerger.isEMFCompareProxy(((InternalEObject)input).eProxyURI());
- }
- }));
-
- try {
- cmd = PapyrusEFactory.getESetCommand(domain, rightElement, theDiff.getReference().getName(), target);
- } catch (final 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 {
- CReferenceOrderChangeMerger.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 {
- CReferenceOrderChangeMerger.this.postProcess();
- return null;
- }
- });
- }
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateAttributeMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateAttributeMerger.java
deleted file mode 100644
index f8d23c21d4d..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateAttributeMerger.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*****************************************************************************
- * 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.compare.FactoryException;
-import org.eclipse.emf.compare.diff.internal.merge.impl.UpdateAttributeMerger;
-import org.eclipse.emf.compare.diff.metamodel.UpdateAttribute;
-import org.eclipse.emf.compare.util.EFactory;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.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 CUpdateAttributeMerger extends UpdateAttributeMerger implements ITransactionalMerger {
-
- /**
- * {@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();
- }
- }
-
- @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 CUpdateAttributeMerger");
- 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 CUpdateAttributeMerger");
- 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 UpdateAttribute theDiff = (UpdateAttribute)this.diff;
- final EObject element = theDiff.getRightElement();
- final EObject origin = theDiff.getLeftElement();
- final EAttribute attr = theDiff.getAttribute();
- try {
- cmd = PapyrusEFactory.getESetCommand(domain, origin, attr.getName(), EFactory.eGet(element, attr.getName()));
- } catch (FactoryException e) {
- Activator.log.error(e);
- }
- return cmd;
- }
-
- public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
- Command cmd = null;
- final UpdateAttribute theDiff = (UpdateAttribute)this.diff;
- final EObject element = theDiff.getRightElement();
- final EObject origin = theDiff.getLeftElement();
- final EAttribute attr = theDiff.getAttribute();
- try {
- cmd = PapyrusEFactory.getESetCommand(domain, element, attr.getName(), EFactory.eGet(origin, attr.getName()));
- } 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 {
- CUpdateAttributeMerger.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 {
- CUpdateAttributeMerger.this.postProcess();
- return null;
- }
- });
- }
-}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateReferenceMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateReferenceMerger.java
deleted file mode 100644
index 3f89bb0acaf..00000000000
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateReferenceMerger.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*****************************************************************************
- * 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.compare.diff.internal.merge.impl.UpdateReferenceMerger;
-import org.eclipse.emf.compare.diff.metamodel.UpdateReference;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.util.FeatureMapUtil;
-import org.eclipse.emf.edit.command.SetCommand;
-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;
-import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusCompareEObjectCopier;
-
-
-public class CUpdateReferenceMerger extends UpdateReferenceMerger implements ITransactionalMerger {
-
- /**
- * {@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();
- }
- }
-
- @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 CUpdateReferenceMerger");
- 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 CUpdateReferenceMerger");
- 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 UpdateReference theDiff = (UpdateReference)this.diff;
- final EReference reference = theDiff.getReference();
- final EObject element = theDiff.getLeftElement();
- final EObject leftTarget = (EObject)theDiff.getRightElement().eGet(reference);
- final EObject matchedLeftTarget = theDiff.getLeftTarget();
-
- if(leftTarget == null) {
- if(FeatureMapUtil.isMany(element, reference)) {
- //TODO : I didn't find an example to test this case.
- throw new UnsupportedOperationException("Not Yet Supported");
- } else {
- final Object value = theDiff.getLeftElement().eGet(reference);
- if(value instanceof EObject) {
- cmd = PapyrusMergeCommandProvider.INSTANCE.getDestroyReferenceCommand(domain, element, reference, (EObject)value, false);
- } else {
- //TODO : we don't use the ServiceEdit
- //TODO : not tested
- // element.eUnset(reference);
- cmd = new SetCommand(domain, element, reference, null);
- }
- }
- } else {
- final PapyrusCompareEObjectCopier copier = new PapyrusCompareEObjectCopier(diff);
- cmd = copier.getCopyReferenceValueCommand(domain, reference, element, leftTarget, matchedLeftTarget, -1);
- }
- return cmd;
- }
-
-
- public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) {
- Command cmd = null;
- final UpdateReference theDiff = (UpdateReference)this.diff;
- final EReference reference = theDiff.getReference();
- final EObject element = theDiff.getRightElement();
- final EObject rightTarget = (EObject)theDiff.getLeftElement().eGet(reference);
- final EObject matchedRightTarget = theDiff.getRightTarget();
-
- if(rightTarget == null) {
- if(FeatureMapUtil.isMany(element, reference)) {
- //TODO : I didn't find an example to test this case.
- throw new UnsupportedOperationException("Not Yet Supported");
- } else {
- final Object value = theDiff.getRightElement().eGet(reference);
- if(value instanceof EObject) {
- cmd = PapyrusMergeCommandProvider.INSTANCE.getDestroyReferenceCommand(domain, element, reference, (EObject)value, false);
- } else {
- //TODO : we don't use the ServiceEdit
- //TODO : not tested
- // element.eUnset(reference);
- cmd = new SetCommand(domain, element, reference, null);
- }
- }
- } else {
- final PapyrusCompareEObjectCopier copier = new PapyrusCompareEObjectCopier(diff);
- cmd = copier.getCopyReferenceValueCommand(domain, reference, element, rightTarget, matchedRightTarget, -1);
- }
- 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 {
- CUpdateReferenceMerger.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 {
- CUpdateReferenceMerger.this.postProcess();
- return null;
- }
- });
- }
-}

Back to the top