Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[mdt-papyrus.dev] DnD framework rework

 Hello all,

I was working with the DnD common edit policy lately and I found some problems with it. I am bringing this here to discuss before submitting important modifications. (org.eclipse.papyrus.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy)


The biggest issue I found is that the current common class bypasses the gmf command framework, which leads to unwanted behavior because the policies are ignored.

For example in getDefaultDropNodeCommand we are building a createcommand and a setbounds command instead of asking the edit part to give us a fully complete command using a request.


An other problem is that we change the location of the request to a relative one before calling the abstract method. I agree it could be convenient to already have relative location in the sub classes but it is not correct regarding the framework which uses absolute location in its requests. A protected helper method to translate from absolute coordinates to relative should be sufficient.

Since this problem affects the behavior of an overridden method, most implementations need to be corrected regarding this point.

You can find attached an incomplete patch.
It fixes the common class according to this remarks and the sequence subclass for giving an example.
I am working on usecase and activity subclasses that will follow tomorrow.

I don't have time to look at all the other subclasses, but here is the procedure to fix each one of them :

- take care not to bypass the command framework. replace all new CreateCommand() by a call to getDefaultDropNodeCommand or dropBinaryLink, or at least use hostEditPart.getCommand if you need more control. And there is quite a lot of them :). - if you do really use location in your algo (ie not just passing it to getDefaultDropNodeCommand or dropBinaryLink) you should translate it to relative before so that your algo behaves the same way as before. You can use getTranslatedToRelative method for that. And don't forget to use the original absolute coordinates for calling getDefaultDropNodeCommand and dropBinaryLink, or for using a request. - in your methods (and method signatures) try to use absoluteLocation or relativeLocation variable names to keep track of which one is in use.


Thank you for reacting if necessary.

Best regards,

Mathieu
### Eclipse Workspace Patch 1.0
#P org.eclipse.papyrus.diagram.clazz
Index: custom-src/org/eclipse/papyrus/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java
===================================================================
--- custom-src/org/eclipse/papyrus/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java	(revision 3011)
+++ custom-src/org/eclipse/papyrus/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java	(working copy)
@@ -264,7 +264,7 @@
 	protected Command dropChildNodeWithContainmentLink(DropObjectsRequest dropRequest, Element droppedElement, int nodeVISUALID) {
 		ContainmentHelper containmentHelper = new ContainmentHelper(getEditingDomain());
 		CompositeCommand cc = new CompositeCommand(CONTAINED_CLASS_DROP_TO_COMPARTMENT);
-		cc = getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), droppedElement);
+		cc.add(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), droppedElement));
 
 		if((View)containmentHelper.findEditPartFor(getViewer().getEditPartRegistry(), droppedElement) != null) {
 			View droppedView = (View)containmentHelper.findEditPartFor(getViewer().getEditPartRegistry(), droppedElement).getModel();
#P org.eclipse.papyrus.diagram.common
Index: src/org/eclipse/papyrus/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java
===================================================================
--- src/org/eclipse/papyrus/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java	(revision 3014)
+++ src/org/eclipse/papyrus/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java	(working copy)
@@ -30,12 +30,11 @@
 import org.eclipse.gef.commands.Command;
 import org.eclipse.gef.commands.UnexecutableCommand;
 import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
 import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
 import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
 import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
 import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
@@ -51,12 +50,13 @@
 import org.eclipse.gmf.runtime.notation.Diagram;
 import org.eclipse.gmf.runtime.notation.Node;
 import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.diagram.common.command.wrappers.CommandProxyWithResult;
 import org.eclipse.papyrus.diagram.common.commands.CommonDeferredCreateConnectionViewCommand;
 import org.eclipse.papyrus.diagram.common.commands.SemanticAdapter;
 import org.eclipse.papyrus.diagram.common.helper.ILinkMappingHelper;
+import org.eclipse.papyrus.diagram.common.util.DiagramEditPartsUtil;
 import org.eclipse.papyrus.diagram.common.util.ViewServiceUtil;
 import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Package;
 
 /**
  * This class is used to execute the drag and drop from the outline. It can manage the drop of nodes
@@ -140,7 +140,7 @@
 	 * 
 	 * @return the composite command
 	 */
-	public CompositeCommand dropBinaryLink(CompositeCommand cc, Element source, Element target, int linkVISUALID, Point location, Element semanticLink) {
+	public CompositeCommand dropBinaryLink(CompositeCommand cc, Element source, Element target, int linkVISUALID, Point absoluteLocation, Element semanticLink) {
 		// look for editpart
 		GraphicalEditPart sourceEditPart = (GraphicalEditPart)lookForEditPart(source);
 		GraphicalEditPart targetEditPart = (GraphicalEditPart)lookForEditPart(target);
@@ -151,30 +151,18 @@
 		IAdaptable sourceAdapter = null;
 		IAdaptable targetAdapter = null;
 		if(sourceEditPart == null) {
-			// creation of the node
-			ViewDescriptor descriptor = new ViewDescriptor(new EObjectAdapter(source), Node.class, null, ViewUtil.APPEND, false, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
-
-			// get the command and execute it.
-			CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart)getHost()).getEditingDomain(), descriptor, ((View)getHost().getModel()));
-			cc.compose(nodeCreationCommand);
-			SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y + 100)); //$NON-NLS-1$
-			cc.compose(setBoundsCommand);
+			ICommand createCommand = getDefaultDropNodeCommand(absoluteLocation, source);
+			cc.add(createCommand);
 
