Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/CDiffGroupMerger.java')
-rw-r--r--sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/CDiffGroupMerger.java122
1 files changed, 122 insertions, 0 deletions
diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/CDiffGroupMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/CDiffGroupMerger.java
new file mode 100644
index 00000000000..bf0b3c89490
--- /dev/null
+++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/CDiffGroupMerger.java
@@ -0,0 +1,122 @@
+/*****************************************************************************
+ * 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.internal.merger;
+
+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.internal.utils.MergerUtils;
+import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger;
+
+
+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;
+ }
+ });
+ }
+}

Back to the top