Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-04-30 05:29:40 -0400
committervlorenzo2012-04-30 05:29:40 -0400
commita9ef6455aeb2430d6cba30f854c0a101bd7e0cf3 (patch)
tree7b36f97bbbe73dff1e9f0524a3894031c5f576ab /sandbox/UMLCompareMergerExample
parent61f0cb8dc55fac77fcf8a0e6ec6e8dd30ada037b (diff)
downloadorg.eclipse.papyrus-a9ef6455aeb2430d6cba30f854c0a101bd7e0cf3.tar.gz
org.eclipse.papyrus-a9ef6455aeb2430d6cba30f854c0a101bd7e0cf3.tar.xz
org.eclipse.papyrus-a9ef6455aeb2430d6cba30f854c0a101bd7e0cf3.zip
342163: [Usability] Papyrus merge should use the service edit of Papyrus
https://bugs.eclipse.org/bugs/show_bug.cgi?id=342163 A save of my work
Diffstat (limited to 'sandbox/UMLCompareMergerExample')
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CReferenceOrderChangeMerger.java174
1 files changed, 129 insertions, 45 deletions
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
index b077a0872b0..dceacce5484 100644
--- 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
@@ -1,76 +1,160 @@
+/*****************************************************************************
+ * 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.compare.EMFComparePlugin;
+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.compare.util.EFactory;
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 {
+public class CReferenceOrderChangeMerger extends ReferenceOrderChangeMerger implements ICommandMerger {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.diff.merge.IMerger#applyInOrigin()
+ */
@Override
- public void doUndoInTarget() {
+ public void applyInOrigin() {
if(MergerUtils.usePapyrusMerger()) {
- 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(EObject input) {
- return !input.eIsProxy()
- || !DefaultMerger.isEMFCompareProxy(((InternalEObject)input).eProxyURI());
- }
- }));
-
- TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
-// try {
-// EFactory.eSet(rightElement, theDiff.getReference().getName(), target);
-
- Command command = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, rightElement, theDiff.getReference(), target);
- domain.getCommandStack().execute(command );
-// } catch (final FactoryException e) {
-// EMFComparePlugin.log(e, true);
-// }
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getApplyInOriginCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
} else {
- super.doUndoInTarget();
+ super.applyInOrigin();
}
}
@Override
- public void doApplyInOrigin() {
+ public void undoInTarget() {
if(MergerUtils.usePapyrusMerger()) {
- 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(EObject input) {
- return !input.eIsProxy()
- || !DefaultMerger.isEMFCompareProxy(((InternalEObject)input).eProxyURI());
- }
- }));
- TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
-// try {
-// EFactory.eSet(leftElement, theDiff.getReference().getName(), target);
- Command command = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, leftElement, theDiff.getReference(), target);
- domain.getCommandStack().execute(command );
-// } catch (final FactoryException e) {
-// EMFComparePlugin.log(e, true);
-// }
+ final TransactionalEditingDomain domain = MergerUtils.getEditingDomain();
+ final Command cmd = getUndoInTargetCommand(domain);
+ if(cmd.canExecute()) {
+ domain.getCommandStack().execute(cmd);
+ }
} else {
- super.doApplyInOrigin();
+ 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;
+ }
+ });
+ }
}

Back to the top