-			sourceAdapter = (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue();
+			sourceAdapter = (IAdaptable)createCommand.getCommandResult().getReturnValue();
 		} else {
 			sourceAdapter = new SemanticAdapter(null, sourceEditPart.getModel());
 		}
 		if(targetEditPart == null) {
-			// creation of the node
-			ViewDescriptor descriptor = new ViewDescriptor(new EObjectAdapter(target), Node.class, null, ViewUtil.APPEND, false, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
-
-			// get the command and execute it.
-			CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart)getHost()).getEditingDomain(), descriptor, ((View)getHost().getModel()));
-			cc.compose(nodeCreationCommand);
-			SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y - 100)); //$NON-NLS-1$
-			cc.compose(setBoundsCommand);
-			targetAdapter = (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue();
+			ICommand createCommand = getDefaultDropNodeCommand(absoluteLocation, target);
+			cc.add(createCommand);
 
+			targetAdapter = (IAdaptable)createCommand.getCommandResult().getReturnValue();
 		} else {
 			targetAdapter = new SemanticAdapter(null, targetEditPart.getModel());
 		}
@@ -220,32 +208,31 @@
 		 */
 		ViewServiceUtil.forceLoad();
 
-		
+
 		if(dropRequest.getObjects().size() > 0 && dropRequest.getObjects().get(0) instanceof String) {
 			return getDropFileCommand(dropRequest);
 		}
-		
-		
+
+
 		// Create a view request from the drop request and then forward getting
 		// the command for that.
 		CompositeCommand cc = new CompositeCommand("Drop"); //$NON-NLS-1$
 		Iterator<?> iter = dropRequest.getObjects().iterator();
-		Point location = getTranslatedLocation(dropRequest);
-		
+
 		while(iter.hasNext()) {
 			EObject droppedObject = (EObject)iter.next();
-			cc.add(getDropObjectCommand(dropRequest, droppedObject, location));
+			cc.add(getDropObjectCommand(dropRequest, droppedObject));
 		}
 
 		return new ICommandProxy(cc);
 	}
 
