summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-02-28 07:23:37 (EST)
committerVincent Lorenzo2014-03-18 10:00:40 (EDT)
commitab2f48a1904a94c25bd910354920ee5717148820 (patch)
tree64715b3cd41279e9dacf2fcc258662f80c1f0b52
parent38987f2559764e1f12b9c9edc60213665502c78a (diff)
downloadorg.eclipse.papyrus-ab2f48a1904a94c25bd910354920ee5717148820.zip
org.eclipse.papyrus-ab2f48a1904a94c25bd910354920ee5717148820.tar.gz
org.eclipse.papyrus-ab2f48a1904a94c25bd910354920ee5717148820.tar.bz2
[Usability] Papyrus shall provide a copy/paste/cut feature
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr> Conflicts: plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java90
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java104
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java129
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java153
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/IStrategyManager.java61
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyManager.java21
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/IPasteStrategy.java50
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/GraphicalCommandHandler.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelCommandHandler.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ImportResourcePasteStrategy.java105
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java176
14 files changed, 880 insertions, 18 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
index 1088779..3c0e984 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
@@ -17,6 +17,7 @@ Export-Package: org.eclipse.papyrus.infra.gmfdiag.common,
org.eclipse.papyrus.infra.gmfdiag.common.providers,
org.eclipse.papyrus.infra.gmfdiag.common.service.shape,
org.eclipse.papyrus.infra.gmfdiag.common.snap,
+ org.eclipse.papyrus.infra.gmfdiag.common.strategy,
org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy,
org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste,
org.eclipse.papyrus.infra.gmfdiag.common.types,
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java
new file mode 100644
index 0000000..e550c85
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.AbstractCommand.NonDirtying;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.command.AbstractOverrideableCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+
+/**
+ * Command that puts a list of object in the clipboard, and that copy them.
+ */
+public class DefaultCopyCommand extends AbstractOverrideableCommand implements NonDirtying {
+
+ /** list of objects to put in the clipboard */
+ private final Collection<Object> objectsToPutInClipboard;
+
+ public Collection<Object> getObjectsToPutInClipboard() {
+ return objectsToPutInClipboard;
+ }
+
+ /** old list of the clipboard, for undo */
+ private Collection<Object> oldClipboardContent;
+
+ /**
+ * Creates a new Command that set the new content of the clipboard
+ *
+ * @param domain
+ * editing domain for which the clipboard is set.
+ */
+ public DefaultCopyCommand(EditingDomain domain, PapyrusClipboard papyrusClipboard, Collection<EObject> pObjectsToPutInClipboard) {
+ super(domain);
+ objectsToPutInClipboard = new ArrayList<Object>();
+ for(EObject element : pObjectsToPutInClipboard) {
+ EcoreUtil.Copier copier = new EcoreUtil.Copier();
+ Object copy = copier.copy(element);
+ papyrusClipboard.addInternalCopyInClipboard(element, copy);
+ objectsToPutInClipboard.add(copy);
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doExecute() {
+ oldClipboardContent = domain.getClipboard();
+ domain.setClipboard(objectsToPutInClipboard);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doUndo() {
+ domain.setClipboard(oldClipboardContent);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doRedo() {
+ domain.setClipboard(objectsToPutInClipboard);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean prepare() {
+ return domain != null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
new file mode 100644
index 0000000..5756b1c
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.command.AbstractCommand.NonDirtying;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.command.AbstractOverrideableCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+
+/**
+ * Command that puts a list of object in the clipboard
+ */
+public class DefaultDiagramCopyCommand extends AbstractOverrideableCommand implements NonDirtying {
+
+ /** list of objects to put in the clipboard */
+ private final Collection<Object> objectsToPutInClipboard;
+
+ public Collection<Object> getObjectsToPutInClipboard() {
+ return objectsToPutInClipboard;
+ }
+
+ /** old list of the clipboard, for undo */
+ private Collection<Object> oldClipboardContent;
+
+ /**
+ * Creates a new Command that set the new content of the clipboard
+ *
+ * @param domain
+ * editing domain for which the clipboard is set.
+ */
+ public DefaultDiagramCopyCommand(EditingDomain domain, PapyrusClipboard<Object> papyrusClipboard, Collection<IGraphicalEditPart> pObjectsToPutInClipboard) {
+ super(domain);
+ objectsToPutInClipboard = new ArrayList<Object>();
+ EcoreUtil.Copier copier = new EcoreUtil.Copier();
+ List<EObject> objectToCopy = new ArrayList<EObject>();
+ for(IGraphicalEditPart iGraphicalEditPart : pObjectsToPutInClipboard) {
+ Object object = iGraphicalEditPart.getModel();
+ if(object instanceof View) {
+ View view = (View)object;
+ EObject element = view.getElement();
+ objectToCopy.add(view);
+ objectToCopy.add(element);
+ }
+ copier.copyAll(objectToCopy);
+ copier.copyReferences();
+ for(EObject eObject : objectToCopy) {
+ papyrusClipboard.addInternalCopyInClipboard(eObject, copier.get(eObject));
+ }
+ }
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doExecute() {
+ oldClipboardContent = domain.getClipboard();
+ domain.setClipboard(objectsToPutInClipboard);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doUndo() {
+ domain.setClipboard(oldClipboardContent);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doRedo() {
+ domain.setClipboard(objectsToPutInClipboard);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean prepare() {
+ return domain != null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java
new file mode 100644
index 0000000..783fe43
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java
@@ -0,0 +1,129 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.ArrayList;
+import java.util.Collection;
+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.ecore.EObject;
+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.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
+import org.eclipse.gmf.runtime.notation.Bounds;
+import org.eclipse.gmf.runtime.notation.LayoutConstraint;
+import org.eclipse.gmf.runtime.notation.Shape;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+
+
+/**
+ * this command is used to wrap a copy command. it allows set a new owner for views.
+ */
+public class DefaultDiagramPasteCommand extends AbstractTransactionalCommand {
+
+ //TODO: should be provided configurable in prefs
+ private static final int DEFAULT_AVOID_SUPERPOSITION_Y = 10;
+
+ //TODO: should be provided configurable in prefs
+ private static final int DEFAULT_AVOID_SUPERPOSITION_X = 10;
+
+ /** the new container for the shape */
+ protected View container = null;
+
+ protected List<EObject> semanticList = new ArrayList<EObject>();
+
+ protected List<EObject> viewList = new ArrayList<EObject>();
+
+ protected ICommand editCommand;
+
+
+ /**
+ * Constructor.
+ *
+ * @param editingDomain
+ * @param label
+ * @param eObjectsToBeDuplicated
+ * @param subCommand
+ * @param container
+ */
+ public DefaultDiagramPasteCommand(TransactionalEditingDomain editingDomain, String label, List<Object> eObjectsToBeDuplicated, View container) {
+ super(editingDomain, label, null);
+ this.container = container;
+ EcoreUtil.Copier copier = new EcoreUtil.Copier();
+ copier.copyAll(eObjectsToBeDuplicated);
+ copier.copyReferences();
+ Collection<EObject> values = copier.values();
+ viewList.addAll(values);
+ for(Object eObject : eObjectsToBeDuplicated) {
+ if(!(eObject instanceof View)) {
+ viewList.remove(copier.get(eObject));
+ semanticList.add(copier.get(eObject));
+ }
+ }
+ MoveRequest moveRequest = new MoveRequest(container.getElement(), semanticList);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(container.getElement());
+ if(provider != null) {
+ editCommand = provider.getEditCommand(moveRequest);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ // semantic copy (Move)
+ editCommand.execute(progressMonitor, info);
+ shiftLayout(container, viewList);
+ return editCommand.getCommandResult();
+ }
+
+ /**
+ * Shift the layout of all duplicate Views
+ *
+ * @param values
+ */
+ // TODO : move it in a View utilities class
+ private void shiftLayout(View container, Collection values) {
+ //Collection values = duplicatedObject.values();
+ Iterator iterator = values.iterator();
+ // for each view, a container is set if it is null
+ // if this is a shape a new position is set in order to avoid superposition
+ while(iterator.hasNext()) {
+ Object object = iterator.next();
+ if(object instanceof View) {
+ View duplicatedView = (View)object;
+ if(object instanceof Shape) {
+ LayoutConstraint layoutConstraint = ((Shape)object).getLayoutConstraint();
+ if(layoutConstraint instanceof Bounds) {
+ ((Bounds)layoutConstraint).setX(((Bounds)layoutConstraint).getX() + DEFAULT_AVOID_SUPERPOSITION_X);
+ ((Bounds)layoutConstraint).setY(((Bounds)layoutConstraint).getY() + DEFAULT_AVOID_SUPERPOSITION_Y);
+ }
+ }
+ if(duplicatedView.eContainer() == null && container != null) {
+ ViewUtil.insertChildView(container, duplicatedView, -1, true);
+ }
+ }
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java
new file mode 100644
index 0000000..4d0c805
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java
@@ -0,0 +1,153 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+
+
+/**
+ * this handler has in charge to exexute the paste of UML element with their applied stereotypes
+ *
+ */
+public class DefaultPasteCommand extends AbstractCommand {
+
+ protected EObject targetOwner;
+
+ protected CompositeCommand command;
+
+
+ /**
+ * get the command do the paste on the target owner
+ *
+ * @param domain
+ * the editing owner
+ * @param targetOwner
+ * the element where the paste will be done
+ */
+ public DefaultPasteCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard papyrusClipboard) {
+ super();
+ this.targetOwner = targetOwner;
+ if(papyrusClipboard.size() > 0) {
+ //Filter only EObject
+ List<EObject> eobjectsTopaste = new ArrayList<EObject>();
+ Iterator<Object> iterData = papyrusClipboard.iterator();
+ while(iterData.hasNext()) {
+ Object object = iterData.next();
+ if(object instanceof EObject) {
+ eobjectsTopaste.add((EObject)object);
+ }
+ }
+
+ //Copy all eObjects (inspired from PasteFromClipboardCommand)
+ EcoreUtil.Copier copier = new EcoreUtil.Copier();
+ copier.copyAll(eobjectsTopaste);
+ copier.copyReferences();
+ Map<EObject, EObject> duplicatedObjects = new HashMap<EObject, EObject>();
+ duplicatedObjects.putAll(copier);
+
+
+ // Inform the clipboard of the elment created (used by strategies)
+ papyrusClipboard.addAllInternalToTargetCopy(duplicatedObjects);
+
+ //Prepare the move command to move UML element to their new owner
+ //Nota: move only the "root" semantic elements to be paste
+ List<EObject> objectsToMove = new ArrayList<EObject>();
+ Iterator<EObject> it = eobjectsTopaste.iterator();
+ while(it.hasNext()) {
+ EObject eObject = it.next();
+ EObject copyObject = duplicatedObjects.get(eObject);
+ if(copyObject != null) {
+ objectsToMove.add(copyObject);
+ }
+ }
+
+ MoveRequest moveRequest = new MoveRequest(targetOwner, objectsToMove);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetOwner);
+ if(provider != null) {
+ command = new CompositeCommand("Paste All Object"); //$NON-NLS-1$
+ ICommand editCommand = provider.getEditCommand(moveRequest);
+ command.compose(editCommand);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute() {
+ if(command != null) {
+ try {
+ command.execute(new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean canExecute() {
+ if(command == null) {
+ return false;
+ }
+ return command.canExecute();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void redo() {
+ if(command != null) {
+ try {
+ command.redo(new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void undo() {
+ try {
+ IProgressMonitor monitor = new NullProgressMonitor();
+ command.undo(monitor, null);
+ } catch (ExecutionException e) {
+ Activator.log.error(e);
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/IStrategyManager.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/IStrategyManager.java
index 7865221..66f9c35 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/IStrategyManager.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/IStrategyManager.java
@@ -1,19 +1,80 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.strategy;
import java.util.List;
+
+/**
+ * The Interface IStrategyManager.
+ */
public interface IStrategyManager {
+
+ /**
+ * Checks if the strategy is active.
+ *
+ * @param strategy
+ * the strategy
+ * @return true, if is active
+ */
boolean isActive(IStrategy strategy);
+ /**
+ * Sets the strategy to isActive.
+ *
+ * @param strategy
+ * the strategy
+ * @param isActive
+ * the is active
+ */
void setActive(IStrategy strategy, boolean isActive);
+ /**
+ * Find priority of a strategy
+ *
+ * @param otherStrategy
+ * the other strategy
+ * @return the int
+ */
int findPriority(IStrategy otherStrategy);
+ /**
+ * Sets the priority for a strategy.
+ *
+ * @param strategyToMove
+ * the strategy to move
+ * @param newPriority
+ * the new priority
+ */
void setPriority(IStrategy strategyToMove, int newPriority);
+ /**
+ * Gets the all strategies.
+ *
+ * @return the all strategies
+ */
List<IStrategy> getAllStrategies();
+ /**
+ * Restore defaults.
+ */
void restoreDefaults();
+ /**
+ * Gets all the active strategies.
+ *
+ * @return the active strategies
+ */
+ List<IStrategy> getAllActiveStrategies();
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyManager.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyManager.java
index 47779c8..73a9558 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyManager.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyManager.java
@@ -12,6 +12,7 @@
package org.eclipse.papyrus.infra.gmfdiag.common.strategy;
import java.text.Collator;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -37,9 +38,6 @@ import org.osgi.service.prefs.BackingStoreException;
* Singleton instance. This class is used to read and manage the various
* DropStrategies: activation, order (priority)
*
- *
- * @author Camille Letavernier
- *
*/
public class StrategyManager implements IStrategyManager {
@@ -223,11 +221,11 @@ public class StrategyManager implements IStrategyManager {
}
/**
- * All DropStrategies
* The values are grouped by priority.
*
* (Including the DefaultIStrategy)
*/
+ @Deprecated // remove all ref to priority
public Map<Integer, List<IStrategy>> getAllAvailableStrategies() {
return allAvailableStrategies;
}
@@ -382,5 +380,20 @@ public class StrategyManager implements IStrategyManager {
}
}
+ /**
+ * Return all active strategies
+ */
+ @Override
+ public List<IStrategy> getAllActiveStrategies() {
+ List<IStrategy> res = new ArrayList<IStrategy>();
+ List<IStrategy> allStrategies = getAllStrategies();
+ for (IStrategy iStrategy : allStrategies) {
+ if (isActive(iStrategy)){
+ res.add(iStrategy);
+ }
+ }
+ return res;
+ }
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/IPasteStrategy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/IPasteStrategy.java
index 975a311..4270705 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/IPasteStrategy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/IPasteStrategy.java
@@ -11,18 +11,19 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.IStrategy;
import org.eclipse.swt.graphics.Image;
/**
* A strategy to be applied when pasting elements
*/
-
-// TODO Extract a super interface for merging with drop
-public interface IPasteStrategy extends IStrategy{
+public interface IPasteStrategy extends IStrategy {
/**
* A user-readable label
@@ -43,6 +44,7 @@ public interface IPasteStrategy extends IStrategy{
*
* @return
*/
+ @Deprecated
public Image getImage();
/**
@@ -64,16 +66,50 @@ public interface IPasteStrategy extends IStrategy{
* A command, or null if the strategy cannot handle the request
*/
public Command getCommand(Request request, EditPart targetEditPart);
-
+
/**
* The default priority for this strategy. Might be overridden by a user
* preference.
*
* @return
- * @deprecated The priority mechanism isn't used anymore
+ * @deprecated The priority mechanism should not be used anymore
*/
@Deprecated
public int getPriority();
-
-
+
+ /**
+ * Get the command for the semantic strategy pasting
+ *
+ * @param domain
+ * @param targetOwner
+ * @param papyrusClipboard
+ * @return
+ */
+ public org.eclipse.emf.common.command.Command getSemanticCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard);
+
+ /**
+ * Get the command for the graphical and semantic strategy pasting
+ *
+ * @param domain
+ * @param targetOwner
+ * @param papyrusClipboard
+ * @return
+ */
+ public Command getGraphicalCommand(EditingDomain domain, org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart targetOwner, PapyrusClipboard<Object> papyrusClipboard);
+
+
+ /**
+ * Get the required strategy if one
+ *
+ * @return
+ */
+ public IPasteStrategy dependsOn();
+
+ /**
+ * Prepare in the clipboard the data required for the pasting strategy
+ *
+ * @param papyrusClipboard
+ */
+ public void prepare(PapyrusClipboard<Object> papyrusClipboard);
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
index 1c01988..afd4ff8 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
@@ -35,6 +35,7 @@ Export-Package: org.eclipse.papyrus.uml.diagram.common,
org.eclipse.papyrus.uml.diagram.common.service,
org.eclipse.papyrus.uml.diagram.common.service.palette,
org.eclipse.papyrus.uml.diagram.common.sheet,
+ org.eclipse.papyrus.uml.diagram.common.strategy.paste,
org.eclipse.papyrus.uml.diagram.common.ui.dialogs,
org.eclipse.papyrus.uml.diagram.common.ui.helper,
org.eclipse.papyrus.uml.diagram.common.util,
@@ -93,6 +94,7 @@ Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
org.apache.batik.dom;bundle-version="[1.6.0,1.7.0)",
org.eclipse.core.databinding;bundle-version="1.4.1",
org.eclipse.gmf.tooling.runtime,
+ org.eclipse.papyrus.uml.commands;bundle-version="1.0.0",
org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
org.eclipse.papyrus.infra.core.pluginexplorer;bundle-version="1.0.0",
org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0"
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/GraphicalCommandHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/GraphicalCommandHandler.java
index 229325f..2e418cf 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/GraphicalCommandHandler.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/GraphicalCommandHandler.java
@@ -38,7 +38,9 @@ import org.eclipse.ui.handlers.HandlerUtil;
* calculates the visibility and enablement based on command executability -
* executes the command in Papyrus command stack
*
+ * @deprecated Since February 2014 use org.eclipse.papyrus.infra.gmfdiag.menu.handlers.AbstractGraphicalCommandHandler
*/
+@Deprecated
public abstract class GraphicalCommandHandler extends AbstractHandler {
protected abstract Command getCommand();
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelCommandHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelCommandHandler.java
index 64747a6..8558ec0 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelCommandHandler.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelCommandHandler.java
@@ -25,7 +25,9 @@ import org.eclipse.ui.handlers.HandlerUtil;
*
* @see org.eclipse.core.commands.IHandler
* @see org.eclipse.core.commands.AbstractHandler
+ * @deprecated unused and with the text "Hello, Eclipse world"
*/
+@Deprecated
public class PasteWithModelCommandHandler extends AbstractHandler {
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java
index dc73f95..ab22bb3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java
@@ -35,7 +35,9 @@ import org.eclipse.ui.handlers.HandlerUtil;
*
* @see org.eclipse.core.commands.IHandler
* @see org.eclipse.core.commands.AbstractHandler
+ * @Deprecated seems unused, use org.eclipse.papyrus.uml.diagram.menu.handlers.PasteWithModelHandler
*/
+@Deprecated // seems unused, use org.eclipse.papyrus.uml.diagram.menu.handlers.PasteWithModelHandler
public class PasteWithModelHandler extends AbstractHandler {
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ImportResourcePasteStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ImportResourcePasteStrategy.java
index b22ddaf..f5a3f73 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ImportResourcePasteStrategy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ImportResourcePasteStrategy.java
@@ -8,60 +8,157 @@
*
* Contributors:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.strategy.paste;
import java.util.Map;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.commands.wrappers.GMFtoGEFCommandWrapper;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.DefaultDiagramPasteCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.DefaultPasteCommand;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.swt.graphics.Image;
+
/**
- *
+ * The Class ImportResourcePasteStrategy.
*/
public class ImportResourcePasteStrategy implements IPasteStrategy {
+
+ /** The instance. */
+ private static IPasteStrategy instance = new ImportResourcePasteStrategy();
+
+ /**
+ * Gets the single instance of ImportResourcePasteStrategy.
+ *
+ * @return single instance of ImportResourcePasteStrategy
+ */
+ public static IPasteStrategy getInstance() {
+ return instance;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel()
+ */
public String getLabel() {
return "ImportResourcePasteStrategy"; //$NON-NLS-1$
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID()
+ */
public String getID() {
- return Activator.ID + ".ImportResourcePasteStrategy"; //".ClassifierToStructureCompDrop"; //$NON-NLS-1$
+ return Activator.ID + ".ImportResourcePasteStrategy"; //$NON-NLS-1$
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription()
+ */
public String getDescription() {
return "Import required ressources for paste."; //$NON-NLS-1$
}
+ /**
+ * Gets the category id.
+ *
+ * @return the category id
+ */
public String getCategoryID() {
return "org.eclipse.papyrus.strategy.paste"; //$NON-NLS-1$
}
+ /**
+ * Gets the category label.
+ *
+ * @return the category label
+ */
public String getCategoryLabel() {
return "Paste all copied elements"; //$NON-NLS-1$
- }
-
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getImage()
+ */
public Image getImage() {
return null;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getPriority()
+ */
public int getPriority() {
return 0;
}
+ /**
+ * Sets the options.
+ *
+ * @param options the options
+ */
public void setOptions(Map<String, Object> options) {
//Nothing
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getCommand(org.eclipse.gef.Request, org.eclipse.gef.EditPart)
+ */
@Override
public Command getCommand(Request request, EditPart targetEditPart) {
// TODO Auto-generated method stub
return null;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getSemanticCommand(org.eclipse.emf.edit.domain.EditingDomain, org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public org.eclipse.emf.common.command.Command getSemanticCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard) {
+ // TODO : deport to Default Copy
+
+ DefaultPasteCommand pasteElementCommand = new DefaultPasteCommand(domain, targetOwner, papyrusClipboard);
+ return pasteElementCommand;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
+ */
+ @Override
+ public IPasteStrategy dependsOn() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#prepare(org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public void prepare(PapyrusClipboard<Object> papyrusClipboard) {
+ // TODO Auto-generated method stub
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getGraphicalCommand(org.eclipse.emf.edit.domain.EditingDomain, org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public Command getGraphicalCommand(EditingDomain domain, org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart targetEditPart, PapyrusClipboard<Object> papyrusClipboard) {
+ CompoundCommand compoundCommand = new CompoundCommand("Semantic And Graphical paste"); //$NON-NLS-1$
+ DefaultDiagramPasteCommand defaultDiagramPasteCommand = new DefaultDiagramPasteCommand(targetEditPart.getEditingDomain(), "DefaultGraphicalPasteWithModel", papyrusClipboard, (View)targetEditPart.getModel());
+ GMFtoGEFCommandWrapper gmFtoGEFCommandWrapper = new GMFtoGEFCommandWrapper(defaultDiagramPasteCommand);
+ compoundCommand.add(gmFtoGEFCommandWrapper);
+ return compoundCommand;
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java
index 780129e..f5322fa 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java
@@ -11,59 +11,229 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.strategy.paste;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
+import org.eclipse.papyrus.infra.core.clipboard.IClipboardAdditionalData;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
-import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.TransactionalPasteStrategy;
import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.tools.commands.ApplyStereotypeCommand;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.util.UMLUtil;
/**
- *
+ * Offer a strategy for copying stereotypes.
*/
public class StereotypePasteStrategy implements IPasteStrategy {
+ /** The instance. */
+ private static IPasteStrategy instance = new StereotypePasteStrategy();
+
+ /**
+ * Gets the single instance of StereotypePasteStrategy.
+ *
+ * @return single instance of StereotypePasteStrategy
+ */
+ public static IPasteStrategy getInstance(){
+ return instance;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel()
+ */
public String getLabel() {
return "StereotypeStrategy"; //$NON-NLS-1$
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID()
+ */
public String getID() {
return Activator.ID + ".StereotypeStrategy"; //".ClassifierToStructureCompDrop"; //$NON-NLS-1$
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription()
+ */
public String getDescription() {
return "Paste stereotype elements"; //$NON-NLS-1$
}
+ /**
+ * Gets the category id.
+ *
+ * @return the category id
+ */
public String getCategoryID() {
return "org.eclipse.papyrus.strategy.paste"; //$NON-NLS-1$
}
+ /**
+ * Gets the category label.
+ *
+ * @return the category label
+ */
public String getCategoryLabel() {
return "Paste all copied elements"; //$NON-NLS-1$
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getImage()
+ */
+ @Deprecated
public Image getImage() {
return null;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getPriority()
+ */
+ @Deprecated
public int getPriority() {
- return 0;
+ return 1;
}
+ /**
+ * Sets the options.
+ *
+ * @param options the options
+ */
public void setOptions(Map<String, Object> options) {
//Nothing
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getCommand(org.eclipse.gef.Request, org.eclipse.gef.EditPart)
+ */
@Override
public Command getCommand(Request request, EditPart targetEditPart) {
// TODO Auto-generated method stub
return null;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getSemanticCommand(org.eclipse.emf.edit.domain.EditingDomain, org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public org.eclipse.emf.common.command.Command getSemanticCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> p) {
+ CompoundCommand compoundCommand = new CompoundCommand("Copy all stereotypes"); //$NON-NLS-1$
+ for (Iterator<Object> iterator = p.iterator(); iterator.hasNext();) {
+ Object object = (Object) iterator.next();
+ // get target Element
+ EObject target= p.getTragetCopyFromInternalClipboardCopy(object);
+ if (target != null && target instanceof Element){
+ // get affiliate StereotypeClipboard
+ Map<Object, ?> additionalDataMap = p.getAdditionalDataForStrategy(getID());
+ Object additionnalData = additionalDataMap.get(object);
+ if (additionnalData instanceof StereotypeClipboard){
+ StereotypeClipboard stereotypeClipboard = (StereotypeClipboard) additionnalData;
+ Stereotype stereotype = stereotypeClipboard.getStereotype();
+ if (stereotype != null) {
+ // append command to apply stereotype
+ ApplyStereotypeCommand applyStereotypeCommand = new ApplyStereotypeCommand((Element)target, stereotype, (TransactionalEditingDomain) domain);
+ compoundCommand.append(applyStereotypeCommand);
+ }
+ }
+ }
+ }
+ // An empty can't be executed
+ if (compoundCommand.getCommandList().isEmpty()) {
+ return null;
+ }
+ return compoundCommand;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getGraphicalCommand(org.eclipse.emf.edit.domain.EditingDomain, org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public Command getGraphicalCommand(
+ EditingDomain domain,
+ org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart targetOwner,
+ PapyrusClipboard<Object> papyrusClipboard) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
+ */
+ @Override
+ public IPasteStrategy dependsOn() {
+ // TODO Auto-generated method stub
+ return ImportResourcePasteStrategy.getInstance();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#prepare(org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public void prepare(PapyrusClipboard<Object> papyrusClipboard) {
+ for (Iterator<EObject> iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) {
+ EObject eObjectSource = (EObject) iterator.next();
+ if (eObjectSource instanceof Element){
+ Element element = (Element) eObjectSource;
+ EList<EObject> stereotypeApplications = element.getStereotypeApplications();
+ Map<Object,IClipboardAdditionalData> hashMap = new HashMap<Object,IClipboardAdditionalData>();
+ for (EObject stereotypeApplication : stereotypeApplications) { // TODO : manage many stereotypes
+ Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
+ StereotypeClipboard stereotypeClipboard = new StereotypeClipboard(stereotype);
+ Object copy = papyrusClipboard.getCopyFromSource(eObjectSource);
+ hashMap.put(copy, stereotypeClipboard);
+ }
+ papyrusClipboard.pushAdditionalData(getID(), hashMap);
+ }
+ }
+ }
+
+
+
+ // TODO : remove no internal class
+ /**
+ * The Class StereotypeClipboard.
+ */
+ private class StereotypeClipboard implements IClipboardAdditionalData{
+
+ /** The stereotype. */
+ private Stereotype stereotype;
+
+ /**
+ * Gets the stereotype.
+ *
+ * @return the stereotype
+ */
+ public Stereotype getStereotype() {
+ return stereotype;
+ }
+
+ /**
+ * Instantiates a new stereotype clipboard.
+ *
+ * @param pStereotype the stereotype
+ */
+ public StereotypeClipboard(Stereotype pStereotype) {
+ stereotype = pStereotype;
+ }
+
+ }
+
+
+
}