From 1f192e4c741e1d68e1b8957269ac633fc6ea87ba Mon Sep 17 00:00:00 2001 From: vlorenzo Date: Mon, 7 May 2012 15:03:57 +0000 Subject: 378689: [Releng] Add EMF-Compare projects to releng https://bugs.eclipse.org/bugs/show_bug.cgi?id=378689 --- .../.classpath | 7 - .../.project | 28 -- .../.settings/org.eclipse.jdt.core.prefs | 7 - .../META-INF/MANIFEST.MF | 23 -- .../about.html | 28 -- .../build.properties | 10 - .../plugin.pdoc | 4 - .../plugin.properties | 3 - .../plugin.xml | 13 - .../papyrus/uml/compare/merger/Activator.java | 68 ---- .../commands/AbstractFireMergeCommand.java | 76 ----- .../merger/internal/commands/CopyXMIIDCommand.java | 112 ------- .../internal/commands/FireMergeDiffEndCommand.java | 43 --- .../commands/FireMergeDiffStartCommand.java | 43 --- .../commands/FireMergeOperationEndCommand.java | 52 --- .../commands/FireMergeOperationStartCommand.java | 52 --- ...tributeChangeLeftTargetTransactionalMerger.java | 157 --------- ...ributeChangeRightTargetTransactionalMerger.java | 158 ---------- .../AttributeOrderChangeTransactionalMerger.java | 271 ---------------- .../DefaultExtensionTransactionalMerger.java | 21 -- .../merger/DiffExtensionTransactionalMerger.java | 21 -- .../merger/DiffGroupTransactionalMerger.java | 122 ------- ...ElementChangeLeftTargetTransactionalMerger.java | 208 ------------ ...lementChangeRightTargetTransactionalMerger.java | 205 ------------ .../MoveModelElementTransactionalMerger.java | 214 ------------- ...ferenceChangeLeftTargetTransactionalMerger.java | 227 ------------- ...erenceChangeRightTargetTransactionalMerger.java | 224 ------------- .../ReferenceOrderChangeTransactionalMerger.java | 161 ---------- .../merger/UpdateAttributeTransactionalMerger.java | 146 --------- .../merger/UpdateReferenceTransactionalMerger.java | 178 ----------- .../provider/PapyrusMergeCommandProvider.java | 80 ----- .../internal/provider/PapyrusUMLMergeProvider.java | 83 ----- .../compare/merger/internal/utils/MergerUtils.java | 62 ---- .../internal/utils/MoveWithIndexCommand.java | 256 --------------- .../internal/utils/MoveWithIndexRequest.java | 56 ---- .../utils/PapyrusCompareEObjectCopier.java | 350 --------------------- .../merger/internal/utils/PapyrusEFactory.java | 296 ----------------- .../compare/merger/internal/utils/PapyrusMap.java | 104 ------ .../internal/utils/TransactionalMergeService.java | 311 ------------------ .../compare/merger/utils/ITransactionalMerger.java | 81 ----- .../compare/merger/utils/PapyrusCompareMap.java | 104 ------ 41 files changed, 4665 deletions(-) delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.classpath delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.project delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.settings/org.eclipse.jdt.core.prefs delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/META-INF/MANIFEST.MF delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/about.html delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/build.properties delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.pdoc delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.properties delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.xml delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/Activator.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/AbstractFireMergeCommand.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/CopyXMIIDCommand.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeDiffEndCommand.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeDiffStartCommand.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeOperationEndCommand.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeOperationStartCommand.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeChangeLeftTargetTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeChangeRightTargetTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeOrderChangeTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DefaultExtensionTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DiffExtensionTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DiffGroupTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ModelElementChangeLeftTargetTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ModelElementChangeRightTargetTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/MoveModelElementTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceChangeLeftTargetTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceChangeRightTargetTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceOrderChangeTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/UpdateAttributeTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/UpdateReferenceTransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/provider/PapyrusMergeCommandProvider.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/provider/PapyrusUMLMergeProvider.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/MergerUtils.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/MoveWithIndexCommand.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/MoveWithIndexRequest.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/PapyrusCompareEObjectCopier.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/PapyrusEFactory.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/PapyrusMap.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/TransactionalMergeService.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/ITransactionalMerger.java delete mode 100644 sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusCompareMap.java (limited to 'sandbox/UMLCompareMergerExample') diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.classpath b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.classpath deleted file mode 100644 index 6ee16b50555..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.project b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.project deleted file mode 100644 index 95abdd04718..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.eclipse.papyrus.uml.compare.merger - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.settings/org.eclipse.jdt.core.prefs b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 44217f8c068..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/META-INF/MANIFEST.MF b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/META-INF/MANIFEST.MF deleted file mode 100644 index 11fad835f80..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/META-INF/MANIFEST.MF +++ /dev/null @@ -1,23 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.papyrus.uml.compare.merger;singleton:=true -Bundle-Version: 0.9.0.qualifier -Bundle-Activator: org.eclipse.papyrus.uml.compare.merger.Activator -Require-Bundle: org.eclipse.ui, - org.eclipse.core.runtime, - org.eclipse.emf.compare.diff, - org.eclipse.papyrus.infra.core.log, - org.eclipse.emf.transaction, - org.eclipse.gmf.runtime.emf.type.core, - org.eclipse.papyrus.infra.gmfdiag.commands, - org.eclipse.papyrus.infra.services.edit, - org.eclipse.emf.compare, - org.eclipse.papyrus.infra.tools;bundle-version="0.9.0", - org.eclipse.papyrus.infra.core.sasheditor, - com.google.guava, - org.eclipse.papyrus.infra.emf;bundle-version="0.9.0" -Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Bundle-Vendor: %providerName -Bundle-Localization: plugin diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/about.html b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/about.html deleted file mode 100644 index 82d49bf5f81..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/about.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - -About - - -

About This Content

- -

June 5, 2007

-

License

- -

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at http://www.eclipse.org/legal/epl-v10.html. -For purposes of the EPL, "Program" will mean the Content.

- -

If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at http://www.eclipse.org.

- - - diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/build.properties b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/build.properties deleted file mode 100644 index 2fe142429ae..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/build.properties +++ /dev/null @@ -1,10 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.xml,\ - plugin.pdoc,\ - build.properties,\ - about.html,\ - plugin.properties -src.includes = about.html diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.pdoc b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.pdoc deleted file mode 100644 index 955d3907f13..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.pdoc +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.properties b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.properties deleted file mode 100644 index 64c9548b201..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.properties +++ /dev/null @@ -1,3 +0,0 @@ -#Properties file for org.eclipse.papyrus.uml.compare.merger -providerName = Eclipse Modeling Tools -pluginName = Payrus UML Merger (Incubation) \ No newline at end of file diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.xml b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.xml deleted file mode 100644 index 2b4f97ea3c3..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/plugin.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/Activator.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/Activator.java deleted file mode 100644 index 5ec3a95fadb..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/Activator.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; - -import org.eclipse.papyrus.infra.core.log.LogHelper; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class Activator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.compare.merger"; //$NON-NLS-1$ - - // The shared instance - private static Activator plugin; - - /**the Papyrus log helper*/ - public static LogHelper log; - - /** - * The constructor - */ - public Activator() { - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - log = new LogHelper(this); - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } - -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/AbstractFireMergeCommand.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/AbstractFireMergeCommand.java deleted file mode 100644 index d6891b822c2..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/AbstractFireMergeCommand.java +++ /dev/null @@ -1,76 +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.internal.commands; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.emf.common.command.AbstractCommand; -import org.eclipse.emf.compare.diff.merge.IMergeListener; -import org.eclipse.emf.compare.diff.metamodel.DiffElement; - - -public abstract class AbstractFireMergeCommand extends AbstractCommand { - - /** - * the list of the listeners - */ - private final List listeners; - - /** - * a list of the diff element - */ - private final List diffs; - - private final DiffElement diffElement; - - public AbstractFireMergeCommand(final DiffElement diffElement, final List listeners) { - this.diffElement = diffElement; - this.diffs = Collections.emptyList(); - this.listeners = new ArrayList(listeners); - } - - public AbstractFireMergeCommand(final List diffs, final List listeners) { - this.diffElement = null; - this.diffs = new ArrayList(diffs); - this.listeners = new ArrayList(listeners); - } - - public boolean canRedo() { - return canExecute(); - } - - public List getMergeListeners() { - return Collections.unmodifiableList(listeners); - } - - public List getDiffElementsList() { - return Collections.unmodifiableList(this.diffs); - } - - public DiffElement getDiffElement() { - return this.diffElement; - } - - @Override - protected boolean prepare() { - return true; - } - - public void redo() { - execute(); - - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/CopyXMIIDCommand.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/CopyXMIIDCommand.java deleted file mode 100644 index ac16505bea4..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/CopyXMIIDCommand.java +++ /dev/null @@ -1,112 +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.internal.commands; - -import org.eclipse.emf.common.command.AbstractCommand; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.xmi.XMIResource; -import org.eclipse.papyrus.infra.emf.utils.EMFHelper; - -/** - * - * This command allows to copy the XMI_ID from one EObject to another one, only if they are not owned by the same resource - * - */ -//TODO should be moved in infra.emf plugin when the problem of the saùme resource will be corrected in Papyrus -public class CopyXMIIDCommand extends AbstractCommand { - - /** - * the EObject which provides the XMI_ID - */ - private final EObject source; - - /** - * the EObject which receive the XMI_ID - */ - private final EObject target; - - /** - * the initial XMI_ID of the target - */ - private String initialID; - - /** - * - * Constructor. - * - * @param source - * the EObject which provides the XMI_ID - * @param target - * the EObject which receive the XMI_ID - */ - public CopyXMIIDCommand(final EObject source, final EObject target) { - this.source = source; - this.target = target; - this.initialID = null; - setLabel("Copy XMI_ID command"); //$NON-NLS-1$ - } - - /** - * - * @see org.eclipse.emf.common.command.Command#execute() - * - */ - public void execute() { - final Resource sourceResource = source.eResource(); - final Resource targetResource = target.eResource(); - if(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(this.source); - this.initialID = EMFHelper.getXMIID(target); - ((XMIResource)this.target.eResource()).setID(this.target, xmi_id); - // } - } - } - - /** - * - * @see org.eclipse.emf.common.command.Command#redo() - * - */ - public void redo() { - execute(); - } - - /** - * - * @see org.eclipse.emf.common.command.AbstractCommand#prepare() - * - * @return - */ - @Override - protected boolean prepare() { - return true; - } - - /** - * - * @see org.eclipse.emf.common.command.AbstractCommand#undo() - * - */ - @Override - public void undo() { - final Resource targetResource = target.eResource(); - if(targetResource instanceof XMIResource) { - ((XMIResource)this.target.eResource()).setID(this.target, this.initialID); - } - } - -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeDiffEndCommand.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeDiffEndCommand.java deleted file mode 100644 index ed68eb4a088..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeDiffEndCommand.java +++ /dev/null @@ -1,43 +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.internal.commands; - -import java.util.List; - -import org.eclipse.emf.compare.diff.merge.IMergeListener; -import org.eclipse.emf.compare.diff.merge.MergeEvent; -import org.eclipse.emf.compare.diff.metamodel.DiffElement; - - -public class FireMergeDiffEndCommand extends AbstractFireMergeCommand { - - public FireMergeDiffEndCommand(final DiffElement diffElement, final List listeners) { - super(diffElement, listeners); - } - - public void execute() { - List listeners = getMergeListeners(); - if(getDiffElement() != null) { - for(IMergeListener current : listeners) { - current.mergeDiffStart(new MergeEvent(getDiffElement())); - } - - } - } - - @Override - public void undo() { - //TODO? - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeDiffStartCommand.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeDiffStartCommand.java deleted file mode 100644 index dc0f23f2cf5..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeDiffStartCommand.java +++ /dev/null @@ -1,43 +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.internal.commands; - -import java.util.List; - -import org.eclipse.emf.compare.diff.merge.IMergeListener; -import org.eclipse.emf.compare.diff.merge.MergeEvent; -import org.eclipse.emf.compare.diff.metamodel.DiffElement; - - -public class FireMergeDiffStartCommand extends AbstractFireMergeCommand { - - public FireMergeDiffStartCommand(final DiffElement diffElement, final List listeners) { - super(diffElement, listeners); - } - - public void execute() { - List listeners = getMergeListeners(); - if(getDiffElement() != null) { - for(IMergeListener current : listeners) { - current.mergeDiffEnd(new MergeEvent(getDiffElement())); - } - - } - } - - @Override - public void undo() { - //TODO? - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeOperationEndCommand.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeOperationEndCommand.java deleted file mode 100644 index d8afd27e6f2..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeOperationEndCommand.java +++ /dev/null @@ -1,52 +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.internal.commands; - -import java.util.List; - -import org.eclipse.emf.compare.diff.merge.IMergeListener; -import org.eclipse.emf.compare.diff.merge.MergeEvent; -import org.eclipse.emf.compare.diff.metamodel.DiffElement; - - -public class FireMergeOperationEndCommand extends AbstractFireMergeCommand { - - public FireMergeOperationEndCommand(final DiffElement diffElement, final List listeners) { - super(diffElement, listeners); - } - - public FireMergeOperationEndCommand(final List diffs, final List listeners) { - super(diffs, listeners); - } - - public void execute() { - List listeners = getMergeListeners(); - if(!getDiffElementsList().isEmpty()) { - for(IMergeListener current : listeners) { - current.mergeOperationEnd(new MergeEvent(getDiffElementsList())); - } - } - if(getDiffElement() != null) { - for(IMergeListener current : listeners) { - current.mergeOperationEnd(new MergeEvent(getDiffElement())); - } - - } - } - - @Override - public void undo() { - //TODO? - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeOperationStartCommand.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeOperationStartCommand.java deleted file mode 100644 index 59c39d98ca7..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/commands/FireMergeOperationStartCommand.java +++ /dev/null @@ -1,52 +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.internal.commands; - -import java.util.List; - -import org.eclipse.emf.compare.diff.merge.IMergeListener; -import org.eclipse.emf.compare.diff.merge.MergeEvent; -import org.eclipse.emf.compare.diff.metamodel.DiffElement; - - -public class FireMergeOperationStartCommand extends AbstractFireMergeCommand { - - public FireMergeOperationStartCommand(final DiffElement diffElement, final List listeners) { - super(diffElement, listeners); - } - - public FireMergeOperationStartCommand(final List diffs, final List listeners) { - super(diffs, listeners); - } - - public void execute() { - List listeners = getMergeListeners(); - if(!getDiffElementsList().isEmpty()) { - for(IMergeListener current : listeners) { - current.mergeOperationStart(new MergeEvent(getDiffElementsList())); - } - } - if(getDiffElement() != null) { - for(IMergeListener current : listeners) { - current.mergeOperationStart(new MergeEvent(getDiffElement())); - } - - } - } - - @Override - public void undo() { - //TODO? - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeChangeLeftTargetTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeChangeLeftTargetTransactionalMerger.java deleted file mode 100644 index 2040da3a658..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeChangeLeftTargetTransactionalMerger.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.compare.merger.internal.merger; - -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.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusEFactory; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - - -public class AttributeChangeLeftTargetTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - AttributeChangeLeftTargetTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - AttributeChangeLeftTargetTransactionalMerger.this.postProcess(); - return null; - } - }); - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeChangeRightTargetTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeChangeRightTargetTransactionalMerger.java deleted file mode 100644 index 0ea546b29a2..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeChangeRightTargetTransactionalMerger.java +++ /dev/null @@ -1,158 +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.internal.merger; - -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.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusEFactory; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - - -public class AttributeChangeRightTargetTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - AttributeChangeRightTargetTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - AttributeChangeRightTargetTransactionalMerger.this.postProcess(); - return null; - } - }); - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeOrderChangeTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeOrderChangeTransactionalMerger.java deleted file mode 100644 index b1356710b99..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/AttributeOrderChangeTransactionalMerger.java +++ /dev/null @@ -1,271 +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.internal.merger; - -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.internal.provider.PapyrusMergeCommandProvider; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - - -public class AttributeOrderChangeTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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 leftList = (List)leftElement.eGet(attribute); - final List rightList = (List)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 leftCopy = new ArrayList(leftList); - final List result = new ArrayList(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 leftList = (List)leftElement.eGet(attribute); - final List rightList = (List)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 rightCopy = new ArrayList(rightList); - final List result = new ArrayList(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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - AttributeOrderChangeTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - AttributeOrderChangeTransactionalMerger.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 - * true 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); //$NON-NLS-1$ - } 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/compare/merger/internal/merger/DefaultExtensionTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DefaultExtensionTransactionalMerger.java deleted file mode 100644 index b75ac6aa5f8..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DefaultExtensionTransactionalMerger.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.compare.merger.internal.merger; - -import org.eclipse.emf.compare.diff.merge.DefaultExtensionMerger; - - -public class DefaultExtensionTransactionalMerger extends DefaultExtensionMerger { - //TODO -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DiffExtensionTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DiffExtensionTransactionalMerger.java deleted file mode 100644 index 938ab66019d..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DiffExtensionTransactionalMerger.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.compare.merger.internal.merger; - -import org.eclipse.emf.compare.diff.internal.merge.impl.DiffExtensionMerger; - - -public class DiffExtensionTransactionalMerger extends DiffExtensionMerger { - //TODO ? -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DiffGroupTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DiffGroupTransactionalMerger.java deleted file mode 100644 index 41ebd7fcdde..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/DiffGroupTransactionalMerger.java +++ /dev/null @@ -1,122 +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.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 DiffGroupTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - } - - public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) { - throw new UnsupportedOperationException("Not yet supported"); //$NON-NLS-1$ - } - - 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - DiffGroupTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - DiffGroupTransactionalMerger.this.postProcess(); - return null; - } - }); - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ModelElementChangeLeftTargetTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ModelElementChangeLeftTargetTransactionalMerger.java deleted file mode 100644 index 921ffedde53..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ModelElementChangeLeftTargetTransactionalMerger.java +++ /dev/null @@ -1,208 +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.internal.merger; - -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.infra.emf.commands.AddToResourceCommand; -import org.eclipse.papyrus.uml.compare.merger.Activator; -import org.eclipse.papyrus.uml.compare.merger.internal.commands.CopyXMIIDCommand; -import org.eclipse.papyrus.uml.compare.merger.internal.provider.PapyrusMergeCommandProvider; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusEFactory; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - -public class ModelElementChangeLeftTargetTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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 listVal = (List)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(new CopyXMIIDCommand(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(new AddToResourceCommand(getDiffModel().getRightRoots().get(0).eResource(), newOne)); - } else if(origin != null) { - // origin.eResource().getContents().add(newOne); - cmd.append(new AddToResourceCommand(origin.eResource(), newOne)); - } else { - // FIXME throw exception : couldn't merge this - } - cmd.append(new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "", null) { //$NON-NLS-1$ - - @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 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 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ModelElementChangeLeftTargetTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ModelElementChangeLeftTargetTransactionalMerger.this.postProcess(); - return null; - } - }); - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ModelElementChangeRightTargetTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ModelElementChangeRightTargetTransactionalMerger.java deleted file mode 100644 index 0ac26c95a87..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ModelElementChangeRightTargetTransactionalMerger.java +++ /dev/null @@ -1,205 +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.internal.merger; - -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.infra.emf.commands.AddToResourceCommand; -import org.eclipse.papyrus.uml.compare.merger.Activator; -import org.eclipse.papyrus.uml.compare.merger.internal.commands.CopyXMIIDCommand; -import org.eclipse.papyrus.uml.compare.merger.internal.provider.PapyrusMergeCommandProvider; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusEFactory; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - - -public class ModelElementChangeRightTargetTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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 listVal = (List)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(new CopyXMIIDCommand(element, newOne)); - } catch (final FactoryException e) { - Activator.log.error(e); - } - } else if(origin == null && getDiffModel().getLeftRoots().size() > 0) { - cmd.append(new AddToResourceCommand(getDiffModel().getLeftRoots().get(0).eResource(), newOne)); - } else if(origin != null) { - cmd.append(new AddToResourceCommand(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 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 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ModelElementChangeRightTargetTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ModelElementChangeRightTargetTransactionalMerger.this.postProcess(); - return null; - } - }); - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/MoveModelElementTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/MoveModelElementTransactionalMerger.java deleted file mode 100644 index 4767fe543e3..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/MoveModelElementTransactionalMerger.java +++ /dev/null @@ -1,214 +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.internal.merger; - -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.internal.provider.PapyrusMergeCommandProvider; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - -/** - * - * Created for EMF-Compare, for MoveModelElementMerger - * - */ -public class MoveModelElementTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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 refRightValueList = (List)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"); //$NON-NLS-1$ - 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 refLeftValueList = (List)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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - MoveModelElementTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - MoveModelElementTransactionalMerger.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) { //$NON-NLS-1$ - - @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/compare/merger/internal/merger/ReferenceChangeLeftTargetTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceChangeLeftTargetTransactionalMerger.java deleted file mode 100644 index 64fc3f3c0c7..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceChangeLeftTargetTransactionalMerger.java +++ /dev/null @@ -1,227 +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.internal.merger; - -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.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusCompareEObjectCopier; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusEFactory; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - - -public class ReferenceChangeLeftTargetTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - final EObject copiedValue = copier.getCopiedValue(leftTarget); - final Iterator 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 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ReferenceChangeLeftTargetTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ReferenceChangeLeftTargetTransactionalMerger.this.postProcess(); - return null; - } - }); - } - - -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceChangeRightTargetTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceChangeRightTargetTransactionalMerger.java deleted file mode 100644 index 23dc77c2690..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceChangeRightTargetTransactionalMerger.java +++ /dev/null @@ -1,224 +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.internal.merger; - -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.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusCompareEObjectCopier; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusEFactory; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - - -public class ReferenceChangeRightTargetTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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) { //$NON-NLS-1$ - - @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 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 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"); //$NON-NLS-1$ - 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 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ReferenceChangeRightTargetTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ReferenceChangeRightTargetTransactionalMerger.this.postProcess(); - return null; - } - }); - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceOrderChangeTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceOrderChangeTransactionalMerger.java deleted file mode 100644 index 31127f77211..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/ReferenceOrderChangeTransactionalMerger.java +++ /dev/null @@ -1,161 +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.internal.merger; - -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.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusEFactory; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; - -public class ReferenceOrderChangeTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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 target = Lists.newArrayList(Collections2.filter(theDiff.getLeftTarget(), new Predicate() { - - 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 target = Lists.newArrayList(Collections2.filter(theDiff.getRightTarget(), new Predicate() { - - 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ReferenceOrderChangeTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - ReferenceOrderChangeTransactionalMerger.this.postProcess(); - return null; - } - }); - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/UpdateAttributeTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/UpdateAttributeTransactionalMerger.java deleted file mode 100644 index b6316e9da0b..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/UpdateAttributeTransactionalMerger.java +++ /dev/null @@ -1,146 +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.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.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.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusEFactory; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - - -public class UpdateAttributeTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - UpdateAttributeTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - UpdateAttributeTransactionalMerger.this.postProcess(); - return null; - } - }); - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/UpdateReferenceTransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/UpdateReferenceTransactionalMerger.java deleted file mode 100644 index 45cdf78407f..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/merger/UpdateReferenceTransactionalMerger.java +++ /dev/null @@ -1,178 +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.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.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.internal.provider.PapyrusMergeCommandProvider; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.MergerUtils; -import org.eclipse.papyrus.uml.compare.merger.internal.utils.PapyrusCompareEObjectCopier; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - - -public class UpdateReferenceTransactionalMerger 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - 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"); //$NON-NLS-1$ - } 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"); //$NON-NLS-1$ - } 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) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - UpdateReferenceTransactionalMerger.this.mergeRequiredDifferences(applyInOrigin); - return null; - } - }); - } - - public Command getPostProcessCommand(final TransactionalEditingDomain domain) { - return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { //$NON-NLS-1$ - - @Override - protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { - UpdateReferenceTransactionalMerger.this.postProcess(); - return null; - } - }); - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/provider/PapyrusMergeCommandProvider.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/provider/PapyrusMergeCommandProvider.java deleted file mode 100644 index 0f59728ea35..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/provider/PapyrusMergeCommandProvider.java +++ /dev/null @@ -1,80 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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.provider; - -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; -import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; -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.services.edit.service.ElementEditServiceUtils; -import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; -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 { - - public static PapyrusMergeCommandProvider INSTANCE = new PapyrusMergeCommandProvider(); - - private PapyrusMergeCommandProvider() { - - } - - public Command getDestroyCommand(final TransactionalEditingDomain domain, final EObject element) { - final IEditCommandRequest request = new DestroyElementRequest(domain, element, false); - return getCommand(element, request); - } - - //TODO elementToEdit and targetContainer are the same - public Command getMoveCommand(final TransactionalEditingDomain domain, final EObject elementToEdit, final EObject targetContainer, final EReference targetFeature, final EObject elementToMove) { - final IEditCommandRequest request = new MoveRequest(domain, targetContainer, targetFeature, elementToMove); - return getCommand(elementToEdit, request); - } - - private Command getCommand(final EObject elementToEdit, final IEditCommandRequest request) { - final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(elementToEdit); - if(request instanceof MoveWithIndexRequest) {//TODO remove this test when the move with index will be in the service edit - return new GMFtoEMFCommandWrapper(new MoveWithIndexCommand((MoveRequest)request)); - } - if(provider != null) { - return new GMFtoEMFCommandWrapper(provider.getEditCommand(request)); - } - return null; - } - - public Command getDestroyReferenceCommand(final TransactionalEditingDomain editingDomain, final EObject container, final EReference containingFeature, final EObject referencedObject, final boolean confirmationRequired) { - final IEditCommandRequest request = new DestroyReferenceRequest(editingDomain, container, containingFeature, referencedObject, confirmationRequired); - return getCommand(container, request); - } - - public Command getSetCommand(final TransactionalEditingDomain domain, final EObject element, final EStructuralFeature feature, final Object value) { - final IEditCommandRequest request = new SetRequest(domain, element, feature, value); - return getCommand(element, request); - } - - - //TODO elementToEdit and targetContainer are the same - public Command getMoveWithIndexCommand(final TransactionalEditingDomain domain, final EObject elementToEdit, final EObject targetContainer, final EReference targetFeature, final EObject elementToMove, final int index, final boolean reorder) { - final IEditCommandRequest request = new MoveWithIndexRequest(domain, targetContainer, targetFeature, elementToMove, index, reorder); - return getCommand(elementToEdit, request); - } - -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/provider/PapyrusUMLMergeProvider.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/provider/PapyrusUMLMergeProvider.java deleted file mode 100644 index b5fb46c6ddc..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/provider/PapyrusUMLMergeProvider.java +++ /dev/null @@ -1,83 +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.internal.provider; - -import java.util.Map; - -import org.eclipse.emf.compare.diff.merge.IMerger; -import org.eclipse.emf.compare.diff.merge.IMergerProvider; -import org.eclipse.emf.compare.diff.metamodel.AttributeChangeLeftTarget; -import org.eclipse.emf.compare.diff.metamodel.AttributeChangeRightTarget; -import org.eclipse.emf.compare.diff.metamodel.AttributeOrderChange; -import org.eclipse.emf.compare.diff.metamodel.DiffElement; -import org.eclipse.emf.compare.diff.metamodel.DiffGroup; -import org.eclipse.emf.compare.diff.metamodel.ModelElementChangeLeftTarget; -import org.eclipse.emf.compare.diff.metamodel.ModelElementChangeRightTarget; -import org.eclipse.emf.compare.diff.metamodel.MoveModelElement; -import org.eclipse.emf.compare.diff.metamodel.ReferenceChangeLeftTarget; -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.AttributeChangeLeftTargetTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.AttributeChangeRightTargetTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.AttributeOrderChangeTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.DiffGroupTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.ModelElementChangeLeftTargetTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.ModelElementChangeRightTargetTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.MoveModelElementTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.ReferenceChangeLeftTargetTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.ReferenceChangeRightTargetTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.ReferenceOrderChangeTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.UpdateAttributeTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.internal.merger.UpdateReferenceTransactionalMerger; -import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusCompareMap; - - -public class PapyrusUMLMergeProvider implements IMergerProvider { - - /** - * This map keeps a bridge between a given {@link DiffElement}'s class and the most accurate merger's - * class for that particular {@link DiffElement}. - */ - private Map, Class> mergerTypes; - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.compare.diff.merge.IMergerProvider#getMergers() - */ - public Map, Class> getMergers() { - if(mergerTypes == null) { - mergerTypes = new PapyrusCompareMap, Class>(); - mergerTypes.put(DiffGroup.class, DiffGroupTransactionalMerger.class); - mergerTypes.put(ModelElementChangeRightTarget.class, ModelElementChangeRightTargetTransactionalMerger.class); - mergerTypes.put(ModelElementChangeLeftTarget.class, ModelElementChangeLeftTargetTransactionalMerger.class); - mergerTypes.put(MoveModelElement.class, MoveModelElementTransactionalMerger.class); - mergerTypes.put(ReferenceChangeRightTarget.class, ReferenceChangeRightTargetTransactionalMerger.class); - mergerTypes.put(ReferenceChangeLeftTarget.class, ReferenceChangeLeftTargetTransactionalMerger.class); - mergerTypes.put(UpdateReference.class, UpdateReferenceTransactionalMerger.class); - mergerTypes.put(AttributeChangeRightTarget.class, AttributeChangeRightTargetTransactionalMerger.class); - mergerTypes.put(AttributeChangeLeftTarget.class, AttributeChangeLeftTargetTransactionalMerger.class); - mergerTypes.put(UpdateAttribute.class, UpdateAttributeTransactionalMerger.class); - mergerTypes.put(ReferenceOrderChange.class, ReferenceOrderChangeTransactionalMerger.class); - mergerTypes.put(AttributeOrderChange.class, AttributeOrderChangeTransactionalMerger.class); - //DiffExtensionMerger : not used for the moment - //DefaultExtensionMerger : not used for the moment - } - return mergerTypes; - } - - -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/MergerUtils.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/MergerUtils.java deleted file mode 100644 index 76aa0ee33d8..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/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.internal.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 - * true 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 null 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/internal/utils/MoveWithIndexCommand.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/MoveWithIndexCommand.java deleted file mode 100644 index 7cda719ebec..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/MoveWithIndexCommand.java +++ /dev/null @@ -1,256 +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.internal.utils; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -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.notify.Adapter; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -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 - 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()) { - reorderList(values); - } - } else { - ((List)value).add(index, element); - if(shouldReorder()) { - reorderList((List)value); - } - } - - } else { - ((Collection)getTargetContainer().eGet(feature)).add(element); - if(shouldReorder()) { - 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 - * true 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; - } - - /** - * 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 object in its list. - */ - private 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 - * type of the list's elements. - */ - private void reorderList(final List list) { - List newList = new ArrayList(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; - } - - /** - * duplicate code from Efactory - * This adapter will be used to remember the accurate position of an EObject in its target list. - * - * @author Laurent Goubet - */ - private static 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; - } - } - - /** - * - * This class allows to compare EObject using the PositionAdapter. - * - * - */ - private static class EObjectComparator implements Comparator { - - /** - * - * @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 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/compare/merger/internal/utils/MoveWithIndexRequest.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/MoveWithIndexRequest.java deleted file mode 100644 index 47a8a1373b4..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/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.internal.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/internal/utils/PapyrusCompareEObjectCopier.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/PapyrusCompareEObjectCopier.java deleted file mode 100644 index 0ce42bf0c21..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/PapyrusCompareEObjectCopier.java +++ /dev/null @@ -1,350 +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.internal.utils; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -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.Adapter; -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.compare.merger.internal.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"); //$NON-NLS-1$ - } - 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)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) { //$NON-NLS-1$ - - @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 it = ((List)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 targetList = (List)referenceValue; - //addAtIndex(targetList, copy, index); - //not tested - cmd = getAddAtIndexCommand(domain, target, targetReference, targetList, copy, index); - } - } else { - final List targetList = (List)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 targetList, final EReference targetReference, final EObject copy, final int currentIndex, final int expectedIndex) { - final List newColl = new ArrayList(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 collection, final EObject newValue, final int index) { - final List newColl = new ArrayList(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 object 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 - * type of the list's elements. - */ - private void reorderList(final List list) { - final List newList = new ArrayList(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 Laurent Goubet - */ - 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; - } - } - - /** - * - * This class allows to compare EObject using the PositionAdapter. - * - * - */ - private class EObjectComparator implements Comparator { - - /** - * - * @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 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/compare/merger/internal/utils/PapyrusEFactory.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/PapyrusEFactory.java deleted file mode 100644 index 85c201ff26a..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/PapyrusEFactory.java +++ /dev/null @@ -1,296 +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.internal.utils; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -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.papyrus.uml.compare.merger.internal.provider.PapyrusMergeCommandProvider; -//TODO : merge with thepapyrus table command factory? -/** - * - * This class is adapted from {@link EFactory} - * - */ -/** - * - * This class is adapted from {@link EFactory} - * - */ -public class PapyrusEFactory { - - - private PapyrusEFactory() { - //nothing to do - } - - public static final 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 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 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 internalEList = (InternalEList)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 list = (List)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)manyValue).add(arg); - // } - - if(manyValue instanceof Collection) { - List newValue = new ArrayList((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); - } - - /** - * 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 object in its list. - */ - private 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 - * type of the list's elements. - */ - private static void reorderList(final List list) { - List newList = new ArrayList(list); - Collections.sort(newList, new EObjectComparator()); - for(int i=0;iLaurent Goubet - */ - private static 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; - } - } - - /** - * - * This class allows to compare EObject using the PositionAdapter. - * - * - */ - private static class EObjectComparator implements Comparator { - - /** - * - * @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 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/compare/merger/internal/utils/PapyrusMap.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/PapyrusMap.java deleted file mode 100644 index dc8db9c169c..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/PapyrusMap.java +++ /dev/null @@ -1,104 +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.internal.utils; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.papyrus.uml.compare.merger.Activator; - -/** - * This map log an error when a wanted element is unknown in the map - * - * @author VL222926 - * - * @param - * @param - */ -public class PapyrusMap extends HashMap { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Constructs an empty HashMap with the specified initial - * capacity and load factor. - * - * @param initialCapacity - * The initial capacity. - * @param loadFactor - * The load factor. - * @throws IllegalArgumentException - * if the initial capacity is negative - * or the load factor is nonpositive. - */ - public PapyrusMap(final int initialCapacity, final float loadFactor) { - super(initialCapacity, loadFactor); - } - - /** - * Constructs an empty HashMap with the specified initial - * capacity and the default load factor (0.75). - * - * @param initialCapacity - * the initial capacity. - * @throws IllegalArgumentException - * if the initial capacity is negative. - */ - public PapyrusMap(final int initialCapacity) { - super(initialCapacity); - } - - /** - * Constructs an empty HashMap with the default initial capacity - * (16) and the default load factor (0.75). - */ - public PapyrusMap() { - super(); - } - - /** - * Constructs a new HashMap with the same mappings as the - * specified Map. The HashMap is created with - * default load factor (0.75) and an initial capacity sufficient to - * hold the mappings in the specified Map. - * - * @param m - * the map whose mappings are to be placed in this map. - * @throws NullPointerException - * if the specified map is null. - */ - public PapyrusMap(final Map m) { - super(m); - } - - /** - * We display an error when a wanted element is not included in the Map - * - * @see java.util.HashMap#get(java.lang.Object) - * - * @param key - * @return - */ - @Override - public V get(final Object key) { - V obj = super.get(key); - if(obj == null) { - Activator.log.error("The following element is unknown in the map : " + key, new NullPointerException()); //$NON-NLS-1$ - } - return obj; - } -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/TransactionalMergeService.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/TransactionalMergeService.java deleted file mode 100644 index 3bbc589bd23..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/internal/utils/TransactionalMergeService.java +++ /dev/null @@ -1,311 +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.internal.utils; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.command.CompoundCommand; -import org.eclipse.emf.compare.diff.merge.IMergeListener; -import org.eclipse.emf.compare.diff.merge.IMerger; -import org.eclipse.emf.compare.diff.merge.service.MergeFactory; -import org.eclipse.emf.compare.diff.merge.service.MergeService; -import org.eclipse.emf.compare.diff.metamodel.ConflictingDiffElement; -import org.eclipse.emf.compare.diff.metamodel.DiffElement; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.osgi.util.NLS; -import org.eclipse.papyrus.infra.tools.util.ReflectHelper; -import org.eclipse.papyrus.uml.compare.merger.Activator; -import org.eclipse.papyrus.uml.compare.merger.internal.commands.FireMergeDiffEndCommand; -import org.eclipse.papyrus.uml.compare.merger.internal.commands.FireMergeDiffStartCommand; -import org.eclipse.papyrus.uml.compare.merger.internal.commands.FireMergeOperationEndCommand; -import org.eclipse.papyrus.uml.compare.merger.internal.commands.FireMergeOperationStartCommand; -import org.eclipse.papyrus.uml.compare.merger.utils.ITransactionalMerger; - -/** - * - * This service should replace the EMF-Compare MergeService - * - */ -//TODO not used -public class TransactionalMergeService { - - private static Method addMergeListenerMethod = null; - - private static Method removeMergeListenerMethod = null; - - // /** This copier will be used when merging references. */ - // private static EMFCompareEObjectCopier copier; - - /** - * Default constructor. - */ - private TransactionalMergeService() { - // hides default constructor - } - - /** - * TODO this method should be covered with a JUnit test - * Registers a new merge listener for notifications about merge operations. Has no effect if the listener - * is already registered. - * - * @param listener - * New Listener to register for notifications. - */ - public static void addMergeListener(final IMergeListener listener) { - if(addMergeListenerMethod == null) { - Class[] parameterTypes = new Class[1]; - parameterTypes[0] = IMergeListener.class; - try { - addMergeListenerMethod = ReflectHelper.getMethod(MergeService.class, "addMergeListener", parameterTypes); //$NON-NLS-1$ - } catch (SecurityException e) { - Activator.log.error(e); - } catch (NoSuchMethodException e) { - Activator.log.error(e); - } - } - final Object[] parameters = new Object[1]; - parameters[0] = listener; - try { - addMergeListenerMethod.invoke(null, parameters); - } catch (IllegalArgumentException e) { - Activator.log.error(e); - } catch (IllegalAccessException e) { - Activator.log.error(e); - } catch (InvocationTargetException e) { - Activator.log.error(e); - } - } - - - // /** - // * Returns the copier given the diff it should merge. - // * - // * @param diff - // * The DiffElement for which a copier is needed. - // * @return The copier for a given diff. - // */ - // public static EMFCompareEObjectCopier getCopier(final DiffElement diff) { - // final DiffModel diffModel = getContainerDiffModel(diff); - // if (diffModel == null) - // throw new IllegalArgumentException("The diff element should be contained in a DiffModel instance"); //$NON-NLS-1$ - // if (diffModel.eContainer() instanceof DiffResourceSet) { - // if (copier == null) { - // copier = new EMFCompareEObjectCopier((DiffResourceSet)diffModel.eContainer()); - // } else if (copier.getDiffResourceSet() != diffModel.eContainer()) { - // copier.clear(); - // copier = new EMFCompareEObjectCopier((DiffResourceSet)diffModel.eContainer()); - // } - // } else { - // if (copier == null) { - // copier = new EMFCompareEObjectCopier(diffModel); - // } else if (copier.getDiffModel() != diffModel) { - // copier.clear(); - // copier = new EMFCompareEObjectCopier(diffModel); - // } - // } - // return copier; - // } - - // /** - // * Browse the diff model from the leaf to the top to find the containing {@link DiffModel} instance. - // * - // * @param diff - // * any {@link DiffElement}. - // * @return the containing {@link DiffModel} instance, null if not found. - // */ - // private static DiffModel getContainerDiffModel(final DiffElement diff) { - // EObject container = diff.eContainer(); - // while (container != null) { - // if (container instanceof DiffModel) - // return (DiffModel)container; - // container = container.eContainer(); - // } - // return null; - // } - - /** - * Merges a single DiffElement in the direction specified by leftToRight. - *

