Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsboyko2014-11-10 21:36:12 +0000
committersboyko2014-11-10 21:36:12 +0000
commit71dc5d82ed7f825bbd495bd7b6c8f613b558d98c (patch)
treea916ec0a74617c51e2956a6be2a60578a72b1420 /plugins/uml
parente6903132f559c8b3f73892be56b57aad53c9b31e (diff)
downloadorg.eclipse.papyrus-71dc5d82ed7f825bbd495bd7b6c8f613b558d98c.tar.gz
org.eclipse.papyrus-71dc5d82ed7f825bbd495bd7b6c8f613b558d98c.tar.xz
org.eclipse.papyrus-71dc5d82ed7f825bbd495bd7b6c8f613b558d98c.zip
Bug 443884 - [Sequence Diagram] Resizing of an overlapping executione
specification should resize the corresponding overlapped ESs Change-Id: Ib957863a7489876b3d6e10aa6943e23a2b5165b1 Signed-off-by: sboyko <serg.boyko2011@gmail.com>
Diffstat (limited to 'plugins/uml')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java81
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineXYLayoutEditPolicy.java20
2 files changed, 84 insertions, 17 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java
index e5a8094652d..85aa058014e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java
@@ -1,6 +1,7 @@
package org.eclipse.papyrus.uml.diagram.sequence.edit.parts;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import org.eclipse.draw2d.ConnectionAnchor;
@@ -22,6 +23,7 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gef.handles.HandleBounds;
import org.eclipse.gef.requests.ChangeBoundsRequest;
@@ -60,6 +62,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.LifelineXYLayoutEd
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.sequence.util.HighlightUtil;
import org.eclipse.papyrus.uml.diagram.sequence.util.LifelineEditPartUtil;
+import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
import org.eclipse.swt.graphics.Color;
import org.eclipse.uml2.uml.ExecutionSpecification;
@@ -141,25 +144,81 @@ public abstract class AbstractExecutionSpecificationEditPart extends ShapeNodeEd
@Override
protected Command getResizeCommand(ChangeBoundsRequest request) {
- // Bugfix: Avoid resize ES with the child size is little than parent one.
+ CompoundCommand command = new CompoundCommand();
+ command.add(super.getResizeCommand(request));
EditPart host = getHost();
+ LifelineEditPart lifelinePart = SequenceUtil.getParentLifelinePart(host);
+ // Calculate children levels
List<ShapeNodeEditPart> movedChildrenParts = LifelineXYLayoutEditPolicy.getAffixedExecutionSpecificationEditParts((ShapeNodeEditPart) host);
- Rectangle r = getInitialFeedbackBounds().getCopy();
- getHostFigure().translateToAbsolute(r);
- r.translate(0, request.getMoveDelta().y);
- r.resize(0, request.getSizeDelta().height);
+ List<ShapeNodeEditPart> testChildrenParts = new ArrayList<ShapeNodeEditPart>(movedChildrenParts);
+ HashMap<ShapeNodeEditPart, Integer> childrenLevels = new HashMap<ShapeNodeEditPart, Integer>();
+ Integer currentLevel = 0;
+ while (!testChildrenParts.isEmpty()) {
+ currentLevel ++;
+ List<ShapeNodeEditPart> testChildrenPartsNew = new ArrayList<ShapeNodeEditPart>(testChildrenParts);
+ HashMap<ShapeNodeEditPart, Integer> childrenLevelsNew = new HashMap<ShapeNodeEditPart, Integer>(childrenLevels);
+ for (ShapeNodeEditPart child : testChildrenParts) {
+ IFigure figure = child.getFigure();
+ Rectangle childRect = figure.getBounds().getCopy();
+ if (figure instanceof HandleBounds) {
+ childRect = ((HandleBounds) figure).getBounds().getCopy();
+ }
+ movedChildrenParts.remove(child);
+ ShapeNodeEditPart parentTest = LifelineXYLayoutEditPolicy.getParent(lifelinePart, childRect, movedChildrenParts);
+ movedChildrenParts.add(child);
+ if (childrenLevels.containsKey(parentTest) || parentTest == null) {
+ testChildrenPartsNew.remove(child);
+ childrenLevelsNew.put(child, currentLevel);
+ }
+ }
+ childrenLevels = childrenLevelsNew;
+ testChildrenParts = testChildrenPartsNew;
+ }
+ // Fetch basic coords
+ Rectangle rectRequest = getInitialFeedbackBounds().getCopy();
+ getHostFigure().translateToAbsolute(rectRequest);
+ rectRequest.translate(0, request.getMoveDelta().y);
+ rectRequest.resize(0, request.getSizeDelta().height);
for (ShapeNodeEditPart child : movedChildrenParts) {
IFigure figure = child.getFigure();
- Rectangle rect = figure.getBounds().getCopy();
+ Rectangle originalRect = figure.getBounds().getCopy();
if (figure instanceof HandleBounds) {
- rect = ((HandleBounds) figure).getBounds().getCopy();
+ originalRect = ((HandleBounds) figure).getBounds().getCopy();
}
- figure.translateToAbsolute(rect);
- if (rect.y < (r.y) || r.bottom() < (rect.y)) {
- return UnexecutableCommand.INSTANCE;
+ Integer level = childrenLevels.get(child);
+ Rectangle r = rectRequest.getCopy();
+ r.translate(0, level*LifelineXYLayoutEditPolicy.SPACING_HEIGHT);
+ r.resize(0, -2*level*LifelineXYLayoutEditPolicy.SPACING_HEIGHT);
+ Rectangle translatedRect = originalRect.getCopy();
+ figure.translateToAbsolute(translatedRect);
+ if (translatedRect.y < r.y || translatedRect.bottom() > r.bottom()) {
+ int moveAmount = 0;
+ int resizeAmount = 0;
+ if (translatedRect.y < r.y) {
+ moveAmount = r.y - translatedRect.y;
+ resizeAmount = moveAmount;
+ } else { // translatedRect.bottom() > r.bottom()
+ resizeAmount = translatedRect.bottom() - r.bottom();
+ }
+ if (translatedRect.height() - resizeAmount < figure.getMinimumSize().height()) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ // Resize child ES
+ ChangeBoundsRequest esRequest = new ChangeBoundsRequest(org.eclipse.gef.RequestConstants.REQ_MOVE);
+ esRequest.setEditParts(child);
+ esRequest.setResizeDirection(PositionConstants.SOUTH);
+ esRequest.setMoveDelta(new Point(0, moveAmount));
+ esRequest.setSizeDelta(new Dimension(0, -resizeAmount));
+ Command moveESCommand = LifelineXYLayoutEditPolicy.getResizeOrMoveChildrenCommand((LifelineEditPart) lifelinePart, esRequest, false, false, true);
+ if (moveESCommand != null && !moveESCommand.canExecute()) {
+ // forbid creation of the message if the es can't be moved correctly
+ return UnexecutableCommand.INSTANCE;
+ } else if (moveESCommand != null) {
+ command.add(moveESCommand);
+ }
}
}
- return super.getResizeCommand(request);
+ return command.unwrap();
}
@Override
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineXYLayoutEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineXYLayoutEditPolicy.java
index acdb91b3fa3..f65f3545959 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineXYLayoutEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineXYLayoutEditPolicy.java
@@ -84,7 +84,7 @@ public class LifelineXYLayoutEditPolicy extends XYLayoutEditPolicy {
private static final int TIME_BAR_HEIGHT = 1;
/** The default spacing used between Execution Specification */
- private final static int SPACING_HEIGHT = 5;
+ public final static int SPACING_HEIGHT = 5;
// private final static int MAX_CHILD_EXECUTION_DEPTH = 4;
// force location of time/duration elements and ES
@@ -384,7 +384,9 @@ public class LifelineXYLayoutEditPolicy extends XYLayoutEditPolicy {
Command p = new ICommandProxy(new SetBoundsCommand(editPart.getEditingDomain(), "Creation of an ExecutionSpecification", viewDescriptor, newBounds));
// resize parent bar
if (parent != null) {
- p = p.chain(resizeParentExecutionSpecification((LifelineEditPart) getHost(), parent, newBounds.getCopy(), executionSpecificationList));
+ Rectangle newAdjustedBounds = newBounds.getCopy();
+ newAdjustedBounds.height += LifelineXYLayoutEditPolicy.SPACING_HEIGHT;
+ p = p.chain(resizeParentExecutionSpecification((LifelineEditPart) getHost(), parent, newAdjustedBounds, executionSpecificationList));
}
return p;
}
@@ -394,20 +396,26 @@ public class LifelineXYLayoutEditPolicy extends XYLayoutEditPolicy {
childBounds.x = bounds.x;
childBounds.width = bounds.width;
Rectangle rect = bounds.getCopy();
- if (childBounds.y > rect.y) {
+ int spacingY = LifelineXYLayoutEditPolicy.SPACING_HEIGHT;
+ if (childBounds.y - spacingY < rect.y) {
+ rect.height += rect.y - childBounds.y + spacingY;
+ rect.y = childBounds.y - spacingY;
+ } else if (childBounds.bottom() + spacingY> rect.bottom()) {
+ rect.height = childBounds.bottom() - rect.y + spacingY;
+ } else {
return null;
}
- rect.height += rect.y - childBounds.y;
- rect.y = childBounds.y;
Rectangle newBounds = rect.getCopy();
CompoundCommand command = new CompoundCommand();
Command c = new ICommandProxy(new SetBoundsCommand(part.getEditingDomain(), "Resize of Parent Bar", part, newBounds.getCopy()));
command.add(c);
Point moveDelta = new Point(newBounds.x - bounds.x, newBounds.y - bounds.y);
- if (moveDelta.y != 0) {
+ Dimension sizeDelta = new Dimension(newBounds.width() - bounds.width(), newBounds.height() - bounds.height());
+ if (moveDelta.y != 0 || sizeDelta.height() != 0) {
ChangeBoundsRequest request = new ChangeBoundsRequest();
request.setEditParts(part);
request.setMoveDelta(moveDelta);
+ request.setSizeDelta(sizeDelta);
command = OccurrenceSpecificationMoveHelper.completeMoveExecutionSpecificationCommand(command, part, newBounds.getCopy(), request);
}
list.remove(part);

Back to the top