summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-04-18 10:28:56 (EDT)
committerRemi Schnekenburger2014-05-06 03:57:04 (EDT)
commit599bb088e21f7aba8c558a627f672f8cf09890d5 (patch)
treefd0c85b4dca13bd370552ecc73c867d2ed807e44
parent7f14df266a69b5a465eb71b816009c2824c21f4c (diff)
downloadorg.eclipse.papyrus-599bb088e21f7aba8c558a627f672f8cf09890d5.zip
org.eclipse.papyrus-599bb088e21f7aba8c558a627f672f8cf09890d5.tar.gz
org.eclipse.papyrus-599bb088e21f7aba8c558a627f672f8cf09890d5.tar.bz2
[290261] Papyrus shall provide a copy/paste/cut featurerefs/changes/75/25275/2
- Add poste to a view container and transform the paste in a drop for target diagram different from source diagram Change-Id: I4042ce5c1e31b75442c729a3eec570947610a5ea 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.java24
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java10
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java184
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/DefaultPasteStrategy.java3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/MDTUtil.java2
6 files changed, 208 insertions, 21 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 8f84365..2052c6e 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
@@ -53,6 +53,30 @@ public class PapyrusClipboard<E> extends ArrayList<E> {
return instance;
}
+ private static String UNKNOW_TYPE = "unknown"; //$NON-NLS-1$
+
+ /** Type of the source container, ex : type of Diagram */
+ protected String containerType;
+
+
+ /**
+ * @return containerType
+ */
+ public String getContainerType() {
+ if (containerType != null) {
+ return containerType;
+ }
+ return UNKNOW_TYPE;
+ }
+
+ /**
+ * set containerType
+ * @param containerType
+ */
+ public void setContainerType(String containerType) {
+ this.containerType = containerType;
+ }
+
/**
* Clean the clipboard (target data) before pasting
*/
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
index bfb0b8b..a3bd9b4 100644
--- 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
@@ -23,6 +23,7 @@ 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.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
@@ -67,6 +68,15 @@ public class DefaultDiagramCopyCommand extends AbstractOverrideableCommand imple
Map<EObject, Object> mapInternalCopyInClipboard = new HashMap<EObject, Object>();
mapInternalCopyInClipboard.putAll(copier);
papyrusClipboard.addAllInternalCopyInClipboard(mapInternalCopyInClipboard);
+
+
+ if (pObjectsToPutInClipboard!=null && !pObjectsToPutInClipboard.isEmpty()){
+ IGraphicalEditPart next = pObjectsToPutInClipboard.iterator().next();
+ Diagram diagram = next.getNotationView().getDiagram();
+ String type = diagram.getType();
+ papyrusClipboard.setContainerType(type);
+ }
+
}
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
index 85a45d5..b005897 100644
--- 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
@@ -13,27 +13,43 @@ package org.eclipse.papyrus.infra.gmfdiag.common.commands;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.FigureCanvas;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
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.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
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.Diagram;
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.core.clipboard.PapyrusClipboard;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
/**
@@ -56,6 +72,12 @@ public class DefaultDiagramPasteCommand extends AbstractTransactionalCommand {
protected ICommand editCommand;
+ private CompoundCommand allDropCommand;
+
+ private GraphicalEditPart targetEditPart;
+
+ private List<EObject> objectToDrop;
+
/**
* Constructor.
*
@@ -65,12 +87,14 @@ public class DefaultDiagramPasteCommand extends AbstractTransactionalCommand {
* @param subCommand
* @param container
*/
- public DefaultDiagramPasteCommand(TransactionalEditingDomain editingDomain, String label, PapyrusClipboard papyrusClipboard, View container) {
+ public DefaultDiagramPasteCommand(TransactionalEditingDomain editingDomain, String label, PapyrusClipboard<Object> papyrusClipboard, GraphicalEditPart targetEditPart) {
super(editingDomain, label, null);
- this.container = container;
+ this.container = (View)targetEditPart.getModel();
+ this.targetEditPart = targetEditPart;
+
EcoreUtil.Copier copier = new EcoreUtil.Copier();
- List<EObject> rootElementInClipboard = EcoreUtil.filterDescendants(papyrusClipboard);
+ List<EObject> rootElementInClipboard = EcoreUtil.filterDescendants(filterEObject(papyrusClipboard));
copier.copyAll(rootElementInClipboard);
copier.copyReferences();
viewList.addAll(EcoreUtil.filterDescendants(copier.values()));
@@ -80,14 +104,19 @@ public class DefaultDiagramPasteCommand extends AbstractTransactionalCommand {
semanticList.add(copier.get(eObject));
}
}
-
+
// Inform the clipboard of the element created (used by strategies)
- papyrusClipboard.addAllInternalToTargetCopy(copier);
- MoveRequest moveRequest = new MoveRequest(container.getElement(), EcoreUtil.filterDescendants(semanticList));
+ papyrusClipboard.addAllInternalToTargetCopy(transtypeCopier(copier));
+ List<EObject> semanticRootList = EcoreUtil.filterDescendants(semanticList);
+ MoveRequest moveRequest = new MoveRequest(container.getElement(), semanticRootList);
+
IElementEditService provider = ElementEditServiceUtils.getCommandProvider(container.getElement());
- if(provider != null) {
+ if(provider != null) {
editCommand = provider.getEditCommand(moveRequest);
}
+ if (!papyrusClipboard.getContainerType().equals(targetEditPart.getNotationView().getType()) || viewList.isEmpty()){
+ this.objectToDrop = semanticRootList;
+ }
}
/**
@@ -95,23 +124,89 @@ public class DefaultDiagramPasteCommand extends AbstractTransactionalCommand {
*/
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- // semantic copy (Move)
editCommand.execute(progressMonitor, info);
- shiftLayout(container, viewList);
+ if (this.objectToDrop != null){ // try to drop the views
+ constructDropRequest(targetEditPart, this.objectToDrop);
+ if (allDropCommand != null && !allDropCommand.isEmpty()) {
+ allDropCommand.execute();
+ }
+ } else if (viewList !=null && !viewList.isEmpty()){
+ shiftLayoutList(container, viewList);
+ }
return editCommand.getCommandResult();
+ }
+
+
+ /**
+ * Construct the drop request
+ * @param targetEditPart
+ * @param objectToDrop
+ */
+ protected void constructDropRequest(GraphicalEditPart targetEditPart, List<EObject> objectToDrop) {
+ DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
+ if (container instanceof Diagram) {
+ Point cursorPosition = getCursorPosition(targetEditPart);
+ allDropCommand = new CompoundCommand("Drop all semantics elements on diagram"); //$NON-NLS-1$
+ for(EObject eObject : objectToDrop) {
+ dropObjectsRequest.setObjects(Collections.singletonList(eObject));
+ dropObjectsRequest.setLocation(cursorPosition);
+ Command command = targetEditPart.getCommand(dropObjectsRequest);
+ allDropCommand.add(command);
+ cursorPosition = shiftLayout(cursorPosition);
+ }
+ } else if (!(container instanceof Diagram)){
+ Rectangle bounds = targetEditPart.getFigure().getBounds();
+ Point center = bounds.getCenter();
+ allDropCommand = new CompoundCommand("Drop all semantics elements on a view"); //$NON-NLS-1$
+ dropObjectsRequest.setObjects(objectToDrop);
+ dropObjectsRequest.setLocation(center);
+ Command command = targetEditPart.getCommand(dropObjectsRequest);
+ if (command == null){
+ command = lookForCommandInSubContainer(targetEditPart, objectToDrop);
+ }
+ allDropCommand.add(command);
+ }
}
+
+ /**
+ * Look in sub container for a dropcommand
+ * @param targetEditPart
+ * @param objectToDrop
+ * @return
+ */
+ protected Command lookForCommandInSubContainer(GraphicalEditPart targetEditPart, List<EObject> objectToDrop) {
+ List children = targetEditPart.getChildren();
+ DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
+ for(Object object : children) {
+ if (object instanceof GraphicalEditPart) {
+ GraphicalEditPart graphicalEditPart = (GraphicalEditPart) object;
+ Point center = graphicalEditPart.getFigure().getBounds().getCenter();
+ dropObjectsRequest.setLocation(center);
+ dropObjectsRequest.setObjects(objectToDrop);
+ Command command = graphicalEditPart.getCommand(dropObjectsRequest);
+ if (command != null) {
+ return command;
+ }
+ }
+ }
+ return null;
+ }
+
+
+
+
/**
* Shift the layout of all duplicate Views
*
* @param values
*/
- // TODO : move it in a View utilities class
- private void shiftLayout(View container, Collection values) {
+ // TODO : move it in a View utility class
+ private void shiftLayoutList(View container, Collection<EObject> values) {
//Collection values = duplicatedObject.values();
- Iterator iterator = values.iterator();
+ Iterator<EObject> 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
+ // if this is a shape a new position is set in order to avoid overlap
while(iterator.hasNext()) {
Object object = iterator.next();
if(object instanceof View) {
@@ -124,10 +219,69 @@ public class DefaultDiagramPasteCommand extends AbstractTransactionalCommand {
}
}
if(duplicatedView.eContainer() == null && container != null) {
- ViewUtil.insertChildView(container, duplicatedView, -1, true);
+ ViewUtil.insertChildView(container, duplicatedView, ViewUtil.APPEND, true);
}
}
}
}
-
+
+
+ // TODO : move it in a View utility class
+ /**
+ * Shift position to avoid overlap
+ * @param point
+ * @return
+ */
+ protected Point shiftLayout(Point point){
+ return new Point(point.x+DEFAULT_AVOID_SUPERPOSITION_X, point.y+DEFAULT_AVOID_SUPERPOSITION_Y);
+ }
+
+ /**
+ * @param targetEditPart
+ * @return
+ */
+ // TODO : move it in utility class
+ protected Point getCursorPosition(GraphicalEditPart targetEditPart) {
+ Display display = Display.getDefault();
+ org.eclipse.swt.graphics.Point cursorLocation = display.getCursorLocation();
+ EditPartViewer viewer = targetEditPart.getViewer();
+ Control control = viewer.getControl();
+ org.eclipse.swt.graphics.Point point = control.toControl(cursorLocation);
+ FigureCanvas figureCanvas = (FigureCanvas) control;
+ Point location = figureCanvas.getViewport().getViewLocation();
+ return new Point(point.x + location.x, point.y + location.y);
+ }
+
+
+ /**
+ * @param collection
+ * @return
+ */
+ // TODO : move it in utility class
+ protected Collection<EObject> filterEObject(Collection<Object> collection){
+ List<EObject> eobjectList = new ArrayList<EObject>();
+ for(Object object : collection) {
+ if (object instanceof EObject){
+ eobjectList.add((EObject)object);
+ }
+ }
+ return eobjectList;
+ }
+
+
+ /**
+ * @param copier
+ * @return
+ */
+ // TODO : move it in utility class
+ protected Map<Object, EObject> transtypeCopier(EcoreUtil.Copier copier) {
+ Map<Object, EObject> map = new HashMap<Object, EObject>();
+ Set<Entry<EObject, EObject>> entrySet = copier.entrySet();
+ for(Entry<EObject, EObject> entry : entrySet) {
+ map.put(entry.getValue(), entry.getValue());
+ }
+ return map;
+ }
+
+
}
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 b7db90d..560ee8d 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
@@ -12,7 +12,6 @@
package org.eclipse.papyrus.infra.gmfdiag.common.commands;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -32,10 +31,11 @@ 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;
/**
- * this handler has in charge to exexute the paste of UML element with their applied stereotypes
+ * this handler has in charge to execute the paste of UML element with their applied stereotypes
*
*/
public class DefaultPasteCommand extends AbstractCommand {
@@ -62,7 +62,7 @@ public class DefaultPasteCommand extends AbstractCommand {
Iterator<Object> iterData = papyrusClipboard.iterator();
while(iterData.hasNext()) {
Object object = iterData.next();
- if(object instanceof EObject) {
+ if(object instanceof Element) { // TODO : create utility to detec if the element is part of the semantic model
eobjectsTopaste.add((EObject)object);
}
}
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/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/DefaultPasteStrategy.java
index 4ef0c2b..6a6dc34 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/DefaultPasteStrategy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/DefaultPasteStrategy.java
@@ -18,7 +18,6 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
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;
@@ -139,7 +138,7 @@ public class DefaultPasteStrategy implements IPasteStrategy {
@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());
+ DefaultDiagramPasteCommand defaultDiagramPasteCommand = new DefaultDiagramPasteCommand(targetEditPart.getEditingDomain(), "DefaultGraphicalPasteWithModel", papyrusClipboard,targetEditPart ); //$NON-NLS-1$
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/util/MDTUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/MDTUtil.java
index 7375d27..0bc5363 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/MDTUtil.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/MDTUtil.java
@@ -1039,7 +1039,7 @@ public class MDTUtil {
// some <Diagram>s were found
return diagrams;
}
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
// // Filter Views and Labels