From 8135688d9519dbfe224499dbc7a32892f769980f Mon Sep 17 00:00:00 2001 From: vlorenzo Date: Mon, 30 Apr 2012 09:45:16 +0000 Subject: 342163: [Usability] Papyrus merge should use the service edit of Papyrus https://bugs.eclipse.org/bugs/show_bug.cgi?id=342163 A save of my work --- .../merger/provider/CUpdateAttributeMerger.java | 143 ++++++++++++++++----- 1 file changed, 109 insertions(+), 34 deletions(-) (limited to 'sandbox') diff --git a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateAttributeMerger.java b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateAttributeMerger.java index cb386170b74..a5076286e1d 100644 --- a/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateAttributeMerger.java +++ b/sandbox/UMLCompareMergerExample/org.eclipse.papyrus.uml.compare.merger/src/org/eclipse/papyrus/uml/merger/provider/CUpdateAttributeMerger.java @@ -1,70 +1,145 @@ +/***************************************************************************** + * Copyright (c) 2012 CEA LIST. + * + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation + * + *****************************************************************************/ package org.eclipse.papyrus.uml.merger.provider; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; import org.eclipse.emf.compare.FactoryException; import org.eclipse.emf.compare.diff.internal.merge.impl.UpdateAttributeMerger; import org.eclipse.emf.compare.diff.metamodel.UpdateAttribute; -import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.compare.util.EFactory; +import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; import org.eclipse.papyrus.uml.compare.merger.Activator; import org.eclipse.papyrus.uml.compare.merger.utils.MergerUtils; +import org.eclipse.papyrus.uml.compare.merger.utils.PapyrusEFactory; -public class CUpdateAttributeMerger extends UpdateAttributeMerger { +public class CUpdateAttributeMerger extends UpdateAttributeMerger implements ICommandMerger { /** * {@inheritDoc} * - * @see org.eclipse.emf.compare.diff.merge.api.AbstractMerger#doApplyInOrigin() + * @see org.eclipse.emf.compare.diff.merge.IMerger#applyInOrigin() */ @Override - public void doApplyInOrigin() { + public void applyInOrigin() { if(MergerUtils.usePapyrusMerger()) { final TransactionalEditingDomain domain = MergerUtils.getEditingDomain(); - final UpdateAttribute theDiff = (UpdateAttribute)this.diff; - final EObject element = theDiff.getRightElement(); - final EObject origin = theDiff.getLeftElement(); - final EAttribute attr = theDiff.getAttribute(); - - Command cmd = null; - try { - cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, origin, origin.eClass().getEStructuralFeature(attr.getName()), EFactory.eGet(element, attr.getName())); - } catch (final FactoryException e) { - Activator.log.error(e); + final Command cmd = getApplyInOriginCommand(domain); + if(cmd.canExecute()) { + domain.getCommandStack().execute(cmd); } - domain.getCommandStack().execute(cmd); } else { - super.doApplyInOrigin(); + super.applyInOrigin(); } } - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.compare.diff.merge.api.AbstractMerger#doUndoInTarget() - */ @Override - public void doUndoInTarget() { + public void undoInTarget() { if(MergerUtils.usePapyrusMerger()) { final TransactionalEditingDomain domain = MergerUtils.getEditingDomain(); - final UpdateAttribute theDiff = (UpdateAttribute)this.diff; - final EObject element = theDiff.getRightElement(); - final EObject origin = theDiff.getLeftElement(); - final EAttribute attr = theDiff.getAttribute(); - Command cmd = null; - try { - cmd = PapyrusMergeCommandProvider.INSTANCE.getSetCommand(domain, element, element.eClass().getEStructuralFeature(attr.getName()), EFactory.eGet(origin, attr.getName())); - } catch (final FactoryException e) { - Activator.log.error(e); + final Command cmd = getUndoInTargetCommand(domain); + if(cmd.canExecute()) { + domain.getCommandStack().execute(cmd); } - domain.getCommandStack().execute(cmd); } else { - super.doUndoInTarget(); + super.undoInTarget(); + } + } + + + public Command getApplyInOriginCommand(final TransactionalEditingDomain domain) { + // mergeRequiredDifferences(true); + // doApplyInOrigin(); + // postProcess(); + CompoundCommand cmd = new CompoundCommand("Apply in Origin Command for CUpdateAttributeMerger"); + cmd.append(getMergeRequiredDifferencesCommand(domain, true)); + cmd.append(getDoApplyInOriginCommand(domain)); + cmd.append(getPostProcessCommand(domain)); + return cmd; + } + + public Command getUndoInTargetCommand(final TransactionalEditingDomain domain) { + // mergeRequiredDifferences(false); + // doUndoInTarget(); + // postProcess(); + + CompoundCommand cmd = new CompoundCommand("Undo In Target Command for CUpdateAttributeMerger"); + cmd.append(getMergeRequiredDifferencesCommand(domain, false)); + cmd.append(getDoUndoInTargetCommand(domain)); + cmd.append(getPostProcessCommand(domain)); + return cmd; + } + + public Command getDoApplyInOriginCommand(final TransactionalEditingDomain domain) { + Command cmd = null; + final UpdateAttribute theDiff = (UpdateAttribute)this.diff; + final EObject element = theDiff.getRightElement(); + final EObject origin = theDiff.getLeftElement(); + final EAttribute attr = theDiff.getAttribute(); + try { + cmd = PapyrusEFactory.getESetCommand(domain, origin, attr.getName(), EFactory.eGet(element, attr.getName())); + } catch (FactoryException e) { + Activator.log.error(e); } + return cmd; + } + + public Command getDoUndoInTargetCommand(final TransactionalEditingDomain domain) { + Command cmd = null; + final UpdateAttribute theDiff = (UpdateAttribute)this.diff; + final EObject element = theDiff.getRightElement(); + final EObject origin = theDiff.getLeftElement(); + final EAttribute attr = theDiff.getAttribute(); + try { + cmd = PapyrusEFactory.getESetCommand(domain, element, attr.getName(), EFactory.eGet(origin, attr.getName())); + } catch (FactoryException e) { + Activator.log.error(e); + } + return cmd; + } + + public Command getMergeRequiredDifferencesCommand(final TransactionalEditingDomain domain, final boolean applyInOrigin) { + // TODO the super method mergeRequiredDifferences should be rewritten to use cmd too + return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { + + @Override + protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + CUpdateAttributeMerger.this.mergeRequiredDifferences(applyInOrigin); + return null; + } + }); + } + + public Command getPostProcessCommand(final TransactionalEditingDomain domain) { + return new GMFtoEMFCommandWrapper(new AbstractTransactionalCommand(domain, "Merge Required Differences", null) { + + @Override + protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + CUpdateAttributeMerger.this.postProcess(); + return null; + } + }); } - } -- cgit v1.2.3