- * Will notify the list of its merge listeners before, and after the operation. - *

- * - * @param element - * {@link DiffElement} containing the information to merge. - * @param leftToRight - * True if the changes must be applied from the left to the right model, False when they have to be applied the - * other way around. - */ - // public static void merge(final DiffElement element, final boolean leftToRight) { - // fireMergeOperationStart(element); - // doMerge(element, leftToRight); - // fireMergeOperationEnd(element); - // } - - public static Command getMergeCommand(final TransactionalEditingDomain domain, final DiffElement element, final boolean leftToRight) { - CompoundCommand cmd = new CompoundCommand("MergeCommand"); //$NON-NLS-1$ - cmd.append(new FireMergeOperationStartCommand(element, getMergeListeners())); - cmd.append(getDoMergeCommand(domain, element, leftToRight)); - cmd.append(new FireMergeOperationEndCommand(element, getMergeListeners())); - return cmd; - } - - /** - * Applies the changes implied by a given {@link DiffElement} in the direction specified by leftToRight. - *

- * Will notify the list of its merge listeners before, and after the merge. - *

- * - * @param element - * {@link DiffElement} containing the information to merge. - * @param leftToRight - * True if the changes must be applied from the left to the right model, False when they have to be applied the - * other way around. - */ - // protected static void doMerge(final DiffElement element, final boolean leftToRight) { - // fireMergeDiffStart(element); - // final IMerger merger; - // if(element instanceof ConflictingDiffElement) - // merger = MergeFactory.createMerger(element.getSubDiffElements().get(0)); - // else - // merger = MergeFactory.createMerger(element); - // if(leftToRight && merger.canUndoInTarget()) { - // merger.undoInTarget(); - // } else if(!leftToRight && merger.canApplyInOrigin()) { - // merger.applyInOrigin(); - // } - // fireMergeDiffEnd(element); - // } - - private static Command getDoMergeCommand(final TransactionalEditingDomain domain, final DiffElement element, final boolean leftToRight) { - final CompoundCommand cmd = new CompoundCommand("DoMergeCommand"); //$NON-NLS-1$ - cmd.append(new FireMergeDiffStartCommand(element, getMergeListeners())); - final IMerger merger; - if(element instanceof ConflictingDiffElement) { - merger = MergeFactory.createMerger(element.getSubDiffElements().get(0)); - } else { - merger = MergeFactory.createMerger(element); - } - if(merger instanceof ITransactionalMerger) { - if(leftToRight && merger.canUndoInTarget()) { - cmd.append(((ITransactionalMerger)merger).getUndoInTargetCommand(domain)); - } else if(!leftToRight && merger.canApplyInOrigin()) { - cmd.append(((ITransactionalMerger)merger).getApplyInOriginCommand(domain)); - } - } else { - throw new UnsupportedOperationException(NLS.bind("I can't found the Papyrus Merger for {0}.", element)); //$NON-NLS-1$ - } - - cmd.append(new FireMergeDiffEndCommand(element, getMergeListeners())); - return cmd; - } - - - // /** - // * Merges a list of DiffElements in the direction specified by leftToRight. - // *

