summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-04-25 04:42:52 (EDT)
committerBenoit Maggi2014-05-15 05:38:45 (EDT)
commitf29407a0123ceec8a28e93d2b33c2103d6d979e5 (patch)
tree89aa4f1999a07253238db87f1faf9b4c8eb8d1f8
parent0dece8259523219654efc2b32092fcca4360649d (diff)
downloadorg.eclipse.papyrus-f29407a0123ceec8a28e93d2b33c2103d6d979e5.zip
org.eclipse.papyrus-f29407a0123ceec8a28e93d2b33c2103d6d979e5.tar.gz
org.eclipse.papyrus-f29407a0123ceec8a28e93d2b33c2103d6d979e5.tar.bz2
Bug 405565 -[Papyrus Model Explorer] Papyrus Model Explorer shall enablerefs/changes/43/25543/2
copy/past with views. - Refactor paste strategies to have an AbstractPasteStrategy - Add DiagramPasteStrategy for copy/paste in Model explorer Change-Id: I9286daf8b68d2555cd98d966ee2e215b47f52bb5 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/PapyrusClipboard.java33
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF152
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml9
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java50
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/InsertDiagramCommand.java97
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java40
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java4
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/AbstractPasteStrategy.java113
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/DefaultPasteStrategy.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/DefaultPasteStrategy.java)66
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/DiagramPasteStrategy.java238
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/IPasteStrategy.java5
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/PasteStrategyManager.java2
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java31
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java49
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java5
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/RenamePasteStrategy.java112
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java166
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CopyHandler.java2
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java4
20 files changed, 707 insertions, 474 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/PapyrusClipboard.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/PapyrusClipboard.java
index 2052c6e..8dd843e 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/PapyrusClipboard.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/PapyrusClipboard.java
@@ -33,6 +33,9 @@ public class PapyrusClipboard<E> extends ArrayList<E> {
*/
public static PapyrusClipboard<Object> instance = null;
+ /**
+ * @return singleton of papyrus clipboard
+ */
public static PapyrusClipboard<Object> getInstance() {
if (instance == null) {
instance = new PapyrusClipboard<Object>();
@@ -40,6 +43,10 @@ public class PapyrusClipboard<E> extends ArrayList<E> {
return instance;
}
+ /**
+ * Set instance of papyrus clipboard
+ * @param pInstance
+ */
public static void setInstance(PapyrusClipboard<Object> pInstance) {
instance = pInstance;
}
@@ -84,19 +91,43 @@ public class PapyrusClipboard<E> extends ArrayList<E> {
internalClipboardToTargetCopy = new HashMap<Object, EObject>();
}
+
+ /**
+ * @return true if the clipboard is empty without additional data
+ */
+ public boolean isEmptyWithNoAdditionalData(){
+ return this.isEmpty() && this.getStrategiesAdditionalData().isEmpty();
+ }
+
/**
* Keeps the mapping between the source and the temporary copy in clipboard
* (Can be use for a reference copy strategy)
*/
private Map<EObject, Object> sourceToInternalClipboard = new HashMap<EObject, Object>();
-
/**
+ * Get the mapping for source to internal clipboard
+ * @return
+ */
+ public Map<EObject, Object> getSourceToInternalClipboard() {
+ return sourceToInternalClipboard;
+ }
+
+ /**
* Keeps the mapping between the internal clipboard copy and the target copy
* (Used by paste strategies)
*/
private Map<Object, EObject> internalClipboardToTargetCopy = new HashMap<Object, EObject>();
+
+ /**
+ * Get the mapping for internal copy to target copy
+ * @return
+ */
+ public Map<Object, EObject> getInternalClipboardToTargetCopy() {
+ return internalClipboardToTargetCopy;
+ }
+
/**
* Store all additional data needed for paste stregies application
* key: Strategy id ; Map<E,ClipboardAdditionalData> data for each object
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 d71ef89..704850f 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
@@ -1,76 +1,76 @@
-Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.infra.gmfdiag.common,
- org.eclipse.papyrus.infra.gmfdiag.common.adapter,
- org.eclipse.papyrus.infra.gmfdiag.common.commands,
- org.eclipse.papyrus.infra.gmfdiag.common.commands.requests,
- org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom,
- org.eclipse.papyrus.infra.gmfdiag.common.decoration,
- org.eclipse.papyrus.infra.gmfdiag.common.editpart,
- org.eclipse.papyrus.infra.gmfdiag.common.editpolicies,
- org.eclipse.papyrus.infra.gmfdiag.common.figure.edge,
- org.eclipse.papyrus.infra.gmfdiag.common.figure.node,
- org.eclipse.papyrus.infra.gmfdiag.common.handler,
- org.eclipse.papyrus.infra.gmfdiag.common.helper,
- org.eclipse.papyrus.infra.gmfdiag.common.listener,
- org.eclipse.papyrus.infra.gmfdiag.common.model,
- org.eclipse.papyrus.infra.gmfdiag.common.preferences,
- 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,
- org.eclipse.papyrus.infra.gmfdiag.common.undocontext,
- org.eclipse.papyrus.infra.gmfdiag.common.utils
-Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="2.5.0",
- org.eclipse.emf.ecore.edit;bundle-version="2.5.0",
- org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0";visibility:=reexport,
- org.eclipse.gef;bundle-version="3.7.1";visibility:=reexport,
- org.eclipse.emf.workspace;bundle-version="1.4.0",
- org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0";visibility:=reexport,
- org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.0.0",
- org.eclipse.core.databinding;bundle-version="1.4.1",
- org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
- org.eclipse.ui.ide;bundle-version="3.8.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.0",
- com.google.guava;bundle-version="11.0.0",
- org.eclipse.papyrus.infra.tools;bundle-version="1.0.0",
- org.eclipse.emf.databinding;bundle-version="1.3.0",
- org.eclipse.core.databinding.property;bundle-version="1.4.200",
- org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="1.4.1",
- org.eclipse.core.expressions,
- org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
- org.apache.batik.util;bundle-version="[1.6.0,1.7.0)",
- org.apache.batik.svggen;bundle-version="[1.6.0,1.7.0)",
- org.w3c.dom.svg;bundle-version="1.1.0",
- org.apache.batik.dom.svg;bundle-version="[1.6.0,1.7.0)",
- org.apache.batik.dom;bundle-version="[1.6.0,1.7.0)",
- org.apache.batik.xml;bundle-version="[1.6.0,1.7.0)",
- org.eclipse.gmf.tooling.runtime,
- com.ibm.icu,
- org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0",
- org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.decoration;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.tools;bundle-version="1.0.0"
-Bundle-Vendor: %providerName
-Bundle-ActivationPolicy: lazy
-Bundle-ClassPath: .
-Bundle-Version: 1.0.0.qualifier
-Bundle-Localization: plugin
-Bundle-Name: %pluginName
-Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.common.Activator
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.common;singleto
- n:=true
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-
+Manifest-Version: 1.0
+Export-Package: org.eclipse.papyrus.infra.gmfdiag.common,
+ org.eclipse.papyrus.infra.gmfdiag.common.adapter,
+ org.eclipse.papyrus.infra.gmfdiag.common.commands,
+ org.eclipse.papyrus.infra.gmfdiag.common.commands.requests,
+ org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom,
+ org.eclipse.papyrus.infra.gmfdiag.common.decoration,
+ org.eclipse.papyrus.infra.gmfdiag.common.editpart,
+ org.eclipse.papyrus.infra.gmfdiag.common.editpolicies,
+ org.eclipse.papyrus.infra.gmfdiag.common.figure.edge,
+ org.eclipse.papyrus.infra.gmfdiag.common.figure.node,
+ org.eclipse.papyrus.infra.gmfdiag.common.handler,
+ org.eclipse.papyrus.infra.gmfdiag.common.helper,
+ org.eclipse.papyrus.infra.gmfdiag.common.listener,
+ org.eclipse.papyrus.infra.gmfdiag.common.model,
+ org.eclipse.papyrus.infra.gmfdiag.common.preferences,
+ 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,
+ org.eclipse.papyrus.infra.gmfdiag.common.undocontext,
+ org.eclipse.papyrus.infra.gmfdiag.common.utils
+Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="2.5.0",
+ org.eclipse.emf.ecore.edit;bundle-version="2.5.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0";visibility:=reexport,
+ org.eclipse.gef;bundle-version="3.7.1";visibility:=reexport,
+ org.eclipse.emf.workspace;bundle-version="1.4.0",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0";visibility:=reexport,
+ org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.0.0",
+ org.eclipse.core.databinding;bundle-version="1.4.1",
+ org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
+ org.eclipse.ui.ide;bundle-version="3.8.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.0",
+ com.google.guava;bundle-version="11.0.0",
+ org.eclipse.papyrus.infra.tools;bundle-version="1.0.0",
+ org.eclipse.emf.databinding;bundle-version="1.3.0",
+ org.eclipse.core.databinding.property;bundle-version="1.4.200",
+ org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="1.4.1",
+ org.eclipse.core.expressions,
+ org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
+ org.apache.batik.util;bundle-version="[1.6.0,1.7.0)",
+ org.apache.batik.svggen;bundle-version="[1.6.0,1.7.0)",
+ org.w3c.dom.svg;bundle-version="1.1.0",
+ org.apache.batik.dom.svg;bundle-version="[1.6.0,1.7.0)",
+ org.apache.batik.dom;bundle-version="[1.6.0,1.7.0)",
+ org.apache.batik.xml;bundle-version="[1.6.0,1.7.0)",
+ org.eclipse.gmf.tooling.runtime,
+ com.ibm.icu,
+ org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0",
+ org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.decoration;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.tools;bundle-version="1.0.0"
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-ClassPath: .
+Bundle-Version: 1.0.0.qualifier
+Bundle-Localization: plugin
+Bundle-Name: %pluginName
+Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.common.Activator
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.common;singleto
+ n:=true
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
index 0c421bd..05125a5 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
@@ -289,4 +289,13 @@
class="org.eclipse.papyrus.infra.gmfdiag.common.listener.RollbackNotificationHistoryListener">
</historyListener>
</extension>
+<extension
+ point="org.eclipse.papyrus.infra.gmfdiag.common.pasteStrategy">
+ <strategy
+ strategy="org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.DefaultPasteStrategy">
+ </strategy>
+ <strategy
+ strategy="org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.DiagramPasteStrategy">
+ </strategy>
+</extension>
</plugin>
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
index 560ee8d..1171b15 100644
--- 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
@@ -31,7 +31,6 @@ 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;
-import org.eclipse.uml2.uml.Element;
/**
@@ -61,8 +60,8 @@ public class DefaultPasteCommand extends AbstractCommand {
List<EObject> eobjectsTopaste = new ArrayList<EObject>();
Iterator<Object> iterData = papyrusClipboard.iterator();
while(iterData.hasNext()) {
- Object object = iterData.next();
- if(object instanceof Element) { // TODO : create utility to detec if the element is part of the semantic model
+ Object object = iterData.next();
+ if(object instanceof EObject) {
eobjectsTopaste.add((EObject)object);
}
}
@@ -90,17 +89,29 @@ public class DefaultPasteCommand extends AbstractCommand {
objectsToMove.add(copyObject);
}
}
-
- MoveRequest moveRequest = new MoveRequest(targetOwner, EcoreUtil.filterDescendants(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);
- }
+ List<EObject> rootObjectsToMove = EcoreUtil.filterDescendants(objectsToMove);
+
+ for(EObject eObject : rootObjectsToMove) {
+ MoveRequest moveRequest = new MoveRequest(targetOwner, eObject);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetOwner);
+ if(provider != null) {
+ ICommand editCommand = provider.getEditCommand(moveRequest);
+ if (editCommand.canExecute()){
+ getCommand().compose(editCommand);
+ }
+ }
+ }
}
}
+
+ public CompositeCommand getCommand() {
+ if (command == null){
+ command = new CompositeCommand("Paste All Object"); //$NON-NLS-1$
+ }
+ return command;
+ }
+
/**
* {@inheritDoc}
*/
@@ -119,8 +130,8 @@ public class DefaultPasteCommand extends AbstractCommand {
*/
@Override
public boolean canExecute() {
- if(command == null) {
- return false;
+ if(command == null) { // allow an empty copy for paste with only additional data (Diagram)
+ return true;
}
return command.canExecute();
}
@@ -144,12 +155,13 @@ public class DefaultPasteCommand extends AbstractCommand {
*/
@Override
public void undo() {
- try {
- IProgressMonitor monitor = new NullProgressMonitor();
- command.undo(monitor, null);
- } catch (ExecutionException e) {
- Activator.log.error(e);
+ if (command != null){
+ 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/commands/InsertDiagramCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/InsertDiagramCommand.java
new file mode 100644
index 0000000..26e9ae4
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/InsertDiagramCommand.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * 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 org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+
+
+/**
+ * Insert a diagram with the specified owner and element
+ */
+public class InsertDiagramCommand extends RecordingCommand {
+
+ /** FIXME the domain of Recording command should be accessible */
+ protected TransactionalEditingDomain transactionalEditingDomain;
+
+ /** diagram to be inserted */
+ protected Diagram diagram;
+
+ /** owner of the diagram */
+ protected EObject owner;
+
+ /** element of the diagram */
+ protected EObject element;
+
+
+ /**
+ * Insert a diagram with the specified owner and element
+ *
+ * @param transactionalEditingDomain
+ * @param label
+ * of the command
+ * @param diagram
+ * to be inserted
+ * @param element
+ * of the diagram // FIXME
+ * @param owner
+ * of the diagram
+ */
+ public InsertDiagramCommand(TransactionalEditingDomain transactionalEditingDomain, String label, Diagram diagram, EObject owner) {
+ this(transactionalEditingDomain, label, diagram, owner, null);
+ }
+
+ /**
+ * Insert a diagram with the specified owner and element
+ *
+ * @param transactionalEditingDomain
+ * @param label
+ * of the command
+ * @param diagram
+ * to be inserted
+ * @param element
+ * of the diagram
+ * @param owner
+ * of the diagram
+ */
+ public InsertDiagramCommand(TransactionalEditingDomain transactionalEditingDomain, String label, Diagram diagram, EObject owner, EObject element) {
+ super(transactionalEditingDomain, label);
+ this.transactionalEditingDomain = transactionalEditingDomain; // FIXME the domain of Recording command should be accessible
+ this.diagram = diagram;
+ this.element = element;
+ this.owner = owner;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ */
+ @Override
+ protected void doExecute() {
+ Resource targetResource = NotationUtils.getNotationResourceForDiagram(owner, transactionalEditingDomain);
+ DiagramUtils.setOwner(diagram, owner);
+ if (element != null){
+ diagram.setElement(element);
+ }
+
+ if(targetResource != null) {
+ targetResource.getContents().add(diagram);
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
index 606fa01..c4f9c40 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
@@ -18,7 +18,9 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.core.resource.IModel;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
@@ -26,6 +28,7 @@ import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
@@ -206,5 +209,42 @@ public class NotationUtils {
return null;
}
}
+
+
+ /**
+ * Returns the notation resource where to add the new diagram
+ *
+ * @param eObject
+ * the semantic object linked to the diagram or the diagram itself.
+ * @param domain
+ * the editing domain
+ * @return the resource where the diagram should be added or <code>null</code> if no resource was found
+ *
+ */
+ public static Resource getNotationResourceForDiagram(EObject eObject, TransactionalEditingDomain domain) {
+ Object object = BusinessModelResolver.getInstance().getBusinessModel(eObject);
+ EObject semanticObject;
+ if(!(object instanceof EObject)) {
+ semanticObject = eObject;
+ } else {
+ semanticObject = (EObject)object;
+ }
+
+ Resource containerResource = semanticObject.eResource();
+ if(containerResource == null) {
+ return null;
+ }
+ // retrieve the model set from the container resource
+ ResourceSet resourceSet = containerResource.getResourceSet();
+
+ if(resourceSet instanceof ModelSet) {
+ ModelSet modelSet = (ModelSet)resourceSet;
+ Resource destinationResource = modelSet.getAssociatedResource(semanticObject, NotationModel.NOTATION_FILE_EXTENSION, true);
+ return destinationResource;
+ } else {
+ throw new RuntimeException("Resource Set is not a ModelSet or is null"); //$NON-NLS-1$
+ }
+ }
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java
index 7a70b1c..c28050b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java
@@ -43,7 +43,7 @@ import org.eclipse.swt.widgets.TreeItem;
// TODO : make drag&dropEditor extends it
public class StrategyEditor extends MultipleReferenceEditor {
- private static final String STRATEGIES = "Strategies";
+ private static final String STRATEGIES = "Strategies"; //$NON-NLS-1$
public static final int ACTIVATION_COLUMN = 0;
@@ -61,7 +61,7 @@ public class StrategyEditor extends MultipleReferenceEditor {
IStaticContentProvider provider = new StaticContentProvider(values.toArray());
ColumnViewerToolTipSupport.enableFor(treeViewer, ToolTip.NO_RECREATE);
- setProviders(provider, new StrategyLabelProvider(getStrategyManager()));// FIXME
+ setProviders(provider, new StrategyLabelProvider(getStrategyManager()));
setModelObservable(new StrategyObservableList(values));
TableLayout layout = new TableLayout();
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/AbstractPasteStrategy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/AbstractPasteStrategy.java
new file mode 100644
index 0000000..47adef9
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/AbstractPasteStrategy.java
@@ -0,0 +1,113 @@
+/*****************************************************************************
+ * 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.paste;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * This class offer a default strategy for the graphical paste :
+ * use the semantic command
+ */
+public abstract class AbstractPasteStrategy implements IPasteStrategy {
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel()
+ */
+ @Override
+ public abstract String getLabel() ;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription()
+ */
+ @Override
+ public abstract String getDescription();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID()
+ */
+ @Override
+ public abstract String getID() ;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
+ */
+ @Override
+ public abstract IPasteStrategy dependsOn() ;
+
+
+
+ /* (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 abstract Command getSemanticCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard);
+
+
+
+ /* (non-Javadoc)
+ * By default, if there is no specific graphical command use the semantic one
+ * @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 org.eclipse.gef.commands.Command getGraphicalCommand(EditingDomain domain, GraphicalEditPart targetEditPart, PapyrusClipboard<Object> papyrusClipboard) {
+ if (targetEditPart != null){
+ Object model = targetEditPart.getModel();
+ if (model instanceof View){
+ View view = (View)model;
+ EObject targetOwner = view.getElement();
+ Command semanticCommand = this.getSemanticCommand(domain, targetOwner, papyrusClipboard);
+ if (semanticCommand != null){
+ return new EMFtoGEFCommandWrapper(semanticCommand);
+ }
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#prepare(org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard, java.util.List)
+ */
+ @Override
+ public void prepare(PapyrusClipboard<Object> papyrusClipboard, Collection<EObject> selection) {
+ // by default nothing to prepare
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getImage()
+ */
+ @Override
+ public Image getImage() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getPriority()
+ */
+ @Override
+ public int getPriority() {
+ return 1;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/DefaultPasteStrategy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/DefaultPasteStrategy.java
index 6a6dc34..87327d6 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/DefaultPasteStrategy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/DefaultPasteStrategy.java
@@ -10,9 +10,7 @@
* 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;
+package org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
@@ -20,17 +18,14 @@ import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.papyrus.commands.wrappers.GMFtoGEFCommandWrapper;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
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 DefaultPasteStrategy.
*/
-public class DefaultPasteStrategy implements IPasteStrategy {
+public class DefaultPasteStrategy extends AbstractPasteStrategy implements IPasteStrategy {
/** The instance. */
@@ -67,31 +62,6 @@ public class DefaultPasteStrategy implements IPasteStrategy {
return "Default Paste Strategy"; //$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()
*/
@@ -99,46 +69,30 @@ public class DefaultPasteStrategy implements IPasteStrategy {
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#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) {
- return new DefaultPasteCommand(domain, targetOwner, papyrusClipboard);
- }
-
/* (non-Javadoc)
* @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
*/
@Override
public IPasteStrategy dependsOn() {
return null;
- }
-
+ }
+
/* (non-Javadoc)
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#prepare(org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ * @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 void prepare(PapyrusClipboard<Object> papyrusClipboard) {
+ public org.eclipse.emf.common.command.Command getSemanticCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard) {
+ return new DefaultPasteCommand(domain, targetOwner, papyrusClipboard);
}
-
/* (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,targetEditPart ); //$NON-NLS-1$
+// (View)targetEditPart.getModel()
+ DefaultDiagramPasteCommand defaultDiagramPasteCommand = new DefaultDiagramPasteCommand(targetEditPart.getEditingDomain(), "DefaultDiagramPasteCommand", papyrusClipboard, targetEditPart); //$NON-NLS-1$
GMFtoGEFCommandWrapper gmFtoGEFCommandWrapper = new GMFtoGEFCommandWrapper(defaultDiagramPasteCommand);
compoundCommand.add(gmFtoGEFCommandWrapper);
return compoundCommand;
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/DiagramPasteStrategy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/DiagramPasteStrategy.java
new file mode 100644
index 0000000..d478b8e
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/DiagramPasteStrategy.java
@@ -0,0 +1,238 @@
+/*****************************************************************************
+ * 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.paste;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.core.clipboard.IClipboardAdditionalData;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.DiagramsUtil;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.InsertDiagramCommand;
+
+
+/**
+ * Offer a copy/paste strategy for diagram in model explorer.
+ */
+public class DiagramPasteStrategy extends AbstractPasteStrategy implements IPasteStrategy {
+
+ /** key to store diagrams with no owner */
+ protected static final String DIAGRAM_WITH_NO_OWNER = "DIAGRAM_WITH_NO_OWNER"; //$NON-NLS-1$
+
+ /** The instance. */
+ private static IPasteStrategy instance = new DiagramPasteStrategy();
+
+ /**
+ * Gets the single instance of DiagramPasteStrategy.
+ *
+ * @return single instance of DiagramPasteStrategy
+ */
+ public static IPasteStrategy getInstance() {
+ return instance;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel()
+ */
+ public String getLabel() {
+ return "Diagram Strategy"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID()
+ */
+ public String getID() {
+ return Activator.ID + ".DiagramStrategy"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription()
+ */
+ public String getDescription() {
+ return "Copy Diagrams in model explorer"; //$NON-NLS-1$
+ }
+
+ /*
+ * (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(final EditingDomain domain, final EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard) {
+ CompoundCommand compoundCommand = new CompoundCommand("Copy all Diagrams"); //$NON-NLS-1$
+
+ Map internalClipboardToTargetCopy = papyrusClipboard.getInternalClipboardToTargetCopy();
+ Map<Object, ?> additionalDataMap = papyrusClipboard.getAdditionalDataForStrategy(getID());
+ if(additionalDataMap != null) {
+ Object additionalData = additionalDataMap.get(DIAGRAM_WITH_NO_OWNER);
+ if(additionalData instanceof DiagramClipboardAdditionalData) {
+ DiagramClipboardAdditionalData diagramClipboardAdditionnalData = (DiagramClipboardAdditionalData)additionalData;
+ Collection<Diagram> duplicateDiagrams = diagramClipboardAdditionnalData.getDuplicatedDiagrams(internalClipboardToTargetCopy);
+ for(final Diagram diagram : duplicateDiagrams) {
+ org.eclipse.emf.common.command.Command command = new InsertDiagramCommand((TransactionalEditingDomain)domain, "Insert a diagram with no source owner", diagram, targetOwner); //$NON-NLS-1$
+ compoundCommand.append(command);
+ }
+ }
+
+ for(Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
+ Object object = (Object)iterator.next();
+ // get target Element
+ EObject target = papyrusClipboard.getTragetCopyFromInternalClipboardCopy(object);
+ if(target != null && target instanceof EObject) {
+ // get affiliate additional data
+ additionalData = additionalDataMap.get(object);
+ if(additionalData instanceof DiagramClipboardAdditionalData) {
+ DiagramClipboardAdditionalData diagramClipboardAdditionalData = (DiagramClipboardAdditionalData)additionalData;
+ Collection<Diagram> diagrams = diagramClipboardAdditionalData.getDuplicatedDiagrams(internalClipboardToTargetCopy);
+ // duplicate diagrams
+ for(final Diagram diagram : diagrams) {
+ org.eclipse.emf.common.command.Command command = new InsertDiagramCommand((TransactionalEditingDomain)domain, "InsertDiagramCommand", diagram, target); //$NON-NLS-1$
+ compoundCommand.append(command);
+ }
+ }
+ }
+ }
+ }
+
+ // An empty compound Command can't be executed
+ if(compoundCommand.getCommandList().isEmpty()) {
+ return null;
+ }
+ return compoundCommand;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
+ */
+ @Override
+ public IPasteStrategy dependsOn() {
+ return DefaultPasteStrategy.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, Collection<EObject> selection) {
+ Map<Object, IClipboardAdditionalData> mapCopyToClipboardAdditionalData = new HashMap<Object, IClipboardAdditionalData>();
+ Map sourceToInternalClipboard = papyrusClipboard.getSourceToInternalClipboard();
+ List<Diagram> extractSelectedWithoutOwner = extractDiagramWithoutOwner(selection);
+ if(extractSelectedWithoutOwner != null && !extractSelectedWithoutOwner.isEmpty()) {
+ DiagramClipboardAdditionalData diagramAdditionnalData = new DiagramClipboardAdditionalData(extractSelectedWithoutOwner, sourceToInternalClipboard);
+ mapCopyToClipboardAdditionalData.put(DIAGRAM_WITH_NO_OWNER, diagramAdditionnalData);
+ }
+
+ for(Iterator<EObject> iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) {
+ EObject eObjectSource = iterator.next();
+ ResourceSet resourceSet = eObjectSource.eResource().getResourceSet();
+ List<Diagram> associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(eObjectSource, resourceSet);
+ if(associatedDiagrams != null) {
+ DiagramClipboardAdditionalData diagramAdditionnalData = new DiagramClipboardAdditionalData(associatedDiagrams, sourceToInternalClipboard);
+ Object copy = papyrusClipboard.getCopyFromSource(eObjectSource);
+ mapCopyToClipboardAdditionalData.put(copy, diagramAdditionnalData);
+ }
+
+ }
+ papyrusClipboard.pushAdditionalData(getID(), mapCopyToClipboardAdditionalData);
+ }
+
+
+ /**
+ * Extract Diagram which owner is not in the selection
+ *
+ * @param selection
+ * @return
+ */
+ protected List<Diagram> extractDiagramWithoutOwner(Collection<EObject> selection) {
+ List<Diagram> diagramWithoutOwnerInSelection = new ArrayList<Diagram>();
+ if(selection != null) {
+ for(EObject eObject : selection) {
+ if(eObject instanceof Diagram) {
+ Diagram diagram = (Diagram)eObject;
+ EObject element = diagram.getElement();
+ if(!selection.contains(element)) {
+ diagramWithoutOwnerInSelection.add(diagram);
+ }
+ }
+ }
+ }
+ return diagramWithoutOwnerInSelection;
+ }
+
+
+ protected class DiagramClipboardAdditionalData implements IClipboardAdditionalData {
+
+ /** The diagrams. */
+ protected Collection<Diagram> diagrams;
+
+ /**
+ * @param diagramCopier
+ * @param diagrams
+ */
+ public DiagramClipboardAdditionalData(Collection<Diagram> diagrams, Map<? extends EObject, ? extends EObject> alreadyCopied) {
+ this.diagrams = duplicateDiagrams(diagrams, alreadyCopied);
+ }
+
+ /**
+ * @return
+ */
+ public Collection<Diagram> getDuplicatedDiagrams(Map<? extends EObject, ? extends EObject> alreadyCopied) {
+ return duplicateDiagrams(this.diagrams, alreadyCopied);
+ }
+
+ /**
+ * @param diagrams
+ * to duplicate
+ * @param alreadyCopied
+ * @return duplicated diagrams
+ */
+ protected Collection<Diagram> duplicateDiagrams(Collection<Diagram> diagrams, Map<? extends EObject, ? extends EObject> alreadyCopied) {
+ Collection<Diagram> duplicatedDiagrams = new ArrayList<Diagram>();
+ EcoreUtil.Copier copier = new EcoreUtil.Copier();
+ copier.putAll(alreadyCopied);
+ for(Diagram diagram : diagrams) {
+ copier.copy(diagram);
+ copier.copyReferences();
+ EObject copy = copier.get(diagram);
+ if(copy instanceof Diagram) {
+ duplicatedDiagrams.add((Diagram)copy);
+ }
+ }
+ return duplicatedDiagrams;
+ }
+ }
+
+}
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 0a6f297..3404a4a 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,6 +11,8 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste;
+import java.util.Collection;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gef.commands.Command;
@@ -107,7 +109,8 @@ public interface IPasteStrategy extends IStrategy {
* Prepare in the clipboard the data required for the pasting strategy
*
* @param papyrusClipboard
+ * @param list
*/
- public void prepare(PapyrusClipboard<Object> papyrusClipboard);
+ public void prepare(PapyrusClipboard<Object> papyrusClipboard, Collection<EObject> selection);
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/PasteStrategyManager.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/PasteStrategyManager.java
index ece3ecf..5aa8318 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/PasteStrategyManager.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/paste/PasteStrategyManager.java
@@ -25,7 +25,7 @@ public class PasteStrategyManager extends StrategyManager {
/**
* The paste strategy extension point
*/
- public static final String EXTENSION_ID = Activator.ID + ".pasteStrategy";
+ public static final String EXTENSION_ID = Activator.ID + ".pasteStrategy"; //$NON-NLS-1$
public static final PasteStrategyManager instance = new PasteStrategyManager(EXTENSION_ID);
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java
index a99ea34..28bd859 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java
@@ -15,6 +15,7 @@
package org.eclipse.papyrus.infra.gmfdiag.menu.handlers;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.expressions.IEvaluationContext;
@@ -47,18 +48,17 @@ import org.eclipse.swt.widgets.Text;
*/
public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
+
+
/**
- *
- * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand()
- *
+ * Construct copy command from the selection
+ * @param editingDomain
+ * @param selectedElements
* @return
*/
- @Override
- protected Command getCommand() {
+ public static Command buildCopyCommand(TransactionalEditingDomain editingDomain, Collection<IGraphicalEditPart> selectedElements) {
PapyrusClipboard<Object> papyrusClipboard = PapyrusClipboard.getNewInstance();
- List<IGraphicalEditPart> selectedElements = getSelectedElements();
- TransactionalEditingDomain editingDomain = getEditingDomain();
- // TODO : select copyStrategy
+
Command result;
DefaultDiagramCopyCommand defaultDiagramCopyCommand = new DefaultDiagramCopyCommand(editingDomain, papyrusClipboard, selectedElements);
@@ -83,11 +83,24 @@ public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
List<IStrategy> allStrategies = PasteStrategyManager.getInstance().getAllStrategies();
for(IStrategy iStrategy : allStrategies) {
IPasteStrategy iIPasteStrategy = (IPasteStrategy)iStrategy;
- iIPasteStrategy.prepare(papyrusClipboard);
+ iIPasteStrategy.prepare(papyrusClipboard, null);
}
return result;
}
+
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ return CopyInDiagramHandler.buildCopyCommand(getEditingDomain(), getSelectedElements());
+ }
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java
index 14eab1e..adc49bf 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java
@@ -13,7 +13,6 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.menu.handlers;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -26,21 +25,10 @@ import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.papyrus.commands.util.NonDirtyingUtils;
-import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
-import org.eclipse.papyrus.commands.wrappers.GMFtoGEFCommandWrapper;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.DefaultDiagramCopyCommand;
-import org.eclipse.papyrus.infra.gmfdiag.common.strategy.IStrategy;
-import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
-import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.PasteStrategyManager;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil;
-import org.eclipse.papyrus.infra.gmfdiag.menu.handlers.CopyInDiagramHandler.MyCopyImageCommand;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
@@ -58,7 +46,7 @@ public class CutInDiagramHandler extends AbstractGraphicalCommandHandler {
@Override
protected Command getCommand() {
CompoundCommand cutInDiagramCommand = new CompoundCommand("Cut in Diagram Command"); //$NON-NLS-1$
- Command buildCopy = buildCopyCommand();
+ Command buildCopy = CopyInDiagramHandler.buildCopyCommand(getEditingDomain(), getSelectedElements());
cutInDiagramCommand.add(buildCopy);
Command buildDelete = buildDeleteCommand();
cutInDiagramCommand.add(buildDelete);
@@ -66,41 +54,6 @@ public class CutInDiagramHandler extends AbstractGraphicalCommandHandler {
}
/**
- * Construct a copy command with the cut selection
- * @return the copy command
- */
- protected Command buildCopyCommand() {
- PapyrusClipboard<Object> papyrusClipboard = PapyrusClipboard.getNewInstance();
- List<IGraphicalEditPart> selectedElements = getSelectedElements();
- TransactionalEditingDomain editingDomain = getEditingDomain();
- Command copyCommand;
- DefaultDiagramCopyCommand defaultDiagramCopyCommand = new DefaultDiagramCopyCommand(editingDomain, papyrusClipboard, selectedElements);
- copyCommand = EMFtoGEFCommandWrapper.wrap(defaultDiagramCopyCommand);
- IDiagramWorkbenchPart activeDiagramWorkbenchPart = DiagramEditPartsUtil.getActiveDiagramWorkbenchPart();
- Diagram diagram = activeDiagramWorkbenchPart.getDiagram();
- DiagramEditPart diagramEditPart = activeDiagramWorkbenchPart.getDiagramEditPart();
- List<Object> selectedElementModels = new ArrayList<Object>();
- for(IGraphicalEditPart iGraphicalEditPart : selectedElements) {
- selectedElementModels.add(iGraphicalEditPart.getModel());
- }
- MyCopyImageCommand copyImageCommand = new MyCopyImageCommand("Create image to allow paste on system", diagram, selectedElementModels, diagramEditPart); //$NON-NLS-1$
- if(copyImageCommand.canExecute()) {
- Command gmFtoGEFCommandWrapper = GMFtoGEFCommandWrapper.wrap(copyImageCommand);
- copyCommand = NonDirtyingUtils.chain(copyCommand, gmFtoGEFCommandWrapper);
- } else {
- copyImageCommand.dispose();
- }
-
- List<IStrategy> allStrategies = PasteStrategyManager.getInstance().getAllStrategies();
- for(IStrategy iStrategy : allStrategies) {
- IPasteStrategy iIPasteStrategy = (IPasteStrategy)iStrategy;
- iIPasteStrategy.prepare(papyrusClipboard);
- }
-
- return copyCommand;
- }
-
- /**
* Construct a delete command with the cut selection
* @return the delete command
*/
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java
index d512c06..ccc8fba 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java
@@ -11,6 +11,7 @@
*****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.common.strategy.paste;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -29,12 +30,12 @@ import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
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.DefaultPasteStrategy;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.sysml.blocks.Block;
import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.strategy.paste.DefaultPasteStrategy;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Classifier;
@@ -236,7 +237,7 @@ public class PartPasteStrategy implements IPasteStrategy {
* @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) {
+ public void prepare(PapyrusClipboard<Object> papyrusClipboard, Collection<EObject> selection) {
Map<Object, IClipboardAdditionalData> mapCopyPartData = new HashMap<Object, IClipboardAdditionalData>();
for(Iterator<EObject> iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) {
EObject eObjectSource = iterator.next();
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
index 95fff76..9fccba4 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
@@ -604,9 +604,6 @@
strategy="org.eclipse.papyrus.uml.diagram.common.strategy.paste.StereotypePasteStrategy">
</strategy>
<strategy
- strategy="org.eclipse.papyrus.uml.diagram.common.strategy.paste.DefaultPasteStrategy">
- </strategy>
- <strategy
strategy="org.eclipse.papyrus.uml.diagram.common.strategy.paste.RenamePasteStrategy">
</strategy>
</extension>
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/RenamePasteStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/RenamePasteStrategy.java
index 85cd2c6..7faa23c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/RenamePasteStrategy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/RenamePasteStrategy.java
@@ -13,28 +13,25 @@ package org.eclipse.papyrus.uml.diagram.common.strategy.paste;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.AbstractPasteStrategy;
+import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.DefaultPasteStrategy;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.tools.commands.RenameElementCommand;
import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.NamedElement;
/**
- * Offer a strategy for copying stereotypes.
+ * Offer a strategy for renaming paste root elements.
*/
-public class RenamePasteStrategy implements IPasteStrategy {
+public class RenamePasteStrategy extends AbstractPasteStrategy implements IPasteStrategy {
/** The instance. */
private static IPasteStrategy instance = new RenamePasteStrategy();
@@ -76,54 +73,16 @@ public class RenamePasteStrategy implements IPasteStrategy {
return "Rename 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 1;
- }
-
- /**
- * Sets the options.
- *
- * @param options
- * the options
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
*/
- public void setOptions(Map<String, Object> options) {
- //Nothing
- }
-
+ @Override
+ public IPasteStrategy dependsOn() {
+ return DefaultPasteStrategy.getInstance();
+ }
+
/*
* (non-Javadoc)
*
@@ -152,56 +111,5 @@ public class RenamePasteStrategy implements IPasteStrategy {
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 targetEditPart, PapyrusClipboard<Object> papyrusClipboard) {
- org.eclipse.gef.commands.CompoundCommand compoundCommand = new org.eclipse.gef.commands.CompoundCommand("Stereotype Semantic And Graphical paste"); //$NON-NLS-1$
- View view = (View)targetEditPart.getModel();
- EObject modelTargetOwner = (EObject)view.getElement();
- List<EObject> filterDescendants = EcoreUtil.filterDescendants(papyrusClipboard.getTarget());
- for(Iterator<EObject> iterator = filterDescendants.iterator(); iterator.hasNext();) {
- EObject target = (EObject)iterator.next();
- if(target instanceof NamedElement) {
- NamedElement namedElement = (NamedElement)target;
- if(namedElement.getName() != null) {
- String defaultCopyNameWithIncrement = NamedElementUtil.getDefaultCopyNameWithIncrement(namedElement, modelTargetOwner.eContents());
- RenameElementCommand renameElementCommand = new RenameElementCommand((TransactionalEditingDomain)domain, (NamedElement)target, defaultCopyNameWithIncrement);
- EMFtoGEFCommandWrapper emFtoGEFCommandWrapper = new EMFtoGEFCommandWrapper(renameElementCommand);
- compoundCommand.add(emFtoGEFCommandWrapper);
- }
- }
- }
-
- if(compoundCommand.size() == 0) {// TODO : use unwrap if no use of UnexecutableCommand.INSTANCE
- return null;
- }
- return compoundCommand;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
- */
- @Override
- public IPasteStrategy dependsOn() {
- return DefaultPasteStrategy.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) {
- // Nothing to prepare since the renaming depends of the pasting context
- }
}
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 a234f5c..cf7b6d5 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
@@ -25,20 +25,18 @@ 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.commands.Command;
-import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
import org.eclipse.papyrus.infra.core.clipboard.IClipboardAdditionalData;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.AbstractPasteStrategy;
+import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.DefaultPasteStrategy;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.preferences.IStereotypePasteStrategyPreferenceConstant;
import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
import org.eclipse.papyrus.uml.tools.commands.ApplyStereotypeCommand;
import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Package;
@@ -49,7 +47,7 @@ import org.eclipse.uml2.uml.util.UMLUtil;
/**
* Offer a strategy for copying stereotypes.
*/
-public class StereotypePasteStrategy implements IPasteStrategy {
+public class StereotypePasteStrategy extends AbstractPasteStrategy implements IPasteStrategy {
/** The instance. */
private static IPasteStrategy instance = new StereotypePasteStrategy();
@@ -91,54 +89,16 @@ public class StereotypePasteStrategy implements IPasteStrategy {
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 1;
- }
-
- /**
- * Sets the options.
- *
- * @param options
- * the options
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
*/
- public void setOptions(Map<String, Object> options) {
- //Nothing
- }
-
+ @Override
+ public IPasteStrategy dependsOn() {
+ return DefaultPasteStrategy.getInstance();
+ }
+
/*
* (non-Javadoc)
*
@@ -222,88 +182,6 @@ public class StereotypePasteStrategy implements IPasteStrategy {
}
-
-
-
- /*
- * (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) {
- org.eclipse.gef.commands.CompoundCommand compoundCommand = new org.eclipse.gef.commands.CompoundCommand("Stereotype Semantic And Graphical paste"); //$NON-NLS-1$
- Map<Profile,List<ApplyStereotypeCommand>> missingProfiles = new HashMap<Profile,List<ApplyStereotypeCommand>>();
- View view = (View)targetEditPart.getModel();
- EObject modelTargetOwner = (EObject)view.getElement();
- Package targetPackage = ((Element)modelTargetOwner).getNearestPackage();
- // apply stereotypes
- for(Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
- Object object = (Object)iterator.next();
- // get target Element
- EObject target = papyrusClipboard.getTragetCopyFromInternalClipboardCopy(object);
- if(target != null && target instanceof Element) {
- // get affiliate StereotypeClipboard
- Map<Object, ?> additionalDataMap = papyrusClipboard.getAdditionalDataForStrategy(getID());
- Object additionnalData = additionalDataMap.get(object);
- if(additionnalData instanceof StereotypeClipboard) {
- StereotypeClipboard stereotypeClipboard = (StereotypeClipboard)additionnalData;
- Collection<Stereotype> stereotypes = stereotypeClipboard.getStereotypes();
- for(Stereotype stereotype : stereotypes) {
- // reload the stereotype in the new Contex-ResourceSet (Required because in org.eclipse.uml2.uml.internal.operations.PackageOperations
- // L960 in getProfileApplication the test is using == instead of equals)
- Stereotype stereotypeInTargetContext = EMFHelper.reloadIntoContext(stereotype, modelTargetOwner);
- ApplyStereotypeCommand applyStereotypeCommand = new ApplyStereotypeCommand((Element)target, stereotypeInTargetContext, (TransactionalEditingDomain)domain);
-
- Profile profile = stereotypeInTargetContext.getProfile();
- if (isProfileAppliedRecursive(targetPackage, profile)){
- EMFtoGEFCommandWrapper emFtoGEFCommandWrapper = new EMFtoGEFCommandWrapper(applyStereotypeCommand);
- compoundCommand.add(emFtoGEFCommandWrapper);
- } else { // Profile is missing
- List<ApplyStereotypeCommand> stereotypeListMissingProfiles = missingProfiles.get(profile);
- if (stereotypeListMissingProfiles!= null && !stereotypeListMissingProfiles.isEmpty()){
- stereotypeListMissingProfiles.add(applyStereotypeCommand);
- } else {
- stereotypeListMissingProfiles = new ArrayList<ApplyStereotypeCommand>();
- stereotypeListMissingProfiles.add(applyStereotypeCommand);
- missingProfiles.put(profile, stereotypeListMissingProfiles);
- }
- }
- }
-
- }
- }
- }
-
- // 2. user preferences (Apply profiles, data...)
- IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
- String preferenceProfileStrategy = preferenceStore.getString(IStereotypePasteStrategyPreferenceConstant.PROFILE_STRATEGY);
-
- if (IStereotypePasteStrategyPreferenceConstant.ASK_POPUP.equals(preferenceProfileStrategy)){// Ask user for instruction
- // TODO: 2. user choices (Apply profiles, data...)
- } else if (IStereotypePasteStrategyPreferenceConstant.IMPORT_MISSING_PROFILE.equals(preferenceProfileStrategy)){ // apply profile
- Set<Profile> keySet = missingProfiles.keySet();
- Package rootPackage = PackageUtil.getRootPackage((Element)modelTargetOwner);
- ApplyProfileCommand applyProfileCommand = new ApplyProfileCommand(rootPackage, keySet, (TransactionalEditingDomain)domain);
- EMFtoGEFCommandWrapper emFtoGEFCommandWrapper = new EMFtoGEFCommandWrapper(applyProfileCommand);
- compoundCommand.add(emFtoGEFCommandWrapper);
- for(Profile profile : keySet) {
- List<ApplyStereotypeCommand> list = missingProfiles.get(profile);
- for(ApplyStereotypeCommand applyStereotypeCommand : list) {
- compoundCommand.add(new EMFtoGEFCommandWrapper(applyStereotypeCommand));
- }
- }
- }
-
-
- if(compoundCommand.size() == 0) {// TODO : use unwrap if no use of UnexecutableCommand.INSTANCE
- return null;
- }
- return compoundCommand;
- }
-
-
/**
* Checks recursively if a profile is applied .
*
@@ -313,7 +191,7 @@ public class StereotypePasteStrategy implements IPasteStrategy {
* the profile
* @return true, if is profile applied recursive
*/
- private boolean isProfileAppliedRecursive(Element element, Profile profile) {
+ protected boolean isProfileAppliedRecursive(Element element, Profile profile) {
if(element instanceof Package) {
Package pkg = (Package)element;
boolean profileApplied = pkg.isProfileApplied(profile);
@@ -332,15 +210,7 @@ public class StereotypePasteStrategy implements IPasteStrategy {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
- */
- @Override
- public IPasteStrategy dependsOn() {
- return DefaultPasteStrategy.getInstance();
- }
+
/*
@@ -349,7 +219,7 @@ public class StereotypePasteStrategy implements IPasteStrategy {
* @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) {
+ public void prepare(PapyrusClipboard<Object> papyrusClipboard, Collection<EObject> selection) {
Map<Object, IClipboardAdditionalData> mapCopyToStereotypeData = new HashMap<Object, IClipboardAdditionalData>();
for(Iterator<EObject> iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) {
EObject eObjectSource = (EObject)iterator.next();
@@ -396,15 +266,13 @@ public class StereotypePasteStrategy implements IPasteStrategy {
// }
-
- // TODO : remove no internal class
/**
- * The Class StereotypeClipboard.
+ * This Class store the stereotypes to be reapplied.
*/
- private class StereotypeClipboard implements IClipboardAdditionalData {
+ protected class StereotypeClipboard implements IClipboardAdditionalData {
/** The stereotype. */
- private Collection<Stereotype> stereotypes;
+ protected Collection<Stereotype> stereotypes;
/**
* @param stereotypes
@@ -422,8 +290,4 @@ public class StereotypePasteStrategy implements IPasteStrategy {
}
-
-
-
-
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CopyHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CopyHandler.java
index beb38f2..7fd2a83 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CopyHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CopyHandler.java
@@ -51,7 +51,7 @@ public class CopyHandler extends AbstractCommandHandler {
List<IStrategy> allStrategies = PasteStrategyManager.getInstance().getAllStrategies();
for(IStrategy iStrategy : allStrategies) {
IPasteStrategy iPasteStrategy = (IPasteStrategy)iStrategy;
- iPasteStrategy.prepare(papyrusClipboard);
+ iPasteStrategy.prepare(papyrusClipboard, selectedElements);
}
return defaultCopyCommand;
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java
index 17f8ff5..43c4d72 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java
@@ -60,8 +60,8 @@ public class PasteHandler extends AbstractCommandHandler {
* @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#computeEnabled()
*/
@Override
- protected boolean computeEnabled() { // paste is only available on a simple selection and wit ha full Clipboard
- if (!PapyrusClipboard.getInstance().isEmpty() && getSelectedElements().size() == 1){
+ protected boolean computeEnabled() { // paste is only available on a simple selection and with a non empty Clipboard
+ if (!PapyrusClipboard.getInstance().isEmptyWithNoAdditionalData() && getSelectedElements().size() == 1){
return !EMFHelper.isReadOnly(getSelectedElements().get(0));
} else {
return super.computeEnabled();