From a30f72f151a291511c04eee26da2486ddfabaefb Mon Sep 17 00:00:00 2001 From: Ansgar Radermacher Date: Mon, 23 Nov 2015 20:48:49 +0100 Subject: Bug 481773 - [State Machine Diagram] - Drop of an state inside a composite state lead to an unexpected layout --- .../policies/CustomStateMachineDiagramDragDropEditPolicy.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'plugins/uml') diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomStateMachineDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomStateMachineDiagramDragDropEditPolicy.java index e2f879926ed..9b433ee792c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomStateMachineDiagramDragDropEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomStateMachineDiagramDragDropEditPolicy.java @@ -455,14 +455,19 @@ public class CustomStateMachineDiagramDragDropEditPolicy extends CommonDiagramDr cc.compose(createState); cc.compose(createRegion); + // calculate position relative to graphical parent (passed position is absolute) + Rectangle parentBounds = graphicalParentEditPart.getFigure().getBounds().getCopy(); + graphicalParentEditPart.getFigure().translateToAbsolute(parentBounds); + Point relLocation = new Point(location.x - parentBounds.x, location.y - parentBounds.y); + // take care of the case when a simple state is dropped, then we should provide a reasonable size if (droppedElement.getRegions().isEmpty()) { // final state has default size 20 - int sizeHint = (droppedElement instanceof FinalState) ? 20 : 40; - setBoundsCommand = new CustomCompositeStateSetBoundsCommand(getEditingDomain(), null, descriptor, new Rectangle(location.x, location.y, sizeHint, sizeHint), false); + int sizeHint = (droppedElement instanceof FinalState) ? 20 : 60; + setBoundsCommand = new CustomCompositeStateSetBoundsCommand(getEditingDomain(), null, descriptor, new Rectangle(relLocation.x, relLocation.y, sizeHint, sizeHint), false); cc.compose(setBoundsCommand); } else { - setBoundsCommand = new CustomCompositeStateSetBoundsCommand(getEditingDomain(), null, descriptor, new Rectangle(location.x, location.y, -1, -1), true); + setBoundsCommand = new CustomCompositeStateSetBoundsCommand(getEditingDomain(), null, descriptor, new Rectangle(relLocation.x, relLocation.y, -1, -1), true); cc.compose(setBoundsCommand); // force compartment to be shown SetPropertyCommand showCompartment = new SetPropertyCommand(getEditingDomain(), (IAdaptable) createState.getCommandResult().getReturnValue(), "notation.View.visible", "Visibility", true) { -- cgit v1.2.3