diff options
author | Céline Janssens | 2017-09-05 08:10:16 +0000 |
---|---|---|
committer | Patrick Tessier | 2017-11-08 15:53:49 +0000 |
commit | 0e41fffc4986c2d16c4f7faf5970f6004b2b62ef (patch) | |
tree | 986d61ad1043fdc612f581b69b0194337009ef20 | |
parent | be700575f22f626ef28117450af645e76a1aa147 (diff) | |
download | org.eclipse.papyrus-0e41fffc4986c2d16c4f7faf5970f6004b2b62ef.tar.gz org.eclipse.papyrus-0e41fffc4986c2d16c4f7faf5970f6004b2b62ef.tar.xz org.eclipse.papyrus-0e41fffc4986c2d16c4f7faf5970f6004b2b62ef.zip |
Bug 521688 : [Sequence Diagram] DND of Lifeline
- DND of Lifeline should be at the same y position than when created
from the palette
Change-Id: I42df23d1429f1458a8d56d18f91cbac2b01546f2
Signed-off-by: Céline Janssens <Celine.Janssens@all4tec.net>
2 files changed, 52 insertions, 1 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java index f6ac3e494d8..c2be66e004d 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java @@ -22,6 +22,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.gmf.runtime.notation.Style; import org.eclipse.gmf.runtime.notation.View; @@ -76,6 +77,35 @@ public class DiagramUtils { } /** + * Gets the diagram edit part associated to the given edit part + * + * @param part + * The edit part + * @return The diagram associated to the edit part, or <code>null</code> if none is found + * @since 3.1 + */ + public static DiagramEditPart getDiagramEditPartFrom(EditPart part) { + EditPart current; + + if (null != part) { + current = part; + } else { + return null; + } + + while (!(current instanceof DiagramEditPart)) { + if (null != current.getParent()) { + current = current.getParent(); + } else { + return null; + } + } + + return (DiagramEditPart) current; + } + + + /** * Gets the owner of a diagram as it will appear in the model explorer. * In the case where the diagram does not yet have a defined owner, the diagram's root element will be returned instead. * diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java index cc99249dc4b..47d8f873bca 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java @@ -30,6 +30,7 @@ import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalViewer; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; import org.eclipse.gef.commands.CompoundCommand; @@ -67,6 +68,7 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.papyrus.commands.wrappers.CommandProxyWithResult; import org.eclipse.papyrus.infra.gmfdiag.common.adapter.SemanticAdapter; import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil; +import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils; import org.eclipse.papyrus.uml.diagram.common.commands.DeferredCreateCommand; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.common.helper.DurationConstraintHelper; @@ -114,6 +116,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin; import org.eclipse.papyrus.uml.diagram.sequence.part.UMLVisualIDRegistry; import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes; import org.eclipse.papyrus.uml.diagram.sequence.util.CombinedFragmentMoveHelper; +import org.eclipse.papyrus.uml.diagram.sequence.util.CoordinateReferentialUtils; import org.eclipse.papyrus.uml.diagram.sequence.util.GateHelper; import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceLinkMappingHelper; import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceRequestConstant; @@ -217,6 +220,7 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo boolean someCombinedFragment = false; boolean someNonCombinedFragment = false; + List<?> editParts = ((ChangeBoundsRequest) request).getEditParts(); if (editParts != null) { @@ -438,9 +442,26 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo * @return the drop command if the Element can be dropped */ private Command dropNodeElement(Element element, String nodeVISUALID, Point location) { + if (LifelineEditPart.VISUAL_ID == nodeVISUALID) { - location.setY(50); + + // Work in the Absolute coordinate + Point diagramAbsoluteLocation = CoordinateReferentialUtils.transformPointFromScreenToDiagramReferential(location, (GraphicalViewer) getViewer()); + Point relativeFigurePosition = CoordinateReferentialUtils.getFigurePositionRelativeToDiagramReferential(getHostFigure(), DiagramUtils.getDiagramEditPartFrom(getHost())); + + diagramAbsoluteLocation.translate(relativeFigurePosition.getNegated()); + Point contentPaneRelativeLocation = CoordinateReferentialUtils.getFigurePositionRelativeToDiagramReferential(((GraphicalEditPart) getHost()).getContentPane().getParent(), DiagramUtils.getDiagramEditPartFrom(getHost())); + + // Force the Top position of the Lifeline + location.setY(10 + contentPaneRelativeLocation.y); + + + // Come back to the Relative screen referential + diagramAbsoluteLocation.translate(relativeFigurePosition); + location = CoordinateReferentialUtils.transformPointFromDiagramToScreenReferential(location, (GraphicalViewer) getViewer()); + } + Element parent = element.getOwner(); if (getHostObject().equals(parent)) { List<View> existingViews = DiagramEditPartsUtil.findViews(parent, getViewer()); |