-	protected IUndoableOperation getDropObjectCommand(DropObjectsRequest dropRequest,
-			EObject droppedObject, Point location) {
+	protected IUndoableOperation getDropObjectCommand(DropObjectsRequest dropRequest, EObject droppedObject) {
+		Point location = dropRequest.getLocation().getCopy();
+
 		int nodeVISUALID = getNodeVisualID(((IGraphicalEditPart)getHost()).getNotationView(), droppedObject);
 		int linkVISUALID = getLinkWithClassVisualID(droppedObject);
 		if(getSpecificDrop().contains(nodeVISUALID) || getSpecificDrop().contains(linkVISUALID)) {
-			dropRequest.setLocation(location);
 			// TODO: add to composite command ?
 			return new CommandProxy(getSpecificDropCommand(dropRequest, (Element)droppedObject, nodeVISUALID, linkVISUALID));
 		}
@@ -260,14 +247,12 @@
 			// . Release the constraint when GraphicalParent is a diagram
 			if(getHost().getModel() instanceof Diagram) {
 				return getDefaultDropNodeCommand(nodeVISUALID, location, droppedObject);
-
 			} else if((graphicalParent instanceof Element) && ((Element)graphicalParent).getOwnedElements().contains(droppedObject)) {
 				return getDefaultDropNodeCommand(nodeVISUALID, location, droppedObject);
-
 			}
 			return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
 
-		} 
+		}
 		if(linkVISUALID != -1) {
 			Collection<?> sources = linkmappingHelper.getSource((Element)droppedObject);
 			Collection<?> targets = linkmappingHelper.getTarget((Element)droppedObject);
@@ -278,27 +263,30 @@
 			Element source = (Element)sources.toArray()[0];
 			Element target = (Element)targets.toArray()[0];
 			CompositeCommand cc = new CompositeCommand("Add Link"); //$NON-NLS-1$
-			dropBinaryLink(cc, source, target, linkVISUALID, dropRequest.getLocation(), (Element)droppedObject);
+			dropBinaryLink(cc, source, target, linkVISUALID, location, (Element)droppedObject);
 			return cc;
 		}
-		return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;	
+		return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
 	}
