Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2018-04-19 08:49:59 -0400
committerCamille Letavernier2018-04-19 08:50:16 -0400
commitc303ad37c80ed467ab62237359cd016bfe5a6a59 (patch)
tree89e8dccb542f32abce500e748ff857c97522a037
parent9795d6a6d23ed40a5fe31b89c6868e9c407a5edb (diff)
downloadorg.eclipse.papyrus-c303ad37c80ed467ab62237359cd016bfe5a6a59.tar.gz
org.eclipse.papyrus-c303ad37c80ed467ab62237359cd016bfe5a6a59.tar.xz
org.eclipse.papyrus-c303ad37c80ed467ab62237359cd016bfe5a6a59.zip
Bug 533770: [Sequence Diagram] Layout operands in a CombinedFragment
https://bugs.eclipse.org/bugs/show_bug.cgi?id=533770 - Initial version of the new Layout, based on Operand's height. This version disables the resizing of Operands for now. In general, the resize of Operands must be centralized by the CombinedFragment or CF Compartment (TODO) Change-Id: Ie8d4a8185c13b02a77b9929a6004bfed3fd85d03 Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentCombinedFragmentCompartmentEditPart.java47
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java28
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/layout/SwimlanesCompartmentLayout.java290
3 files changed, 311 insertions, 54 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentCombinedFragmentCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentCombinedFragmentCompartmentEditPart.java
index da61138845c..10d4e1367a0 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentCombinedFragmentCompartmentEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentCombinedFragmentCompartmentEditPart.java
@@ -14,17 +14,11 @@
package org.eclipse.papyrus.uml.diagram.sequence.edit.parts;
import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin;
-import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.BoundForEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.util.LogOptions;
+import org.eclipse.papyrus.uml.diagram.sequence.figures.layout.SwimlanesCompartmentLayout;
/**
* This class has been modified for 2 reasons:
@@ -50,13 +44,7 @@ public class CCombinedFragmentCombinedFragmentCompartmentEditPart extends Combin
*/
@Override
protected void refreshBounds() {
- int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue();
- int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue();
- Dimension size = new Dimension(width, height);
- int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue();
- int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue();
- Point loc = new Point(x, y);
- ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), new Rectangle(loc, size));
+ super.refreshBounds();
// this code has been added in order to force the refresh of Sub Combined fragment
if (children != null) {
@@ -69,24 +57,19 @@ public class CCombinedFragmentCombinedFragmentCompartmentEditPart extends Combin
}
/**
- * This code is specific an use to constraint the size of sub compartments.
- * the ratio has to be recompute in order to have a good display
+ * @see org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentCombinedFragmentCompartmentEditPart#createFigure()
*
- * @see GraphicalEditPart#setLayoutConstraint(EditPart, IFigure, Object)
+ * @return
*/
@Override
- public void setLayoutConstraint(EditPart child, IFigure childFigure,
- Object childConstraint) {
- EditPart parentEditPart = this.getParent();
- // compute the ratio for each children
- int parentHeight = BoundForEditPart.getHeightFromView((Node) parentEditPart.getModel())-27;
- if (childConstraint instanceof Rectangle) {
- double ratio = ((double) ((Rectangle) childConstraint).height) / parentHeight;
- if (ratio >= 1.0) {
- ratio = 0.95;
- }
- UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, ((Rectangle) childConstraint).height +"--> ratio" + ratio); //$NON-NLS-1$
- childFigure.getParent().setConstraint(childFigure, ratio);
- }
+ public IFigure createFigure() {
+ ResizableCompartmentFigure rcf = (ResizableCompartmentFigure) super.createFigure();
+ SwimlanesCompartmentLayout layout = new SwimlanesCompartmentLayout();
+ layout.setStretchMajorAxis(false);
+ layout.setStretchMinorAxis(true);
+ layout.setMinorAlignment(ConstrainedToolbarLayout.ALIGN_TOPLEFT);
+ rcf.getContentPane().setLayoutManager(layout);
+ rcf.getContentPane().setBorder(null);
+ return rcf;
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java
index 38d32b78fcb..cfb39f660ad 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java
@@ -28,6 +28,11 @@ public class InteractionOperandDragDropEditPolicy extends ResizableEditPolicy {
public InteractionOperandDragDropEditPolicy() {
super();
setDragAllowed(false);
+
+ // Bug 533770: The layout is now handled exclusively by the parent.
+ // The operand is no longer directly resizable. It may still provide
+ // a height hint (Integer or Rectangle, height in pixels)
+ setResizeDirections(0);
}
/**
@@ -35,27 +40,6 @@ public class InteractionOperandDragDropEditPolicy extends ResizableEditPolicy {
*/
@Override
protected Command getResizeCommand(ChangeBoundsRequest request) {
- Command cmd= super.getResizeCommand(request);
-// boolean isVertResize = (request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0;
-// boolean isHorResize = (request.getResizeDirection() & PositionConstants.EAST_WEST) != 0;
-// boolean isNorthResize = (request.getResizeDirection() & PositionConstants.NORTH) != 0;
-// boolean isSouthResize = (request.getResizeDirection() & PositionConstants.SOUTH) != 0;
-// if (isHorResize && !isVertResize) {
-// EditPart parent = getHost().getParent().getParent();
-// return parent.getCommand(request);
-// } else if (isVertResize) {
-// if (this.getHost() instanceof InteractionOperandEditPart && this.getHost().getParent() instanceof CombinedFragmentCombinedFragmentCompartmentEditPart) {
-// InteractionOperandEditPart currentIOEP = (InteractionOperandEditPart) this.getHost();
-// CombinedFragmentCombinedFragmentCompartmentEditPart compartEP = (CombinedFragmentCombinedFragmentCompartmentEditPart) this.getHost().getParent();
-// // if the OP's border same as/linked to the CF's border
-// if (this.getHost() == OperandBoundsComputeHelper.findFirstIOEP(compartEP) && isNorthResize
-// || this.getHost() == OperandBoundsComputeHelper.findLastIOEP(compartEP) && isSouthResize) {
-// return getHost().getParent().getParent().getCommand(request);
-// } else {
-// return OperandBoundsComputeHelper.createIOEPResizeCommand(currentIOEP, request, compartEP);
-// }
-// }
-// }
- return cmd;
+ return super.getResizeCommand(request);
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/layout/SwimlanesCompartmentLayout.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/layout/SwimlanesCompartmentLayout.java
new file mode 100644
index 00000000000..925925120a3
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/layout/SwimlanesCompartmentLayout.java
@@ -0,0 +1,290 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource and others.
+ *
+ * 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:
+ * EclipseSource - Initial API and implementation: Bug 533770
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.sequence.figures.layout;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.LayoutManager;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
+
+/**
+ * <p>
+ * A {@link LayoutManager} which places children vertically. Children
+ * are expected to have an integer height constraint, specified in pixels.
+ * </p>
+ * <p>
+ * The children will get their requested size if possible, and will always take all available width.
+ * Otherwise, the following will happen:
+ * <ul>
+ * <li>If the total height of children is higher than the height of the compartment,
+ * the last child(ren) will be smaller than requested (And may ultimately get a size of 0).</li>
+ * <li>If the total height of children is smaller than the height of the compartment,
+ * the last child will be expanded</li>
+ * </ul>
+ * </p>
+ */
+// Note: this compartment can be generalized; but for now it has only been tested/applied
+// on CombinedFragments for InteractionOperands, in the SequenceDiagram. If you want to use
+// it in other contexts, you may move that class to a more general bundle; but don't forget
+// to test/implement missing cases (Typically, horizontal layout is not properly supported)
+public class SwimlanesCompartmentLayout extends ConstrainedToolbarLayout {
+
+ private Map<IFigure, Integer> constraints;
+
+ // The implementation mostly comes from the parent class, with some small variations:
+ // - The layout constraint is an Integer (Height value, in pixels) rather than a Ratio
+ // - Last elements are either expanded or shrank, if the size doesn't perfectly match
+ // the compartment. Other elements get exactly their requested size.
+ @Override
+ public void layout(IFigure parent) {
+ if (!parent.isVisible()) {
+ return;
+ }
+ List<IFigure> children = getChildren(parent);
+ int numChildren = children.size();
+ // FIXME: When the CF is small (< ~120px), the ClientArea is bigger than what's really available
+ // for the compartment. This means that Scrollbars immediately appear.
+ Rectangle clientArea = transposer.t(parent.getClientArea());
+ int x = clientArea.x;
+ int y = clientArea.y;
+ int availableHeight = clientArea.height;
+
+ Dimension prefSizes[] = new Dimension[numChildren];
+ Dimension minSizes[] = new Dimension[numChildren];
+ Dimension maxSizes[] = new Dimension[numChildren];
+
+ // Calculate the width and height hints. If it's a vertical ToolBarLayout,
+ // then ignore the height hint (set it to -1); otherwise, ignore the
+ // width hint. These hints will be passed to the children of the parent
+ // figure when getting their preferred size.
+ int wHint = -1;
+ int hHint = -1;
+ if (isHorizontal()) {
+ hHint = parent.getClientArea(Rectangle.SINGLETON).height;
+ } else {
+ wHint = parent.getClientArea(Rectangle.SINGLETON).width;
+ }
+
+ /*
+ * Calculate sum of preferred heights of all children(totalHeight).
+ * Calculate sum of minimum heights of all children(minHeight).
+ * Cache Preferred Sizes and Minimum Sizes of all children.
+ *
+ * totalHeight is the sum of the preferred heights of all children
+ * totalMinHeight is the sum of the minimum heights of all children
+ * prefMinSumHeight is the sum of the difference between all children's
+ * preferred heights and minimum heights. (This is used as a ratio to
+ * calculate how much each child will shrink).
+ */
+ IFigure child;
+ int totalHeight = 0;
+ int totalMinHeight = 0;
+ double totalMaxHeight = 0;
+ int prefMinSumHeight = 0;
+ double prefMaxSumHeight = 0;
+
+ for (int i = 0; i < numChildren; i++) {
+ child = children.get(i);
+
+ prefSizes[i] = transposer.t(child.getPreferredSize(wHint, hHint));
+ minSizes[i] = transposer.t(new Dimension(0, 0));
+ maxSizes[i] = transposer.t(child.getMaximumSize());
+
+ if (getConstraint(child) != null) {
+ int prefHeight = getConstraint(child);
+ prefHeight = Math.max(prefHeight, minSizes[i].height);
+ prefHeight = Math.min(prefHeight, maxSizes[i].height);
+ prefSizes[i].height = prefHeight;
+ }
+
+ totalHeight += prefSizes[i].height;
+ totalMinHeight += minSizes[i].height;
+ totalMaxHeight += maxSizes[i].height;
+ }
+
+ int spacing = getSpacing();
+
+ totalHeight += (numChildren - 1) * spacing;
+ totalMinHeight += (numChildren - 1) * spacing;
+ totalMaxHeight += (numChildren - 1) * spacing;
+ prefMinSumHeight = totalHeight - totalMinHeight;
+ prefMaxSumHeight = totalMaxHeight - totalHeight;
+
+ /*
+ * The total amount that the children must be shrunk is the
+ * sum of the preferred Heights of the children minus
+ * Max(the available area and the sum of the minimum heights of the children).
+ *
+ * amntShrinkHeight is the combined amount that the children must shrink
+ * amntShrinkCurrentHeight is the amount each child will shrink respectively
+ */
+ int amntShrinkHeight = totalHeight - Math.max(availableHeight, totalMinHeight);
+
+ int maxY = y + availableHeight;
+
+ for (int i = 0; i < numChildren; i++) {
+ int amntShrinkCurrentHeight = 0;
+ int prefHeight = prefSizes[i].height;
+ int minHeight = minSizes[i].height;
+ int maxHeight = maxSizes[i].height;
+ int prefWidth = prefSizes[i].width;
+ int minWidth = minSizes[i].width;
+ int maxWidth = maxSizes[i].width;
+ Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
+
+ child = children.get(i);
+ if (getStretchMajorAxis()) {
+ if (amntShrinkHeight > 0 && prefMinSumHeight != 0) {
+ amntShrinkCurrentHeight = (int) ((long) (prefHeight - minHeight)
+ * amntShrinkHeight / (prefMinSumHeight));
+ } else if (amntShrinkHeight < 0 && totalHeight != 0) {
+ amntShrinkCurrentHeight = (int) (((maxHeight - prefHeight) / prefMaxSumHeight)
+ * amntShrinkHeight);
+ }
+ }
+
+ int width = Math.min(prefWidth, maxWidth);
+ if (isStretchMinorAxis()) {
+ width = maxWidth;
+ }
+ width = Math.max(minWidth, Math.min(clientArea.width, width));
+ // FIXME For InteractionOperand, the width is 2 pixels too big. Why?
+ // It seems that the clientArea includes the border (Even though the border should be on the outside)
+ newBounds.width = width;
+
+ int adjust = clientArea.width - width;
+ switch (getMinorAlignment()) {
+ case ALIGN_TOPLEFT:
+ adjust = 0;
+ break;
+ case ALIGN_CENTER:
+ adjust /= 2;
+ break;
+ case ALIGN_BOTTOMRIGHT:
+ break;
+ }
+ newBounds.x += adjust;
+ if (newBounds.height - amntShrinkCurrentHeight > maxHeight) {
+ amntShrinkCurrentHeight = newBounds.height - maxHeight;
+ }
+ if (amntShrinkHeight < 0 && i == numChildren - 1) {
+ amntShrinkCurrentHeight = amntShrinkHeight;
+ } else if (amntShrinkHeight > 0 && y > (maxY - newBounds.height)) {
+ amntShrinkCurrentHeight = newBounds.height - (maxY - y);
+ }
+ newBounds.height -= amntShrinkCurrentHeight;
+ child.setBounds(transposer.t(newBounds));
+ System.out.println(child.getBounds());
+
+ amntShrinkHeight -= amntShrinkCurrentHeight;
+ prefMinSumHeight -= (prefHeight - minHeight);
+ prefMaxSumHeight -= (maxHeight - prefHeight);
+ totalHeight -= prefHeight;
+ y += newBounds.height + spacing;
+ }
+ }
+
+ @Override
+ protected Dimension getChildPreferredSize(IFigure child, int wHint, int hHint) {
+ return super.getChildPreferredSize(child, wHint, hHint);
+ }
+
+ @Override
+ protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
+ // Return the smallest non-empty value, so that we get exactly the
+ // height we were assigned, and no scrollbars
+ return new Dimension(1, 1);
+ }
+
+ /**
+ * Sets the constraint for the given figure.
+ *
+ * @param child
+ * the child
+ * @param constraint
+ * the child's new constraint. Supported values are <code>null</code> (remove),
+ * {@link Integer} (height in pixels) or {@link Rectangle} (Height in pixels; position and width will be ignored).
+ * Other values are silently ignored.
+ */
+ @Override
+ public void setConstraint(IFigure child, Object constraint) {
+ Integer height;
+ if (constraint instanceof Integer) {
+ height = (Integer) constraint; // Set new constraint
+ } else if (constraint instanceof Rectangle) {
+ height = ((Rectangle) constraint).getSize().height; // Set new constraint
+ } else if (constraint == null) {
+ height = null; // Remove the constraint
+ } else {
+ return; // Not supported, don't change anything
+ }
+ if (constraints == null) {
+ constraints = new HashMap<IFigure, Integer>();
+ }
+ if (height == null || height < 0) {
+ constraints.remove(child);
+ } else {
+ constraints.put(child, height);
+ }
+
+ invalidate();
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout#getConstraint(org.eclipse.draw2d.IFigure)
+ *
+ * @param child
+ * @return
+ */
+ @Override
+ public Integer getConstraint(IFigure child) {
+ return constraints.containsKey(child) ? constraints.get(child) : 0;
+ }
+
+ protected List<IFigure> getChildren(IFigure parent) {
+ @SuppressWarnings("unchecked")
+ List<IFigure> children = new ArrayList<>(parent.getChildren());
+ if (getIgnoreInvisibleChildren()) {
+ Iterator<IFigure> iter = children.iterator();
+ while (iter.hasNext()) {
+ IFigure f = iter.next();
+ if (!f.isVisible()) {
+ iter.remove();
+ }
+ }
+ }
+ if (isReversed()) {
+ Collections.reverse(children);
+ }
+ return children;
+ }
+
+ @Override
+ public void setHorizontal(boolean flag) {
+ if (flag) {
+ // This is not implemented yet; so just make sure we don't accidentally use it...
+ throw new UnsupportedOperationException("Horizontal layout is not supported");
+ }
+ super.setHorizontal(flag);
+ }
+
+}

Back to the top