- // * Will notify the list of its merge listeners before, and after the operation. - // *

- // * - // * @param elements - // * {@link DiffElement}s containing the information to merge. - // * @param leftToRight - // * True if the changes must be applied from the left to the right model, False when they have to be applied the - // * other way around. - // */ - // public static void merge(final List elements, final boolean leftToRight) { - // fireMergeOperationStart(elements); - // for(DiffElement element : new ArrayList(elements)) - // // we might remove the diff from the list before merging it - // // (eOpposite reference) - // if(element.eContainer() != null) - // doMerge(element, leftToRight); - // fireMergeOperationEnd(elements); - // } - - public static Command getMergeCommand(final TransactionalEditingDomain domain, final List elements, final boolean leftToRight) { - final CompoundCommand cmd = new CompoundCommand("MergeCommand"); //$NON-NLS-1$ - cmd.append(new FireMergeOperationStartCommand(elements, getMergeListeners())); - for(DiffElement element : new ArrayList(elements)) { - // we might remove the diff from the list before merging it - // (eOpposite reference) - if(element.eContainer() != null) { - cmd.append(getDoMergeCommand(domain, element, leftToRight)); - } - } - cmd.append(new FireMergeOperationEndCommand(elements, getMergeListeners())); - return cmd; - } - - /** - * removes a merge listener from the list of registered listeners. This will have no effect if the given - * listener is not registered for notifications on this service. - * - * @param listener - * New Listener to register for notifications. - */ - public static void removeMergeListener(final IMergeListener listener) { - if(removeMergeListenerMethod == null) { - Class[] parameterTypes = new Class[1]; - parameterTypes[0] = IMergeListener.class; - try { - removeMergeListenerMethod = ReflectHelper.getMethod(MergeService.class, "removeMergeListener", parameterTypes); //$NON-NLS-1$ - } catch (SecurityException e) { - Activator.log.error(e); - } catch (NoSuchMethodException e) { - Activator.log.error(e); - } - } - final Object[] parameters = new Object[1]; - parameters[0] = listener; - try { - removeMergeListenerMethod.invoke(null, parameters); - } catch (IllegalArgumentException e) { - Activator.log.error(e); - } catch (IllegalAccessException e) { - Activator.log.error(e); - } catch (InvocationTargetException e) { - Activator.log.error(e); - } - } - - - @SuppressWarnings("unchecked") - //we suppress this warning because the field is always a List of IMergeListener - private static List getMergeListeners() { - List listeners = null; - Field myField = null; - try { - myField = MergeService.class.getDeclaredField("MERGE_LISTENERS"); //$NON-NLS-1$ - } catch (SecurityException e) { - Activator.log.error(e); - } catch (NoSuchFieldException e) { - Activator.log.error(e); - } - myField.setAccessible(true); - try { - listeners = (List)myField.get(null); - } catch (IllegalArgumentException e) { - Activator.log.error(e); - } catch (IllegalAccessException e) { - Activator.log.error(e); - } - return listeners; - } - -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/ITransactionalMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/ITransactionalMerger.java deleted file mode 100644 index eaaf5f44ec2..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/ITransactionalMerger.java +++ /dev/null @@ -1,81 +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.command.Command; -import org.eclipse.emf.compare.diff.merge.DefaultMerger; -import org.eclipse.emf.compare.diff.merge.IMerger; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -; - -/** - * - * The mergers which implement this interface are able to provide commands for the merge actions - * TODO : rename into ITransactionalMerger - */ -public interface ITransactionalMerger extends IMerger { - - /** - * This command should have the same behavior as {@link DefaultMerger#applyInOrigin()} - * - * @return - * the command to do the action - */ - public Command getApplyInOriginCommand(final TransactionalEditingDomain domain); - - /** - * This command should have the same behavior as {@link DefaultMerger#undoInTarget()} - * - * @param domain - * @return - * the command to do the action - */ - public Command getUndoInTargetCommand(final TransactionalEditingDomain domain); - - /** - * This command should have the same behavior as {@link DefaultMerger#doApplyInOrigin} - * - * @param domain - * @return - * the command to do the action - */ - public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain); - - /** - * This command should have the same behavior as {@link DefaultMerger#doUndoInTarget} - * - * @param domain - * @return - * the command to do the action - */ - public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain); - - /** - * This command should have the same behavior as {@link DefaultMerger#mergeRequiredDifferences} - * - * @param domain - * @param applyInOrigin - * @return - * the command to do the action - */ - public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin); - - /** - * This command should have the same behavior as {@link DefaultMerger#postProcess} - * - * @param domain - * @return - * the command to do the action - */ - public Command getPostProcessCommand(final TransactionalEditingDomain domain); - -} diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusCompareMap.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusCompareMap.java deleted file mode 100644 index 281e1ed927d..00000000000 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/compare/merger/utils/PapyrusCompareMap.java +++ /dev/null @@ -1,104 +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.HashMap; -import java.util.Map; - -import org.eclipse.papyrus.uml.compare.merger.Activator; - -/** - * This map log an error when a wanted element is unknown in the map - * - * @author VL222926 - * - * @param - * @param - */ -public class PapyrusCompareMap extends HashMap { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Constructs an empty HashMap with the specified initial - * capacity and load factor. - * - * @param initialCapacity - * The initial capacity. - * @param loadFactor - * The load factor. - * @throws IllegalArgumentException - * if the initial capacity is negative - * or the load factor is nonpositive. - */ - public PapyrusCompareMap(final int initialCapacity, final float loadFactor) { - super(initialCapacity, loadFactor); - } - - /** - * Constructs an empty HashMap with the specified initial - * capacity and the default load factor (0.75). - * - * @param initialCapacity - * the initial capacity. - * @throws IllegalArgumentException - * if the initial capacity is negative. - */ - public PapyrusCompareMap(final int initialCapacity) { - super(initialCapacity); - } - - /** - * Constructs an empty HashMap with the default initial capacity - * (16) and the default load factor (0.75). - */ - public PapyrusCompareMap() { - super(); - } - - /** - * Constructs a new HashMap with the same mappings as the - * specified Map. The HashMap is created with - * default load factor (0.75) and an initial capacity sufficient to - * hold the mappings in the specified Map. - * - * @param m - * the map whose mappings are to be placed in this map. - * @throws NullPointerException - * if the specified map is null. - */ - public PapyrusCompareMap(final Map m) { - super(m); - } - - /** - * We display an error when a wanted element is not included in the Map - * - * @see java.util.HashMap#get(java.lang.Object) - * - * @param key - * @return - */ - @Override - public V get(final Object key) { - V obj = super.get(key); - if(obj == null) { - Activator.log.error("The following element is unknown in the map : " + key, new NullPointerException()); //$NON-NLS-1$ - } - return obj; - } -} -- cgit v1.2.3