-	
-	private Point getTranslatedLocation(DropObjectsRequest dropRequest) {
-		Point location = dropRequest.getLocation().getCopy();
-		((GraphicalEditPart) getHost()).getContentPane().translateToRelative(
-				location);
-		((GraphicalEditPart) getHost()).getContentPane().translateFromParent(
-				location);
-		location.translate(((GraphicalEditPart) getHost()).getContentPane()
-				.getClientArea().getLocation().getNegated());
-		return location;
+
+	/**
+	 * Get a new Point translated to relative coordinate
+	 * 
+	 * @param absoluteLocation
+	 *        the absolute point
+	 * @return the relative point
+	 */
+	protected Point getTranslatedToRelative(Point absoluteLocation) {
+		Point relativeLocation = absoluteLocation.getCopy();
+		((GraphicalEditPart)getHost()).getContentPane().translateToRelative(relativeLocation);
+		((GraphicalEditPart)getHost()).getContentPane().translateFromParent(relativeLocation);
+		relativeLocation.translate(((GraphicalEditPart)getHost()).getContentPane().getClientArea().getLocation().getNegated());
+		return relativeLocation;
 	}
 
 	/**
-	 * This method returns the default drop command for node. Default here means the no
-	 * consideration is made regarding the semantic elements, the expected figure is basically
-	 * created where expected.
+	 * This method returns the default drop command for node. It create the view at the specified location,
+	 * using the gmf command framework so the policies are used.
 	 * 
 	 * @param nodeVISUALID
 	 *        the node visual identifier
@@ -306,19 +294,100 @@
 	 *        the drop location
 	 * @param droppedObject
 	 *        the object to drop
-	 * @return a CompositeCommand for Drop
+	 * @return the creation node command
 	 */
-	protected CompositeCommand getDefaultDropNodeCommand(int nodeVISUALID, Point location, EObject droppedObject) {
-		CompositeCommand cc = new CompositeCommand("Drop"); //$NON-NLS-1$
-		IAdaptable elementAdapter = new EObjectAdapter(droppedObject);
+	protected ICommand getDefaultDropNodeCommand(int nodeVISUALID, Point absoluteLocation, EObject droppedObject) {
+		return getDefaultDropNodeCommand(getHost(), nodeVISUALID, absoluteLocation, droppedObject);
+	}
 
-		ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, ((IHintedType)getUMLElementType(nodeVISUALID)).getSemanticHint(), ViewUtil.APPEND, false, getDiagramPreferencesHint());
-		CreateCommand createCommand = new CreateCommand(getEditingDomain(), descriptor, ((View)(getHost().getModel())));
-		cc.compose(createCommand);
+	/**
+	 * This method returns the default drop command for node. It create the view at the specified location,
+	 * using the gmf command framework so the policies are used.
+	 * 
+	 * @param location
+	 *        the drop location
+	 * @param droppedObject
+	 *        the object to drop
+	 * @return the creation node command
+	 */
+	protected ICommand getDefaultDropNodeCommand(Point absoluteLocation, EObject droppedObject) {
+		return getDefaultDropNodeCommand(getHost(), null, absoluteLocation, droppedObject);
+	}
 
-		SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)createCommand.getCommandResult().getReturnValue(), location); //$NON-NLS-1$
-		cc.compose(setBoundsCommand);
-		return cc;
+	/**
+	 * This method returns the default drop command for node. It create the view at the specified location,
+	 * using the gmf command framework so the policies are used.
+	 * 
+	 * @param hostEP
+	 *        The host edit part which will be the parent of the new node
+	 * @param location
+	 *        the drop location
+	 * @param droppedObject
+	 *        the object to drop
+	 * @return the creation node command
+	 */
+	protected ICommand getDefaultDropNodeCommand(EditPart hostEP, Point absoluteLocation, EObject droppedObject) {
+		return getDefaultDropNodeCommand(hostEP, null, absoluteLocation, droppedObject);
+	}
+
+	/**
+	 * This method returns the default drop command for node. It create the view at the specified location,
+	 * using the gmf command framework so the policies are used.
+	 * 
+	 * @param hostEP
+	 *        The host edit part which will be the parent of the new node
+	 * @param nodeVISUALID
+	 *        the node visual identifier
+	 * @param location
+	 *        the drop location
+	 * @param droppedObject
+	 *        the object to drop
+	 * @return the creation node command
+	 */
+	protected ICommand getDefaultDropNodeCommand(EditPart hostEP, int nodeVISUALID, Point absoluteLocation, EObject droppedObject) {
+		IHintedType type = ((IHintedType)getUMLElementType(nodeVISUALID));
+
+		String semanticHint = null;
+		if(type != null) {
+			semanticHint = type.getSemanticHint();
+		}
+
+		return getDefaultDropNodeCommand(getHost(), semanticHint, absoluteLocation, droppedObject);
+	}
+
+	/**
+	 * This method returns the default drop command for node. It create the view at the specified location,
+	 * using the gmf command framework so the policies are used.
+	 * 
+	 * @param hostEP
+	 *        The host edit part which will be the parent of the new node
+	 * @param semanticHint
+	 *        the semantic hint of the view to create
+	 * @param location
+	 *        the drop location
+	 * @param droppedObject
+	 *        the object to drop
+	 * @return the creation node command
+	 */
+	protected ICommand getDefaultDropNodeCommand(EditPart hostEP, String semanticHint, Point absoluteLocation, EObject droppedObject) {
+		List<View> existingViews = DiagramEditPartsUtil.findViews(droppedObject, getViewer());
+
+		// only allow one view instance of a single element by diagram
+		if(existingViews.isEmpty()) {
+			IAdaptable elementAdapter = new EObjectAdapter(droppedObject);
+
+			ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, semanticHint, ViewUtil.APPEND, false, getDiagramPreferencesHint());
+			CreateViewRequest createViewRequest = new CreateViewRequest(descriptor);
+			createViewRequest.setLocation(absoluteLocation);
+
+			// "ask" the host for a command associated with the CreateViewRequest
+			Command command = hostEP.getCommand(createViewRequest);
+			// set the viewdescriptor as result
+			// it then can be used as an adaptable to retrieve the View
+			return new CommandProxyWithResult(command, descriptor);
+		}
+
+		return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
 	}
 
 	/**
@@ -419,5 +488,4 @@
 	protected boolean isEditPartTypeSuitableForEClass(Class<? extends GraphicalEditPart> editPartClass, EClass eClass) {
 		return true;
 	}
-
 }
Index: src/org/eclipse/papyrus/diagram/common/command/wrappers/CommandProxyWithResult.java
===================================================================
--- src/org/eclipse/papyrus/diagram/common/command/wrappers/CommandProxyWithResult.java	(revision 0)
+++ src/org/eclipse/papyrus/diagram/common/command/wrappers/CommandProxyWithResult.java	(revision 0)
@@ -0,0 +1,56 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *    
+ * 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:
+ *   Mathieu Velten (Atos Origin) mathieu.velten@xxxxxxxxxxxxxx - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagram.common.command.wrappers;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
+
+/**
+ * This command proxy wraps a GEF command into a GMF one,
+ * with result stored in the CommandResult.
+ * @author mvelten
+ *
+ */
+public class CommandProxyWithResult extends CommandProxy {
+
+	public CommandProxyWithResult(Command command, Object result) {
+		super(command);
+		setResult(CommandResult.newOKCommandResult(result));
+	}
+
+	@Override
+	protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+
+		super.doExecuteWithResult(progressMonitor, info);
+		return getCommandResult();
+	}
+
+	@Override
+	protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+
+		super.doRedoWithResult(progressMonitor, info);
+		return getCommandResult();
+	}
+
+	@Override
+	protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+
+		super.doUndoWithResult(progressMonitor, info);
+		return getCommandResult();
+	}
+}
#P org.eclipse.papyrus.diagram.sequence
Index: custom-src/org/eclipse/papyrus/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java
===================================================================
--- custom-src/org/eclipse/papyrus/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java	(revision 3011)
+++ custom-src/org/eclipse/papyrus/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java	(working copy)
@@ -25,26 +25,21 @@
 import org.eclipse.draw2d.geometry.Rectangle;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
 import org.eclipse.gef.commands.UnexecutableCommand;
 import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.diagram.core.commands.AddCommand;
 import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
 import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
 import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-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.emf.type.core.IElementType;
 import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
