diff options
Diffstat (limited to 'plugins/infra/gmfdiag')
3 files changed, 182 insertions, 18 deletions
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 bfb0b8b4ed7..a3bd9b47535 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 85a45d58491..b0058975109 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 b7db90ddc5f..560ee8d96d0 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); } } |