Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF1
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java147
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/META-INF/MANIFEST.MF1
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java146
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/CustomDiagramDragDropEditPolicy.java162
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestPortLocation.java7
6 files changed, 149 insertions, 315 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
index 2c72fc2e624..df8c33781e8 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
@@ -69,6 +69,7 @@ Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="1.2.0",
org.eclipse.papyrus.infra.extendedtypes;bundle-version="1.2.0",
org.eclipse.papyrus.infra.services.edit;bundle-version="1.2.0",
org.eclipse.papyrus.infra.gmfdiag.navigation;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="1.2.0",
org.eclipse.papyrus.uml.diagram.navigation;bundle-version="1.2.0",
org.eclipse.gmf.runtime.diagram.ui.printing,
org.eclipse.gmf.runtime.diagram.ui.providers.ide,
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java
index fc9dad982a1..cb745cd9cef 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java
@@ -24,12 +24,17 @@ import java.util.List;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.Viewport;
+import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.commands.UnexecutableCommand;
@@ -46,6 +51,9 @@ 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.editparts.ListCompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
+import org.eclipse.gmf.runtime.diagram.ui.figures.ShapeCompartmentFigure;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest.ConnectionViewDescriptor;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
@@ -60,19 +68,28 @@ import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.commands.wrappers.CommandProxyWithResult;
import org.eclipse.papyrus.infra.gmfdiag.common.adapter.SemanticAdapter;
import org.eclipse.papyrus.infra.gmfdiag.common.commands.CommonDeferredCreateConnectionViewCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.CreateViewCommand;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.AbstractDiagramDragDropEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.ViewServiceUtil;
+import org.eclipse.papyrus.infra.gmfdiag.dnd.policy.CustomizableDropEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.commands.DeferredCreateCommand;
import org.eclipse.papyrus.uml.diagram.common.helper.Element2IAdaptableRegistryHelper;
import org.eclipse.papyrus.uml.diagram.common.helper.ILinkMappingHelper;
import org.eclipse.papyrus.uml.diagram.common.listeners.DropTargetListener;
+import org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator;
import org.eclipse.papyrus.uml.diagram.common.util.AssociationUtil;
import org.eclipse.swt.dnd.DND;
+import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.ConnectableElement;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.EncapsulatedClassifier;
+import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
/**
* This class is used to execute the drag and drop from the outline. It can
@@ -885,6 +902,136 @@ public abstract class CommonDiagramDragDropEditPolicy extends AbstractDiagramDra
}
/**
+ * <pre>
+ * Returns the drop command for Affixed nodes (Parameter, Port).
+ * This method uses PortPositionLocator used by both Port and Parameter.
+ * If the dropped element is a Port, the graphical parent can be :
+ * - a Class that owns or inherits the Port
+ * - a Property which type owns or inherits the Port
+ * </pre>
+ *
+ * @param dropRequest
+ * the drop request
+ * @param droppedElement
+ * the element to drop
+ * @param nodeVISUALID
+ * the visual identifier of the EditPart of the dropped element
+ * @return the drop command
+ */
+ protected Command dropAffixedNode(DropObjectsRequest dropRequest, Element droppedElement, int nodeVISUALID) {
+ // The dropped element must be a Port or Parameter
+ if (!((droppedElement instanceof Port) || (droppedElement instanceof Parameter))) {
+ // Log.getInstance().error(new Exception("Incorrect parameter type (droppedElement should be a Port or Parameter)"));
+ return UnexecutableCommand.INSTANCE;
+ }
+ // Manage Element drop in compartment
+ Boolean isCompartmentTarget = false; // True if the target is a
+ // ShapeCompartmentEditPart
+ GraphicalEditPart graphicalParentEditPart = (GraphicalEditPart) getHost();
+ // Default drop location
+ Point dropLocation = dropRequest.getLocation().getCopy();
+ // Detect if the drop target is a compartment
+ if (graphicalParentEditPart instanceof ShapeCompartmentEditPart) {
+ isCompartmentTarget = true;
+ // Replace compartment edit part by its parent EditPart
+ graphicalParentEditPart = (GraphicalEditPart) graphicalParentEditPart.getParent();
+ // Translate Port expected location according to the compartment
+ // location
+ Point targetLocation = graphicalParentEditPart.getContentPane().getBounds().getLocation();
+ ShapeCompartmentFigure compartmentFigure = (ShapeCompartmentFigure) getHostFigure();
+ // Retrieve ViewPort location = the area where compartment children
+ // are located
+ // Retrieve ViewPort view location = the relative location of the
+ // viewed compartment
+ // depending on the current scroll bar state
+ Viewport compartmentViewPort = compartmentFigure.getScrollPane().getViewport();
+ Point compartmentViewPortLocation = compartmentViewPort.getLocation();
+ Point compartmentViewPortViewLocation = compartmentViewPort.getViewLocation();
+ // Calculate the delta between the targeted element position for
+ // drop (the Composite figure)
+ // and the View location with eventual scroll bar.
+ Point delta = compartmentViewPortLocation.translate(targetLocation.negate());
+ delta = delta.translate(compartmentViewPortViewLocation.negate());
+ // Translate the requested drop location (relative to parent)
+ dropLocation = dropRequest.getLocation().getTranslated(delta);
+ }
+ // If SideAffixedNodesCreationEditPolicy installed to the parent then delegate calculation of the real drop location to it
+ if (!isSideAffixedNodesCreationPolicyInstalled(graphicalParentEditPart)) {
+ Point parentLoc = graphicalParentEditPart.getFigure().getBounds().getLocation().getCopy();
+ PortPositionLocator locator = new PortPositionLocator(graphicalParentEditPart.getFigure(), PositionConstants.NONE);
+ Rectangle proposedBounds = new Rectangle(dropLocation, new Dimension(20, 20));
+ proposedBounds = proposedBounds.getTranslated(parentLoc);
+ Rectangle preferredBounds = locator.getPreferredLocation(proposedBounds);
+ // Convert the calculated preferred bounds as relative to parent location
+ Rectangle creationBounds = preferredBounds.getTranslated(parentLoc.getNegated());
+ dropLocation = creationBounds.getLocation();
+ }
+ // Manage Element drop in compartment
+ // Create proposed creation bounds and use the locator to find the
+ // expected position
+ EObject graphicalParentObject = graphicalParentEditPart.resolveSemanticElement();
+ if ((graphicalParentObject instanceof EncapsulatedClassifier) && (((EncapsulatedClassifier) graphicalParentObject).getAllAttributes().contains(droppedElement))) {
+ // Drop Port on StructuredClassifier
+ if (isCompartmentTarget) {
+ return getDropAffixedNodeInCompartmentCommand(nodeVISUALID, dropLocation, droppedElement);
+ }
+ return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropLocation, droppedElement));
+ } else if (graphicalParentObject instanceof ConnectableElement) {
+ // Drop Port on Part
+ Type type = ((ConnectableElement) graphicalParentObject).getType();
+ if ((type != null) && (type instanceof EncapsulatedClassifier) && (((EncapsulatedClassifier) type).getAllAttributes().contains(droppedElement))) {
+ if (isCompartmentTarget) {
+ return getDropAffixedNodeInCompartmentCommand(nodeVISUALID, dropLocation, droppedElement);
+ }
+ return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropLocation, droppedElement));
+ }
+ } else if ((graphicalParentObject instanceof Behavior) && (((Behavior) graphicalParentObject).getOwnedParameters().contains(droppedElement))) {
+ // Drop Parameter on Behavior
+ if (isCompartmentTarget) {
+ return getDropAffixedNodeInCompartmentCommand(nodeVISUALID, dropLocation, droppedElement);
+ }
+ return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropLocation, droppedElement));
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ * <pre>
+ * This method returns the drop command for AffixedNode (Port, Parameter)
+ * in case the node is dropped on a ShapeCompartmentEditPart.
+ * </pre>
+ *
+ * @param nodeVISUALID
+ * the node visual identifier
+ * @param location
+ * the drop location
+ * @param droppedObject
+ * the object to drop
+ * @return a CompositeCommand for Drop
+ */
+ protected CompoundCommand getDropAffixedNodeInCompartmentCommand(int nodeVISUALID, Point location, EObject droppedObject) {
+ CompoundCommand cc = new CompoundCommand("Drop");
+ IAdaptable elementAdapter = new EObjectAdapter(droppedObject);
+ ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, ((IHintedType) getUMLElementType(nodeVISUALID)).getSemanticHint(), ViewUtil.APPEND, true, getDiagramPreferencesHint());
+ // Create the command targeting host parent (owner of the
+ // ShapeCompartmentEditPart)
+ CreateViewCommand createCommand = new CreateViewCommand(getEditingDomain(), descriptor, ((View) (getHost().getParent().getModel())));
+ cc.add(new ICommandProxy(createCommand));
+ SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) createCommand.getCommandResult().getReturnValue(), location);
+ cc.add(new ICommandProxy(setBoundsCommand));
+ return cc;
+ }
+
+ private boolean isSideAffixedNodesCreationPolicyInstalled(IGraphicalEditPart editPart) {
+ EditPolicy policy = editPart.getEditPolicy(EditPolicyRoles.CREATION_ROLE);
+ if (policy == null && false == policy instanceof CustomizableDropEditPolicy) {
+ return false;
+ }
+ EditPolicy defaultCreationPolicy = ((CustomizableDropEditPolicy) policy).getDefaultCreationPolicy();
+ return defaultCreationPolicy != null && defaultCreationPolicy instanceof SideAffixedNodesCreationEditPolicy;
+ }
+
+ /**
* the method provides command to create the binary link into the diagram.
* Find source/target adapter
* If the source and the target views do not exist, these views will be
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/META-INF/MANIFEST.MF
index a48e3bb7762..6148d115420 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/META-INF/MANIFEST.MF
@@ -46,7 +46,6 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.uml.tools.utils;bundle-version="1.2.0",
org.eclipse.papyrus.infra.extendedtypes;bundle-version="1.2.0",
org.eclipse.papyrus.infra.gmfdiag.navigation;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="1.2.0",
org.eclipse.uml2.uml.edit;bundle-version="4.0.0",
org.eclipse.papyrus.infra.emf;bundle-version="1.2.0",
org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.2.0",
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java
index 0373326d2ed..47ff847f2b7 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java
@@ -18,14 +18,9 @@ import java.util.Iterator;
import java.util.Set;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.Viewport;
-import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.commands.UnexecutableCommand;
@@ -35,10 +30,6 @@ import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
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.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
-import org.eclipse.gmf.runtime.diagram.ui.figures.ShapeCompartmentFigure;
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;
@@ -46,15 +37,11 @@ import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.dnd.policy.CustomizableDropEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.SideAffixedNodesCreationEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator;
import org.eclipse.papyrus.uml.diagram.component.custom.edit.command.CreateViewCommand;
import org.eclipse.papyrus.uml.diagram.component.custom.edit.helpers.ComponentLinkMappingHelper;
import org.eclipse.papyrus.uml.diagram.component.custom.edit.helpers.ConnectorHelper;
import org.eclipse.papyrus.uml.diagram.component.custom.edit.helpers.MultiDependencyHelper;
-import org.eclipse.papyrus.uml.diagram.component.custom.log.Log;
import org.eclipse.papyrus.uml.diagram.component.edit.parts.AbstractionEditPart;
import org.eclipse.papyrus.uml.diagram.component.edit.parts.CommentEditPart;
import org.eclipse.papyrus.uml.diagram.component.edit.parts.CommentEditPartPCN;
@@ -77,7 +64,6 @@ import org.eclipse.papyrus.uml.diagram.component.edit.parts.SubstitutionEditPart
import org.eclipse.papyrus.uml.diagram.component.edit.parts.UsageEditPart;
import org.eclipse.papyrus.uml.diagram.component.part.UMLVisualIDRegistry;
import org.eclipse.papyrus.uml.diagram.component.providers.UMLElementTypes;
-import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Collaboration;
@@ -88,8 +74,6 @@ import org.eclipse.uml2.uml.Connector;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.Dependency;
import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.EncapsulatedClassifier;
-import org.eclipse.uml2.uml.Parameter;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.StructuredClassifier;
@@ -500,109 +484,6 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
/**
* <pre>
- * Returns the drop command for Affixed nodes (Parameter, Port).
- * This method uses PortPositionLocator used by both Port and Parameter.
- * If the dropped element is a Port, the graphical parent can be :
- * - a Class that owns or inherits the Port
- * - a Property which type owns or inherits the Port
- * </pre>
- *
- * @param dropRequest
- * the drop request
- * @param droppedElement
- * the element to drop
- * @param nodeVISUALID
- * the visual identifier of the EditPart of the dropped element
- * @return the drop command
- */
- protected Command dropAffixedNode(DropObjectsRequest dropRequest, Element droppedElement, int nodeVISUALID) {
- // The dropped element must be a Port or Parameter
- if (!((droppedElement instanceof Port) || (droppedElement instanceof Parameter))) {
- Log.getInstance().error(new Exception("Incorrect parameter type (droppedElement should be a Port or Parameter)"));
- return UnexecutableCommand.INSTANCE;
- }
- // Manage Element drop in compartment
- Boolean isCompartmentTarget = false; // True if the target is a
- // ShapeCompartmentEditPart
- GraphicalEditPart graphicalParentEditPart = (GraphicalEditPart) getHost();
- // Default drop location
- Point dropLocation = dropRequest.getLocation().getCopy();
- // Detect if the drop target is a compartment
- if (graphicalParentEditPart instanceof ShapeCompartmentEditPart) {
- isCompartmentTarget = true;
- // Replace compartment edit part by its parent EditPart
- graphicalParentEditPart = (GraphicalEditPart) graphicalParentEditPart.getParent();
- // Translate Port expected location according to the compartment
- // location
- Point targetLocation = graphicalParentEditPart.getContentPane().getBounds().getLocation();
- ShapeCompartmentFigure compartmentFigure = (ShapeCompartmentFigure) getHostFigure();
- // Retrieve ViewPort location = the area where compartment children
- // are located
- // Retrieve ViewPort view location = the relative location of the
- // viewed compartment
- // depending on the current scroll bar state
- Viewport compartmentViewPort = compartmentFigure.getScrollPane().getViewport();
- Point compartmentViewPortLocation = compartmentViewPort.getLocation();
- Point compartmentViewPortViewLocation = compartmentViewPort.getViewLocation();
- // Calculate the delta between the targeted element position for
- // drop (the Composite figure)
- // and the View location with eventual scroll bar.
- Point delta = compartmentViewPortLocation.translate(targetLocation.negate());
- delta = delta.translate(compartmentViewPortViewLocation.negate());
- // Translate the requested drop location (relative to parent)
- dropLocation = dropRequest.getLocation().getTranslated(delta);
- }
- // If SideAffixedNodesCreationEditPolicy installed to the parent then delegate calculation of the real drop location to it
- if (!isSideAffixedNodesCreationPolicyInstalled(graphicalParentEditPart)) {
- Point parentLoc = graphicalParentEditPart.getFigure().getBounds().getLocation().getCopy();
- PortPositionLocator locator = new PortPositionLocator(graphicalParentEditPart.getFigure(), PositionConstants.NONE);
- Rectangle proposedBounds = new Rectangle(dropLocation, new Dimension(20, 20));
- proposedBounds = proposedBounds.getTranslated(parentLoc);
- Rectangle preferredBounds = locator.getPreferredLocation(proposedBounds);
- // Convert the calculated preferred bounds as relative to parent location
- Rectangle creationBounds = preferredBounds.getTranslated(parentLoc.getNegated());
- dropLocation = creationBounds.getLocation();
- }
- // Manage Element drop in compartment
- // Create proposed creation bounds and use the locator to find the
- // expected position
- EObject graphicalParentObject = graphicalParentEditPart.resolveSemanticElement();
- if ((graphicalParentObject instanceof EncapsulatedClassifier) && (((EncapsulatedClassifier) graphicalParentObject).getAllAttributes().contains(droppedElement))) {
- // Drop Port on StructuredClassifier
- if (isCompartmentTarget) {
- return getDropAffixedNodeInCompartmentCommand(nodeVISUALID, dropLocation, droppedElement);
- }
- return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropLocation, droppedElement));
- } else if (graphicalParentObject instanceof ConnectableElement) {
- // Drop Port on Part
- Type type = ((ConnectableElement) graphicalParentObject).getType();
- if ((type != null) && (type instanceof EncapsulatedClassifier) && (((EncapsulatedClassifier) type).getAllAttributes().contains(droppedElement))) {
- if (isCompartmentTarget) {
- return getDropAffixedNodeInCompartmentCommand(nodeVISUALID, dropLocation, droppedElement);
- }
- return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropLocation, droppedElement));
- }
- } else if ((graphicalParentObject instanceof Behavior) && (((Behavior) graphicalParentObject).getOwnedParameters().contains(droppedElement))) {
- // Drop Parameter on Behavior
- if (isCompartmentTarget) {
- return getDropAffixedNodeInCompartmentCommand(nodeVISUALID, dropLocation, droppedElement);
- }
- return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropLocation, droppedElement));
- }
- return UnexecutableCommand.INSTANCE;
- }
-
- private boolean isSideAffixedNodesCreationPolicyInstalled(IGraphicalEditPart editPart) {
- EditPolicy policy = editPart.getEditPolicy(EditPolicyRoles.CREATION_ROLE);
- if (policy == null && false == policy instanceof CustomizableDropEditPolicy) {
- return false;
- }
- EditPolicy defaultCreationPolicy = ((CustomizableDropEditPolicy) policy).getDefaultCreationPolicy();
- return defaultCreationPolicy != null && defaultCreationPolicy instanceof SideAffixedNodesCreationEditPolicy;
- }
-
- /**
- * <pre>
* This method return a drop command for TopLevelNode.
* It returns an {@link org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand} in
* case the element is dropped on a canvas referencing a domain element that is not a Package.
@@ -628,33 +509,6 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
}
/**
- * <pre>
- * This method returns the drop command for AffixedNode (Port, Parameter)
- * in case the node is dropped on a ShapeCompartmentEditPart.
- * </pre>
- *
- * @param nodeVISUALID
- * the node visual identifier
- * @param location
- * the drop location
- * @param droppedObject
- * the object to drop
- * @return a CompositeCommand for Drop
- */
- protected CompoundCommand getDropAffixedNodeInCompartmentCommand(int nodeVISUALID, Point location, EObject droppedObject) {
- CompoundCommand cc = new CompoundCommand("Drop");
- IAdaptable elementAdapter = new EObjectAdapter(droppedObject);
- ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, ((IHintedType) getUMLElementType(nodeVISUALID)).getSemanticHint(), ViewUtil.APPEND, true, getDiagramPreferencesHint());
- // Create the command targeting host parent (owner of the
- // ShapeCompartmentEditPart)
- CreateViewCommand createCommand = new CreateViewCommand(getEditingDomain(), descriptor, ((View) (getHost().getParent().getModel())));
- cc.add(new ICommandProxy(createCommand));
- SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) createCommand.getCommandResult().getReturnValue(), location);
- cc.add(new ICommandProxy(setBoundsCommand));
- return cc;
- }
-
- /**
* Avoid dropped element to get orphaned for DND action resulting in a
* specific action (not a move).
*
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/CustomDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/CustomDiagramDragDropEditPolicy.java
index 5d42655bfca..b19b3cfcbc9 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/CustomDiagramDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/CustomDiagramDragDropEditPolicy.java
@@ -20,12 +20,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.Viewport;
-import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
@@ -33,30 +28,20 @@ import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
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.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.figures.ShapeCompartmentFigure;
-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.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy;
-import org.eclipse.papyrus.uml.diagram.composite.custom.edit.command.CreateViewCommand;
import org.eclipse.papyrus.uml.diagram.composite.custom.helper.CollaborationHelper;
import org.eclipse.papyrus.uml.diagram.composite.custom.helper.CompositeLinkMappingHelper;
import org.eclipse.papyrus.uml.diagram.composite.custom.helper.ConnectorHelper;
import org.eclipse.papyrus.uml.diagram.composite.custom.helper.DurationObservationHelper;
import org.eclipse.papyrus.uml.diagram.composite.custom.helper.TimeObservationHelper;
import org.eclipse.papyrus.uml.diagram.composite.custom.helper.TypeHelper;
-import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator;
-import org.eclipse.papyrus.uml.diagram.composite.custom.log.Log;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActivityCompositeEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActivityCompositeEditPartCN;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActorEditPart;
@@ -126,7 +111,6 @@ import org.eclipse.papyrus.uml.diagram.composite.edit.parts.UseCaseEditPart;
import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry;
import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes;
import org.eclipse.uml2.uml.Association;
-import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Collaboration;
@@ -137,8 +121,6 @@ import org.eclipse.uml2.uml.Connector;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.DurationObservation;
import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.EncapsulatedClassifier;
-import org.eclipse.uml2.uml.Parameter;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.StructuredClassifier;
@@ -540,118 +522,6 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
}
/**
- * <pre>
- * Returns the drop command for Affixed nodes (Parameter, Port).
- * This method uses PortPositionLocator used by both Port and Parameter.
- * If the dropped element is a Port, the graphical parent can be :
- * - a Class that owns or inherits the Port
- * - a Property which type owns or inherits the Port
- * </pre>
- *
- * @param dropRequest
- * the drop request
- * @param location
- * the location to drop the element
- * @param droppedElement
- * the element to drop
- * @param nodeVISUALID
- * the visual identifier of the EditPart of the dropped element
- * @return the drop command
- */
- protected Command dropAffixedNode(DropObjectsRequest dropRequest, Element droppedElement, int nodeVISUALID) {
-
- // The dropped element must be a Port or Parameter
- if (!((droppedElement instanceof Port) || (droppedElement instanceof Parameter))) {
- Log.getInstance().error(new Exception("Incorrect parameter type (droppedElement should be a Port or Parameter)"));
- return UnexecutableCommand.INSTANCE;
- }
-
- // Manage Element drop in compartment
- Boolean isCompartmentTarget = false; // True if the target is a
- // ShapeCompartmentEditPart
- GraphicalEditPart graphicalParentEditPart = (GraphicalEditPart) getHost();
-
- // Default drop location
- Point dropLocation = dropRequest.getLocation().getCopy();
-
- // Detect if the drop target is a compartment
- if (graphicalParentEditPart instanceof ShapeCompartmentEditPart) {
- isCompartmentTarget = true;
-
- // Replace compartment edit part by its parent EditPart
- graphicalParentEditPart = (GraphicalEditPart) graphicalParentEditPart.getParent();
-
- // Translate Port expected location according to the compartment
- // location
- Point targetLocation = graphicalParentEditPart.getContentPane().getBounds().getLocation();
- ShapeCompartmentFigure compartmentFigure = (ShapeCompartmentFigure) getHostFigure();
-
- // Retrieve ViewPort location = the area where compartment children
- // are located
- // Retrieve ViewPort view location = the relative location of the
- // viewed compartment
- // depending on the current scroll bar state
- Viewport compartmentViewPort = compartmentFigure.getScrollPane().getViewport();
- Point compartmentViewPortLocation = compartmentViewPort.getLocation();
- Point compartmentViewPortViewLocation = compartmentViewPort.getViewLocation();
-
- // Calculate the delta between the targeted element position for
- // drop (the Composite figure)
- // and the View location with eventual scroll bar.
- Point delta = compartmentViewPortLocation.translate(targetLocation.negate());
- delta = delta.translate(compartmentViewPortViewLocation.negate());
-
- // Translate the requested drop location (relative to parent)
- dropLocation = dropRequest.getLocation().getTranslated(delta);
- }
- // Manage Element drop in compartment
-
- // Create proposed creation bounds and use the locator to find the
- // expected position
- Point parentLoc = graphicalParentEditPart.getFigure().getBounds().getLocation().getCopy();
- PortPositionLocator locator = new PortPositionLocator(graphicalParentEditPart.getFigure(), PositionConstants.NONE);
-
- Rectangle proposedBounds = new Rectangle(dropLocation, new Dimension(20, 20));
- proposedBounds = proposedBounds.getTranslated(parentLoc);
- Rectangle preferredBounds = locator.getPreferredLocation(proposedBounds);
-
- // Convert the calculated preferred bounds as relative to parent
- // location
- Rectangle creationBounds = preferredBounds.getTranslated(parentLoc.getNegated());
- dropLocation = creationBounds.getLocation();
-
- EObject graphicalParentObject = graphicalParentEditPart.resolveSemanticElement();
-
- if ((graphicalParentObject instanceof EncapsulatedClassifier) && (((EncapsulatedClassifier) graphicalParentObject).getAllAttributes().contains(droppedElement))) {
- // Drop Port on StructuredClassifier
- if (isCompartmentTarget) {
- return getDropAffixedNodeInCompartmentCommand(nodeVISUALID, dropLocation, droppedElement);
- }
- return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropLocation, droppedElement));
-
- } else if (graphicalParentObject instanceof ConnectableElement) {
- // Drop Port on Part
- Type type = ((ConnectableElement) graphicalParentObject).getType();
-
- if ((type != null) && (type instanceof EncapsulatedClassifier) && (((EncapsulatedClassifier) type).getAllAttributes().contains(droppedElement))) {
- if (isCompartmentTarget) {
- return getDropAffixedNodeInCompartmentCommand(nodeVISUALID, dropLocation, droppedElement);
- }
- return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropLocation, droppedElement));
- }
-
- } else if ((graphicalParentObject instanceof Behavior) && (((Behavior) graphicalParentObject).getOwnedParameters().contains(droppedElement))) {
- // Drop Parameter on Behavior
- if (isCompartmentTarget) {
- return getDropAffixedNodeInCompartmentCommand(nodeVISUALID, dropLocation, droppedElement);
- }
- return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropLocation, droppedElement));
- }
-
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
* Returns the drop command for DurationObservation nodes.
*
* @param dropRequest
@@ -736,36 +606,6 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
/**
* <pre>
- * This method returns the drop command for AffixedNode (Port, Parameter)
- * in case the node is dropped on a ShapeCompartmentEditPart.
- * </pre>
- *
- * @param nodeVISUALID
- * the node visual identifier
- * @param location
- * the drop location
- * @param droppedObject
- * the object to drop
- * @return a CompositeCommand for Drop
- */
- protected CompoundCommand getDropAffixedNodeInCompartmentCommand(int nodeVISUALID, Point location, EObject droppedObject) {
- CompoundCommand cc = new CompoundCommand("Drop");
- IAdaptable elementAdapter = new EObjectAdapter(droppedObject);
-
- ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, ((IHintedType) getUMLElementType(nodeVISUALID)).getSemanticHint(), ViewUtil.APPEND, true, getDiagramPreferencesHint());
- // Create the command targeting host parent (owner of the
- // ShapeCompartmentEditPart)
- CreateViewCommand createCommand = new CreateViewCommand(getEditingDomain(), descriptor, ((View) (getHost().getParent().getModel())));
- cc.add(new ICommandProxy(createCommand));
-
- SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) createCommand.getCommandResult().getReturnValue(), location);
- cc.add(new ICommandProxy(setBoundsCommand));
-
- return cc;
- }
-
- /**
- * <pre>
* This method is overridden to provide DND support to element that are not
* expected relatively to GMF declarations (e.g. : Drop Class on Collaboration).
* In such a case, the VisualID of the dropped element cannot be retrieved, because
@@ -817,7 +657,7 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
CollaborationHelper helper = new CollaborationHelper(getEditingDomain());
cc.add(helper.dropCollaborationAsCollaborationUse((GraphicalEditPart) getHost(), (Collaboration) droppedObject, location));
- }
+ }
} else if (graphicalParentObject instanceof TypedElement) {
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestPortLocation.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestPortLocation.java
index fa9bee5627c..672c6a67a69 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestPortLocation.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestPortLocation.java
@@ -2,7 +2,6 @@ package org.eclipse.papyrus.uml.diagram.composite.test.canonical;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.papyrus.commands.ICreationCommand;
-import org.eclipse.papyrus.junit.framework.classification.FailingTest;
import org.eclipse.papyrus.uml.diagram.composite.CreateCompositeDiagramCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes;
@@ -26,37 +25,31 @@ public class TestPortLocation extends org.eclipse.papyrus.uml.diagram.tests.cano
return ICompositeDiagramTestsConstants.FILE_NAME;
}
- @FailingTest
@Test
public void testStateMachinePortLocation() {
testPortLocation(UMLElementTypes.StateMachine_2063);
}
- @FailingTest
@Test
public void testProtocolStateMachinePortLocation() {
testPortLocation(UMLElementTypes.ProtocolStateMachine_2062);
}
- @FailingTest
@Test
public void testInteractionItemPortLocation() {
testPortLocation(UMLElementTypes.Interaction_2061);
}
- @FailingTest
@Test
public void testClassPortLocation() {
testPortLocation(UMLElementTypes.Class_2073);
}
- @FailingTest
@Test
public void testClassPartPortLocation() {
testPortLocation(UMLElementTypes.Class_2073, ClassCompositeCompartmentEditPart.VISUAL_ID, UMLElementTypes.Property_3070);
}
- @FailingTest
@Test
public void testActivityPortLocation() {
testPortLocation(UMLElementTypes.Activity_2060);

Back to the top