-import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyReferenceCommand;
-import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
 import org.eclipse.gmf.runtime.notation.Node;
 import org.eclipse.gmf.runtime.notation.View;
 import org.eclipse.papyrus.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy;
@@ -89,7 +84,6 @@
 import org.eclipse.uml2.uml.PackageableElement;
 import org.eclipse.uml2.uml.StateInvariant;
 import org.eclipse.uml2.uml.TimeObservation;
-import org.eclipse.uml2.uml.UMLPackage;
 
 /**
  * A policy to support dNd from the Model Explorer in the sequence diagram
@@ -158,6 +152,8 @@
 
 	@Override
 	protected Command getSpecificDropCommand(DropObjectsRequest dropRequest, Element semanticLink, int nodeVISUALID, int linkVISUALID) {
+		Point location = dropRequest.getLocation().getCopy();
+
 		// handle specifically the case when node is on a message
 		Command cmd = handleNodeOnMessage(semanticLink, nodeVISUALID, linkVISUALID);
 		if(cmd != null) {
@@ -168,18 +164,18 @@
 			switch(nodeVISUALID) {
 			case BehaviorExecutionSpecificationEditPart.VISUAL_ID:
 			case ActionExecutionSpecificationEditPart.VISUAL_ID:
-				return dropExecutionSpecification((ExecutionSpecification)semanticLink, nodeVISUALID);
+				return dropExecutionSpecification((ExecutionSpecification)semanticLink, nodeVISUALID, location);
 			case DestructionEventEditPart.VISUAL_ID:
-				return dropDestructionEvent((DestructionEvent)semanticLink, nodeVISUALID);
+				return dropDestructionEvent((DestructionEvent)semanticLink, nodeVISUALID, location);
 			case StateInvariantEditPart.VISUAL_ID:
-				return dropStateInvariant((StateInvariant)semanticLink, nodeVISUALID);
+				return dropStateInvariant((StateInvariant)semanticLink, nodeVISUALID, location);
 			case TimeConstraintEditPart.VISUAL_ID:
 			case DurationConstraintEditPart.VISUAL_ID:
 				return dropIntervalConstraintInLifeline((IntervalConstraint)semanticLink, nodeVISUALID);
 			case TimeObservationEditPart.VISUAL_ID:
 				return dropTimeObservationInLifeline((TimeObservation)semanticLink, nodeVISUALID);
 			case LifelineEditPart.VISUAL_ID:
-				return dropLifeline((Lifeline)semanticLink, nodeVISUALID);
+				return dropLifeline((Lifeline)semanticLink, nodeVISUALID, location);
 			default:
 				return UnexecutableCommand.INSTANCE;
 			}
@@ -213,12 +209,9 @@
 	 *        the node visual id
 	 * @return the drop command if the lifeline can be dropped
 	 */
