Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2019-06-04 09:47:51 -0400
committerNicolas FAUVERGUE2019-06-17 06:22:55 -0400
commitb709a250e6664899d5de6a82e55edeb8a318497e (patch)
tree529c00f62dcf6a947e29a3cb13cd9b16c61d8021
parent1fb6853103e6b85bccaa5acd2050d50f00c1d759 (diff)
downloadorg.eclipse.papyrus-b709a250e6664899d5de6a82e55edeb8a318497e.tar.gz
org.eclipse.papyrus-b709a250e6664899d5de6a82e55edeb8a318497e.tar.xz
org.eclipse.papyrus-b709a250e6664899d5de6a82e55edeb8a318497e.zip
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 <nicolas.fauvergue@cea.fr>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/dnd/behavior/BehaviorToCallBehaviorActionDropStrategy.java94
1 files 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<EObject> 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<Object> 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<CallBehaviorAction, Activity, Behavior>(targetEditPart, CallBehaviorAction.class, activity, behavior, false, UMLElementTypes.CALL_BEHAVIOR_ACTION);
+ ICommand editSlotsCommand = new CreateCallBehaviorAndUpdateCommand<CallBehaviorAction, Activity, Behavior>(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;
}
+
}

Back to the top