Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormgolubev2014-05-28 23:04:31 +0000
committermgolubev2014-05-28 23:17:41 +0000
commit324f0733dcc1261c9fcfed7c50ba5f89e1cafe6b (patch)
tree044472d5c15e568c5a7db4db01807fc8fa7abf3f /plugins
parentf43f1804c19acc5a596a14ae4d573fef16fc1865 (diff)
downloadorg.eclipse.papyrus-324f0733dcc1261c9fcfed7c50ba5f89e1cafe6b.tar.gz
org.eclipse.papyrus-324f0733dcc1261c9fcfed7c50ba5f89e1cafe6b.tar.xz
org.eclipse.papyrus-324f0733dcc1261c9fcfed7c50ba5f89e1cafe6b.zip
[422827] - Comments in activity diagrams does not break text line when
resizing Change-Id: I97dc5b7abd9e85e797806a504a1de1884b130ffb Signed-off-by: mgolubev <golubev@montages.com>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/CompartmentXYLayoutEditPolicy.java70
1 files changed, 63 insertions, 7 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/CompartmentXYLayoutEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/CompartmentXYLayoutEditPolicy.java
index 877eaf0c9f9..fdf8bed4c31 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/CompartmentXYLayoutEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/CompartmentXYLayoutEditPolicy.java
@@ -13,22 +13,73 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.activity.edit.policies;
+import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
+import org.eclipse.papyrus.uml.diagram.activity.edit.parts.CommentEditPartCN;
/**
* This XY layout edit policy consults children parts for chosing a minimum
* size.
- *
- * @see XYLayoutEditPolicy
- *
+ * <p/>
+ * Special considerations made for reflowable edit parts, with minimum size depending on suggested width.
*/
public class CompartmentXYLayoutEditPolicy extends XYLayoutEditPolicy {
/**
- * Get the minimum size from child edit part rather than imposing a constant
- * one.
+ * Fix for #422827
+ * <p/>
+ * We would better override the Dimension.max() logic from the super class but it itself calls super.super so we can't easily do that.
+ * <p/>
+ * So we have to explicitly call {@link #getMinimumSizeForHint(GraphicalEditPart, Dimension)} and ensure that Dimension.max() logic in super-class
+ * does not affect results by returning something small from {@link #getMinimumSizeFor(GraphicalEditPart)}
+ */
+ @Override
+ protected Object getConstraintFor(Request request, GraphicalEditPart child, Rectangle rect) {
+ if(isReflowable(child) && request instanceof ChangeBoundsRequest) {
+ ChangeBoundsRequest reqImpl = (ChangeBoundsRequest)request;
+
+ Dimension sizeDelta = reqImpl.getSizeDelta();
+ if(sizeDelta.width != 0 || sizeDelta.height != 0) {
+ Dimension correctedMinSize = getMinimumSizeForHint(child, rect.getSize());
+ rect.setSize(Dimension.max(correctedMinSize, rect.getSize()));
+ }
+ }
+ return super.getConstraintFor(request, child, rect);
+ }
+
+ /**
+ * Called for reflowable editpart and allows them to compute minimum height based on suggested width.
+ *
+ * @return minimum size computed by using the given width as a hint.
+ */
+ protected Dimension getMinimumSizeForHint(GraphicalEditPart child, Dimension hint) {
+ IFigure figure = child.getFigure();
+ if(figure == null) {
+ return super.getMinimumSizeFor(child);
+ }
+ return figure.getMinimumSize(hint.width, -1);
+ }
+
+ /**
+ * Return true if editpart can reflow, that is if it minimum size
+ * is not static but depends on the width.
+ */
+ protected boolean isReflowable(GraphicalEditPart editPart) {
+ // for now we can check it this way to fix #422827
+ return editPart instanceof CommentEditPartCN;
+ // more general check will be available after fixing #429197
+ }
+
+ /**
+ * Get the static minimum size from child edit part rather than imposing a constant one.
+ * <p/>
+ * Bug #422827 is about this method called for reflowable comments, so the new version of this class should call
+ * {@link #getMinimumSizeForHint(GraphicalEditPart, Dimension)} instead.
*
* @see org.eclipse.gef.editpolicies.XYLayoutEditPolicy#getMinimumSizeFor(org.eclipse.gef.GraphicalEditPart)
* @param child
@@ -37,10 +88,15 @@ public class CompartmentXYLayoutEditPolicy extends XYLayoutEditPolicy {
*/
@Override
protected Dimension getMinimumSizeFor(GraphicalEditPart child) {
+ if(isReflowable(child)) {
+ //call from super class, we need to return something very small
+ //because this class will call getMinimumSizeForHint() anyway
+ return new Dimension(5, 5);
+ }
if(child.getFigure() != null) {
return child.getFigure().getMinimumSize();
- } else {
- return super.getMinimumSizeFor(child);
}
+ return super.getMinimumSizeFor(child);
}
+
}

Back to the top