-	private Command dropLifeline(Lifeline lifeline, int nodeVISUALID) {
+	private Command dropLifeline(Lifeline lifeline, int nodeVISUALID, Point location) {
 		if(getHostObject().equals(lifeline.getOwner())) {
-			List<View> existingViews = DiagramEditPartsUtil.findViews(lifeline, getViewer());
-			if(existingViews.isEmpty()) {
-				return getCreateCommand(lifeline, nodeVISUALID);
-			}
+			return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, location, lifeline));
 		}
 		return UnexecutableCommand.INSTANCE;
 	}
@@ -337,13 +330,10 @@
 	 * @return the command or UnexecutableCommand
 	 */
 	private Command dropNodeOnMessage(PackageableElement durationLabelElement, ConnectionNodeEditPart messageEditPart, int nodeVISUALID) {
-		CompositeCommand cc = new CompositeCommand("Drop");
 		IAdaptable elementAdapter = new EObjectAdapter(durationLabelElement);
 
 		ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, ((IHintedType)getUMLElementType(nodeVISUALID)).getSemanticHint(), ViewUtil.APPEND, false, getDiagramPreferencesHint());
-		CreateCommand createCommand = new CreateCommand(getEditingDomain(), descriptor, ((View)messageEditPart.getModel()));
-		cc.compose(createCommand);
-		return new ICommandProxy(cc);
+		return messageEditPart.getCommand(new CreateViewRequest(descriptor));
 	}
 
 	/**
@@ -356,12 +346,11 @@
 	 * @return the command if the lifeline is the correct one or UnexecutableCommand
 	 */
 	private Command dropTimeObservationInLifeline(TimeObservation observation, int nodeVISUALID) {
-		CompositeCommand cc = new CompositeCommand("Drop");
+		CompoundCommand cc = new CompoundCommand("Drop");
 		IAdaptable elementAdapter = new EObjectAdapter(observation);
 
 		ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, ((IHintedType)getUMLElementType(nodeVISUALID)).getSemanticHint(), ViewUtil.APPEND, false, getDiagramPreferencesHint());
-		CreateCommand createCommand = new CreateCommand(getEditingDomain(), descriptor, ((View)getHost().getModel()));
-		cc.compose(createCommand);
+		cc.add(getHost().getCommand(new CreateViewRequest(descriptor)));
 
 		LifelineEditPart lifelinePart = SequenceUtil.getParentLifelinePart(getHost());
 		if(lifelinePart != null) {
@@ -378,9 +367,9 @@
 					lifelinePart.getFigure().translateToRelative(newBounds);
 					Point parentLoc = lifelinePart.getLocation();
 					newBounds.translate(parentLoc.getNegated());
-					SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)createCommand.getCommandResult().getReturnValue(), newBounds);
-					cc.compose(setBoundsCommand);
-					return new ICommandProxy(cc);
+					SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", descriptor, newBounds);
+					cc.add(new ICommandProxy(setBoundsCommand));
+					return cc;
 				}
 			}
 		}
@@ -397,12 +386,11 @@
 	 * @return the command if the lifeline is the correct one or UnexecutableCommand
 	 */
 	private Command dropIntervalConstraintInLifeline(IntervalConstraint constraint, int nodeVISUALID) {
-		CompositeCommand cc = new CompositeCommand("Drop");
+		CompoundCommand cc = new CompoundCommand("Drop");
 		IAdaptable elementAdapter = new EObjectAdapter(constraint);
 
 		ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, ((IHintedType)getUMLElementType(nodeVISUALID)).getSemanticHint(), ViewUtil.APPEND, false, getDiagramPreferencesHint());
