From 39846ae08337d55a24d3d90a6350f8e565a5c27f Mon Sep 17 00:00:00 2001 From: Artur Date: Tue, 30 May 2017 16:24:58 +0300 Subject: Allow grid columns to optionally shrink to be narrower than contents Fixes #8548 --- server/src/main/java/com/vaadin/ui/Grid.java | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'server/src') diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index d5bdfe45e8..3ae03679cf 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -1472,9 +1472,12 @@ public class Grid extends AbstractListing implements HasComponents, * This defines the minimum guaranteed pixel width of the column * when it is set to expand. * + * @param pixels + * the minimum width for the column * @throws IllegalStateException * if the column is no longer attached to any grid * @see #setExpandRatio(int) + * @return the column itself */ public Column setMinimumWidth(double pixels) throws IllegalStateException { @@ -1501,6 +1504,57 @@ public class Grid extends AbstractListing implements HasComponents, return getState(false).minWidth; } + /** + * Sets whether the width of the contents in the column should be + * considered minimum width for this column. + *

+ * If this is set to true (default for backwards + * compatibility), then a column will not shrink to smaller than the + * width required to show the contents available when calculating the + * widths (only the widths of the initially rendered rows are + * considered). + *

+ * If this is set to false and the column has been set to + * expand using #setExpandRatio(int), then the contents of the column + * will be ignored when calculating the width, and the column will thus + * shrink down to the minimum width defined by #setMinimumWidth(double) + * if necessary. + * + * @param minimumWidthFromContent + * true to reserve space for all contents, + * false to allow the column to shrink smaller + * than the contents + * @return the column itself + * @throws IllegalStateException + * if the column is no longer attached to any grid + * @see #setMinimumWidth(double) + * @since + */ + public Column setMinimumWidthFromContent( + boolean minimumWidthFromContent) throws IllegalStateException { + checkColumnIsAttached(); + + if (isMinimumWidthFromContent() != minimumWidthFromContent) { + getState().minimumWidthFromContent = minimumWidthFromContent; + getGrid().markAsDirty(); + } + return this; + } + + /** + * Gets whether the width of the contents in the column should be + * considered minimum width for this column. + * + * @return true to reserve space for all contents, + * false to allow the column to shrink smaller than + * the contents + * @see #setMinimumWidthFromContent(boolean) + * @since + */ + public boolean isMinimumWidthFromContent() { + return getState(false).minimumWidthFromContent; + } + /** * Sets the maximum width for this column. *

-- cgit v1.2.3