Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-05-02 04:47:38 -0400
committervlorenzo2012-05-02 04:47:38 -0400
commit6082a766756a8d693e1fcfcd83f31fc64b5ce3fa (patch)
tree36cfce89a2c8547335ae02c3355c3d84805f0250 /sandbox/UMLCompareMergerExample
parentc151fc541ceee3f2de3f068c390080aa68033d53 (diff)
downloadorg.eclipse.papyrus-6082a766756a8d693e1fcfcd83f31fc64b5ce3fa.tar.gz
org.eclipse.papyrus-6082a766756a8d693e1fcfcd83f31fc64b5ce3fa.tar.xz
org.eclipse.papyrus-6082a766756a8d693e1fcfcd83f31fc64b5ce3fa.zip
377189: [Nested UML Compare] the merged elements have the same XMI ID
https://bugs.eclipse.org/bugs/show_bug.cgi?id=377189
Diffstat (limited to 'sandbox/UMLCompareMergerExample')
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java2
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java2
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java30
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/PapyrusMergeCommandProvider.java24
4 files changed, 51 insertions, 7 deletions
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java
index 6f659c3a222..12a13a4ed83 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeLeftTargetMerger.java
@@ -129,7 +129,7 @@ public class CModelElementChangeLeftTargetMerger extends ModelElementChangeLeftT
// EFactory.eAdd(origin, ref.getName(), newOne, elementIndex, true);
// setXMIID(newOne, getXMIID(element));
cmd.append(PapyrusEFactory.getEAddCommand(domain, origin, ref.getName(), newOne, elementIndex, true));
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, newOne, getXMIID(element)));
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, element, newOne));
} catch (final FactoryException e) {
Activator.log.error(e);
}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java
index df75b31945c..0f086d8ef1a 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CModelElementChangeRightTargetMerger.java
@@ -123,7 +123,7 @@ public class CModelElementChangeRightTargetMerger extends ModelElementChangeRigh
// EFactory.eAdd(origin, ref.getName(), newOne, expectedIndex, true);
// setXMIID(newOne, getXMIID(element));
cmd.append(PapyrusEFactory.getEAddCommand(domain, origin, ref.getName(), newOne, expectedIndex, true));
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, newOne, getXMIID(element)));
+ cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, element, newOne));
} catch (final FactoryException e) {
Activator.log.error(e);
}
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java
index f0bceedd276..41305144c88 100644
--- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CMoveModelElementMerger.java
@@ -25,6 +25,7 @@ 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;
@@ -122,7 +123,7 @@ public class CMoveModelElementMerger extends MoveModelElementMerger implements I
} else {
cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveCommand(domain, leftTarget, leftTarget, ref, leftElement));
}
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, leftElement, elementID));
+ cmd.append(getPreserveXMIIDCommand(domain, leftElement, elementID));
} else {
// shouldn't be here
@@ -152,7 +153,7 @@ public class CMoveModelElementMerger extends MoveModelElementMerger implements I
cmd.append(PapyrusMergeCommandProvider.INSTANCE.getMoveCommand(domain, rightTarget, rightTarget, ref, rightElement));
}
final String elementID = getXMIID(rightElement);
- cmd.append(PapyrusMergeCommandProvider.INSTANCE.getSetXMIIDCommand(domain, rightElement, elementID));
+ cmd.append(getPreserveXMIIDCommand(domain, rightElement, elementID));
} else {
// shouldn't be here
cmd.append(UnexecutableCommand.INSTANCE);
@@ -183,4 +184,29 @@ public class CMoveModelElementMerger extends MoveModelElementMerger implements I
}
});
}
+
+ /**
+ * 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/PapyrusMergeCommandProvider.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/PapyrusMergeCommandProvider.java
index 036c79f5bcf..e8c5a4a6da2 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/provider/PapyrusMergeCommandProvider.java
@@ -31,6 +31,7 @@ import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
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;
@@ -77,14 +78,31 @@ public class PapyrusMergeCommandProvider {
return getCommand(element, request);
}
- public Command getSetXMIIDCommand(final TransactionalEditingDomain domain, final EObject element, final String id) {
+
+ /**
+ * Returns the command to set the id of the source object to the new object. This command do something, only if the source and the target aren't
+ * owned by the same resource
+ *
+ * @param domain
+ * @param sourceElement
+ * @param targetElement
+ * @return
+ * the command to set the id of the source object to the new object
+ */
+ public Command getSetXMIIDCommand(final TransactionalEditingDomain domain, final EObject sourceElement, final EObject targetElement) {
//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);
+ final Resource sourceResource = sourceElement.eResource();
+ final Resource targetResource = targetElement.eResource();
+ if(sourceElement != null && targetElement != null && sourceResource instanceof XMIResource && targetResource instanceof XMIResource) {
+ //TODO : this test is commented because the result of this command is worse with the test than without...
+ // if(sourceResource != targetResource) {
+ final String xmi_id = EMFHelper.getXMIID(sourceElement);
+ ((XMIResource)targetElement.eResource()).setID(sourceElement, xmi_id);
+ // }
}
return CommandResult.newOKCommandResult();
}

Back to the top