-		CreateCommand createCommand = new CreateCommand(getEditingDomain(), descriptor, ((View)getHost().getModel()));
-		cc.compose(createCommand);
+		cc.add(getHost().getCommand(new CreateViewRequest(descriptor)));
 
 		LifelineEditPart lifelinePart = SequenceUtil.getParentLifelinePart(getHost());
 		if(lifelinePart != null && constraint.getConstrainedElements().size() >= 2) {
@@ -422,9 +410,9 @@
 					lifelinePart.getFigure().translateToRelative(newBounds);
 					Point parentLoc = lifelinePart.getLocation();
 					newBounds.translate(parentLoc.getNegated());
-					SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)createCommand.getCommandResult().getReturnValue(), newBounds);
-					cc.compose(setBoundsCommand);
-					return new ICommandProxy(cc);
+					SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", descriptor, newBounds);
+					cc.add(new ICommandProxy(setBoundsCommand));
+					return cc;
 				}
 			}
 		} else if(lifelinePart != null && constraint.getConstrainedElements().size() == 1) {
@@ -441,9 +429,9 @@
 					lifelinePart.getFigure().translateToRelative(newBounds);
 					Point parentLoc = lifelinePart.getLocation();
 					newBounds.translate(parentLoc.getNegated());
-					SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)createCommand.getCommandResult().getReturnValue(), newBounds);
-					cc.compose(setBoundsCommand);
-					return new ICommandProxy(cc);
+					SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", descriptor, newBounds);
+					cc.add(new ICommandProxy(setBoundsCommand));
+					return cc;
 				}
 			}
 		}
@@ -464,29 +452,13 @@
 		return -1;
 	}
 
-	private Command dropStateInvariant(StateInvariant stateInvariant, int nodeVISUALID) {
-		List<View> existingViews = DiagramEditPartsUtil.findViews(stateInvariant, getViewer());
-		if(existingViews.isEmpty()) {
-
-			// an StateInvariant covereds systematically a unique lifeline
-			Lifeline lifeline = stateInvariant.getCovereds().get(0);
-			// Check that the container view is the view of the lifeline
-			if(lifeline.equals(getHostObject())) {
-				return getCreateCommand(stateInvariant, nodeVISUALID);
-			}
-		} else {
-			CompositeCommand cc = new CompositeCommand("Moving a StateInvariant");
-
-			// Add the view to the new container
-			AddCommand addCommand = new AddCommand(getEditingDomain(), new EObjectAdapter((View)getHost().getModel()), new EObjectAdapter(existingViews.get(0)));
-			cc.add(addCommand);
+	private Command dropStateInvariant(StateInvariant stateInvariant, int nodeVISUALID, Point location) {
 
-			Lifeline oldCoveredLifeline = (Lifeline)ViewUtil.resolveSemanticElement((View)existingViews.get(0).eContainer());
-
-			// Update the ES covered lifeline
-			updateCoveredLifeline(stateInvariant, cc, oldCoveredLifeline);
-
-			return new ICommandProxy(cc);
+		// an StateInvariant covereds systematically a unique lifeline
+		Lifeline lifeline = stateInvariant.getCovereds().get(0);
+		// Check that the container view is the view of the lifeline
+		if(lifeline.equals(getHostObject())) {
+			return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, location, stateInvariant));
 		}
 		return UnexecutableCommand.INSTANCE;
 	}
@@ -518,7 +490,7 @@
 	 *        the node visualID
 	 * @return the command to drop the destructionEvent on a lifeline if allowed.
 	 */
-	private Command dropDestructionEvent(DestructionEvent destructionEvent, int nodeVISUALID) {
+	private Command dropDestructionEvent(DestructionEvent destructionEvent, int nodeVISUALID, Point location) {
 		// Get all the view of this destructionEvent.
 		List<View> existingViews = DiagramEditPartsUtil.findViews(destructionEvent, getViewer());
 		// Get the lifelines containing the graphical destructionEvent
@@ -532,7 +504,7 @@
 					OccurrenceSpecification occurrenceSpecification = (OccurrenceSpecification)ift;
 					// if the event of the occurrenceSpecification is the DestructionEvent, create the command
 					if(destructionEvent.equals(occurrenceSpecification.getEvent())) {
-						return getCreateCommand(destructionEvent, nodeVISUALID);
+						return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, location, destructionEvent));
 					}
 				}
 			}
@@ -540,22 +512,7 @@
 		return UnexecutableCommand.INSTANCE;
 	}
 
