From b709a250e6664899d5de6a82e55edeb8a318497e Mon Sep 17 00:00:00 2001 From: Nicolas FAUVERGUE Date: Tue, 4 Jun 2019 15:47:51 +0200 Subject: Bug 517797: [ActivityDiagram] Copy-paste doesn't work as expected Manage the graphical creation of the CallBehaviorAction for the copy/paste of an activity. Change-Id: I3f2ce172c713d25a5209568d8bdd359573e52c0a Signed-off-by: Nicolas FAUVERGUE --- .../BehaviorToCallBehaviorActionDropStrategy.java | 94 ++++++++++++++++++---- 1 file changed, 78 insertions(+), 16 deletions(-) diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/dnd/behavior/BehaviorToCallBehaviorActionDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/dnd/behavior/BehaviorToCallBehaviorActionDropStrategy.java index 98a91c39af8..0d1688e9227 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/dnd/behavior/BehaviorToCallBehaviorActionDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/dnd/behavior/BehaviorToCallBehaviorActionDropStrategy.java @@ -1,6 +1,6 @@ /***************************************************************************** - * Copyright (c) 2015 CEA LIST and others. - * + * Copyright (c) 2015, 2019 CEA LIST and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -10,13 +10,17 @@ * * Contributors: * Francois Le Fevre (CEA LIST) francois.le-fevre@cea.fr - Initial API and implementation - * + * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 517797 + * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.activity.dnd.behavior; +import java.util.Iterator; import java.util.List; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.draw2d.geometry.Point; import org.eclipse.emf.ecore.EObject; import org.eclipse.gef.EditPart; import org.eclipse.gef.Request; @@ -24,7 +28,15 @@ import org.eclipse.gef.commands.Command; import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor; +import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy; +import org.eclipse.papyrus.uml.diagram.activity.edit.parts.ActivityActivityContentCompartmentEditPart; +import org.eclipse.papyrus.uml.diagram.activity.edit.parts.CallBehaviorActionEditPart; import org.eclipse.papyrus.uml.diagram.activity.part.CustomMessages; import org.eclipse.papyrus.uml.diagram.activity.part.UMLDiagramEditorPlugin; import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; @@ -39,27 +51,31 @@ import org.eclipse.uml2.uml.CallBehaviorAction; */ public class BehaviorToCallBehaviorActionDropStrategy extends TransactionalDropStrategy { + @Override public String getLabel() { - return CustomMessages.BehaviorToCallBehaviorActionDropStrategy_Label; + return CustomMessages.BehaviorToCallBehaviorActionDropStrategy_Label; } + @Override public String getDescription() { return CustomMessages.BehaviorToCallBehaviorActionDropStrategy_Description; } + @Override public Image getImage() { return null; } + @Override public String getID() { return UMLDiagramEditorPlugin.ID + ".operation.represents"; //$NON-NLS-1$ } @Override protected Command doGetCommand(Request request, final EditPart targetEditPart) { - //Step 1: check the environment + // Step 1: check the environment - //Step 1.1: The only supported case is "Drop a single element" + // Step 1.1: The only supported case is "Drop a single element" List sourceElements = getSourceEObjects(request); if (sourceElements.size() != 1) { @@ -67,30 +83,73 @@ public class BehaviorToCallBehaviorActionDropStrategy extends TransactionalDropS } final EObject sourceElement = sourceElements.get(0); - //Step 1.2: The only supported case is Operation + // Step 1.2: The only supported case is Operation if (!(sourceElement instanceof Behavior)) { return null; } - final Behavior behavior = (Behavior)sourceElement; + final Behavior behavior = (Behavior) sourceElement; - //Step 1.3: The only supported case is Activity + // Step 1.3: The only supported case is Activity final EObject targetElement = getTargetSemanticElement(targetEditPart); if (!(targetElement instanceof org.eclipse.uml2.uml.Activity)) { return null; } - final Activity activity = (Activity)targetElement; - - //Step 2: create the commands + final Activity activity = (Activity) targetElement; + + // Get the compartment edit part + ActivityActivityContentCompartmentEditPart compartmentEditPart = null; + Iterator children = targetEditPart.getChildren().iterator(); + while (children.hasNext() && null == compartmentEditPart) { + Object child = children.next(); + if (child instanceof ActivityActivityContentCompartmentEditPart) { + compartmentEditPart = (ActivityActivityContentCompartmentEditPart) child; + } + } + final ActivityActivityContentCompartmentEditPart contentCompartmentEditPart = compartmentEditPart; - //CompositeCommand to hold the commands + // Step 2: create the commands + // CompositeCommand to hold the commands CompositeCommand cc = new CompositeCommand(getLabel()); - - ICommand editSlotsCommand = new CreateCallBehaviorAndUpdateCommand(targetEditPart, CallBehaviorAction.class, activity, behavior, false, UMLElementTypes.CALL_BEHAVIOR_ACTION); + ICommand editSlotsCommand = new CreateCallBehaviorAndUpdateCommand(targetEditPart, CallBehaviorAction.class, activity, behavior, false, UMLElementTypes.CALL_BEHAVIOR_ACTION) { + + /** + * @see org.eclipse.papyrus.uml.diagram.activity.dnd.behavior.CreateCallBehaviorAndUpdateCommand#updateNewlyCreatedEObjectWithEObjectDragged(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject) + * + * @param callBehaviorAction + * @param property + * @throws ExecutionException + */ + @Override + public void updateNewlyCreatedEObjectWithEObjectDragged(CallBehaviorAction callBehaviorAction, Behavior property) throws ExecutionException { + // Manage the super process + super.updateNewlyCreatedEObjectWithEObjectDragged(callBehaviorAction, property); + + // If the content compartment edit part of the activity is visible, add the created CallBehaviorAction + if (null != contentCompartmentEditPart) { + // Get the location + final Point location; + if (request instanceof DropObjectsRequest) { + location = ((DropObjectsRequest) request).getLocation(); + } else { + location = new Point(100, 100); + } + + // Create the view request, its associated command and execute it + final ViewDescriptor descriptor = new ViewDescriptor(new EObjectAdapter(callBehaviorAction), Node.class, CallBehaviorActionEditPart.VISUAL_ID, ((IGraphicalEditPart) targetEditPart).getDiagramPreferencesHint()); + final CreateViewRequest createViewRequest = new CreateViewRequest(descriptor); + createViewRequest.setLocation(location); + final Command createViewCommand = contentCompartmentEditPart.getCommand(createViewRequest); + if (null != createViewCommand) { + createViewCommand.execute(); + } + } + } + }; if (editSlotsCommand != null) { cc.add(editSlotsCommand); } - + return cc.canExecute() ? new ICommandProxy(cc.reduce()) : null; } @@ -101,8 +160,11 @@ public class BehaviorToCallBehaviorActionDropStrategy extends TransactionalDropS * @return * @deprecated */ + @Deprecated + @Override public int getPriority() { return 0; } + } -- cgit v1.2.3