-	/**
-	 * Get the create command
-	 * 
-	 * @param semanticLink
-	 *        the element
-	 * @param nodeVISUALID
-	 *        the visualID
-	 * @return the command
-	 */
-	private Command getCreateCommand(Element semanticLink, int nodeVISUALID) {
-		ViewDescriptor viewDescriptor = new ViewDescriptor(new EObjectAdapter(semanticLink), Node.class, String.valueOf(nodeVISUALID), ViewUtil.APPEND, true, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
-		CreateCommand cc = new CreateCommand(getEditingDomain(), viewDescriptor, (View)getHost().getModel());
-		return new ICommandProxy(cc);
-	}
-
-	private Command dropExecutionSpecification(ExecutionSpecification es, int nodeVISUALID) {
+	private Command dropExecutionSpecification(ExecutionSpecification es, int nodeVISUALID, Point location) {
 		List<View> existingViews = DiagramEditPartsUtil.findViews(es, getViewer());
 		if(existingViews.isEmpty()) {
 			// Find the lifeline of the ES
@@ -565,59 +522,14 @@
 				Lifeline lifeline = es.getStart().getCovereds().get(0);
 				// Check that the container view is the view of the lifeline
 				if(lifeline.equals(getHostObject())) {
-					return getCreateCommand(es, nodeVISUALID);
+					return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, location, es));
 				}
 			}
-		} else {
-
-			CompositeCommand cc = new CompositeCommand("Moving an ES");
-
-			// Add the view to the new container
-			AddCommand addCommand = new AddCommand(getEditingDomain(), new EObjectAdapter((View)getHost().getModel()), new EObjectAdapter(existingViews.get(0)));
-			cc.add(addCommand);
-
-			Lifeline oldCoveredLifeline = (Lifeline)ViewUtil.resolveSemanticElement((View)existingViews.get(0).eContainer());
-
-			// Update the ES covered lifeline
-			updateCoveredLifeline(es, cc, oldCoveredLifeline);
-
-			// Update the start and finish occurrence specification covered lifeline
-			updateCoveredLifeline(es.getStart(), cc, oldCoveredLifeline);
-			updateCoveredLifeline(es.getFinish(), cc, oldCoveredLifeline);
-
-			//TODO  Set the new location of the view. 
-			// Actually there is some layout problems, so it is disable. 
-			//				SetBoundsCommand boundsCommand = new SetBoundsCommand(getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, new EObjectAdapter(existingViews.get(0)), dropRequest.getLocation());
-			//				cc.add(boundsCommand);
-
-			return new ICommandProxy(cc);
 		}
 
 		return UnexecutableCommand.INSTANCE;
 	}
 
-	/**
-	 * Update the covered feature of the interactionFragment : remove the old lifeline and add the new lifeline.
-	 * 
-	 * @param interactionFragment
-	 *        the interaction fragment impacted
-	 * @param cc
-	 *        the composite command to add the new commands
-	 * @param oldCoveredLifeline
-	 *        the old covered lifeline
-	 */
-	private void updateCoveredLifeline(InteractionFragment interactionFragment, CompositeCommand cc, Lifeline oldCoveredLifeline) {
-		// Remove old covered lifeline 
-		DestroyReferenceRequest destroyReferenceRequest = new DestroyReferenceRequest(interactionFragment, UMLPackage.eINSTANCE.getInteractionFragment_Covered(), oldCoveredLifeline, false);
-		DestroyReferenceCommand destroyReferenceCommand = new DestroyReferenceCommand(destroyReferenceRequest);
-		cc.add(destroyReferenceCommand);
-
-		// Add new covered lifeline
-		SetRequest setRequest = new SetRequest(interactionFragment, UMLPackage.eINSTANCE.getInteractionFragment_Covered(), ViewUtil.resolveSemanticElement((View)getHost().getModel()));
-		SetValueCommand coveredLifelineCommand = new SetValueCommand(setRequest);
-		cc.add(coveredLifelineCommand);
-	}
-
 	private Command dropMessage(DropObjectsRequest dropRequest, Element semanticLink, int linkVISUALID) {
 		Collection<?> sources = SequenceLinkMappingHelper.getInstance().getSource(semanticLink);
 		Collection<?> targets = SequenceLinkMappingHelper.getInstance().getTarget(semanticLink);

Back to the top