diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2015-09-29 17:57:14 +0300 |
---|---|---|
committer | Johannes Dahlström <johannesd@vaadin.com> | 2015-10-08 13:10:46 +0300 |
commit | ed5b1f2c279c37ba80da179f92fd66a4e43342f9 (patch) | |
tree | 10b9f0017958a07ad517302c715d021b0faf853b /server | |
parent | ab5f80bb20550a04bb0b6cf0c2208863b41dcf91 (diff) | |
download | vaadin-framework-ed5b1f2c279c37ba80da179f92fd66a4e43342f9.tar.gz vaadin-framework-ed5b1f2c279c37ba80da179f92fd66a4e43342f9.zip |
Add API for setting Grid columns resizable (#16838)
By default columns can be drag-resized by the user. This can be changed on a
column-by-column basis.
Change-Id: I8354e270db9affe865d1444d6cccbe8c839a3b5b
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/Grid.java | 97 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java | 6 |
2 files changed, 77 insertions, 26 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 3907156265..8aa3e90929 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -3192,15 +3192,22 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } /** - * Sets whether the column should be sortable by the user. The grid can - * be sorted by a sortable column by clicking or tapping the column's - * default header. Programmatic sorting using the Grid.sort methods is + * Sets whether this column is sortable by the user. The grid can be + * sorted by a sortable column by clicking or tapping the column's + * default header. Programmatic sorting using the Grid#sort methods is * not affected by this setting. * * @param sortable - * <code>true</code> if the user should be able to sort the - * column, false otherwise + * {@code true} if the user should be able to sort the + * column, {@code false} otherwise * @return the column itself + * + * @throws IllegalStateException + * if the data source of the Grid does not implement + * {@link Sortable} + * @throws IllegalStateException + * if the data source does not support sorting by the + * property associated with this column */ public Column setSortable(boolean sortable) { checkColumnIsAttached(); @@ -3227,9 +3234,13 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } /** - * Returns whether the user is able to sort the grid by this column. + * Returns whether the user can sort the grid by this column. + * <p> + * <em>Note:</em> it is possible to sort by this column programmatically + * using the Grid#sort methods regardless of the returned value. * - * @return true if the column is sortable by the user, false otherwise + * @return {@code true} if the column is sortable by the user, + * {@code false} otherwise */ public boolean isSortable() { return state.sortable; @@ -3486,7 +3497,7 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } /** - * Is this column hidden. Default is {@code false}. + * Returns whether this column is hidden. Default is {@code false}. * * @since 7.5.0 * @return <code>true</code> if the column is currently hidden, @@ -3497,11 +3508,8 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } /** - * Set whether it is possible for the user to hide this column or not. - * Default is {@code false}. - * <p> - * <em>Note:</em> it is still possible to hide the column - * programmatically using {@link #setHidden(boolean)} + * Sets whether this column can be hidden by the user. Hidable columns + * can be hidden and shown via the sidebar menu. * * @since 7.5.0 * @param hidable @@ -3518,7 +3526,7 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } /** - * Is it possible for the the user to hide this column. Default is + * Returns whether this column can be hidden by the user. Default is * {@code false}. * <p> * <em>Note:</em> the column can be programmatically hidden using @@ -3533,6 +3541,38 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } /** + * Sets whether this column can be resized by the user. + * + * @since + * @param resizable + * {@code true} if this column should be resizable, + * {@code false} otherwise + */ + public Column setResizable(boolean resizable) { + if (resizable != getState().resizable) { + getState().resizable = resizable; + grid.markAsDirty(); + } + return this; + } + + /** + * Returns whether this column can be resized by the user. Default is + * {@code true}. + * <p> + * <em>Note:</em> the column can be programmatically resized using + * {@link #setWidth(double)} and {@link #setWidthUndefined()} regardless + * of the returned value. + * + * @since + * @return {@code true} if this column is resizable, {@code false} + * otherwise + */ + public boolean isResizable() { + return getState().resizable; + } + + /** * Writes the design attributes for this column into given element. * * @since 7.5.0 @@ -3546,11 +3586,25 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, protected void writeDesign(Element design, DesignContext designContext) { Attributes attributes = design.attributes(); GridColumnState def = new GridColumnState(); + + DesignAttributeHandler.writeAttribute("property-id", attributes, + getPropertyId(), null, Object.class); + // Sortable is a special attribute that depends on the container. DesignAttributeHandler.writeAttribute("sortable", attributes, isSortable(), null, boolean.class); DesignAttributeHandler.writeAttribute("editable", attributes, isEditable(), def.editable, boolean.class); + DesignAttributeHandler.writeAttribute("resizable", attributes, + isResizable(), def.resizable, boolean.class); + + DesignAttributeHandler.writeAttribute("hidable", attributes, + isHidable(), def.hidable, boolean.class); + DesignAttributeHandler.writeAttribute("hidden", attributes, + isHidden(), def.hidden, boolean.class); + DesignAttributeHandler.writeAttribute("hiding-toggle-caption", + attributes, getHidingToggleCaption(), null, String.class); + DesignAttributeHandler.writeAttribute("width", attributes, getWidth(), def.width, Double.class); DesignAttributeHandler.writeAttribute("min-width", attributes, @@ -3559,14 +3613,6 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, getMaximumWidth(), def.maxWidth, Double.class); DesignAttributeHandler.writeAttribute("expand", attributes, getExpandRatio(), def.expandRatio, Integer.class); - DesignAttributeHandler.writeAttribute("hidable", attributes, - isHidable(), def.hidable, boolean.class); - DesignAttributeHandler.writeAttribute("hidden", attributes, - isHidden(), def.hidden, boolean.class); - DesignAttributeHandler.writeAttribute("hiding-toggle-caption", - attributes, getHidingToggleCaption(), null, String.class); - DesignAttributeHandler.writeAttribute("property-id", attributes, - getPropertyId(), null, Object.class); } /** @@ -3585,11 +3631,15 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, setSortable(DesignAttributeHandler.readAttribute("sortable", attributes, boolean.class)); } - if (design.hasAttr("editable")) { setEditable(DesignAttributeHandler.readAttribute("editable", attributes, boolean.class)); } + if (design.hasAttr("resizable")) { + setResizable(DesignAttributeHandler.readAttribute("resizable", + attributes, boolean.class)); + } + if (design.hasAttr("hidable")) { setHidable(DesignAttributeHandler.readAttribute("hidable", attributes, boolean.class)); @@ -3602,6 +3652,7 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, setHidingToggleCaption(DesignAttributeHandler.readAttribute( "hiding-toggle-caption", attributes, String.class)); } + // Read size info where necessary. if (design.hasAttr("width")) { setWidth(DesignAttributeHandler.readAttribute("width", diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java index 94d611a98b..45c931201e 100644 --- a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java @@ -27,7 +27,7 @@ public class GridColumnDeclarativeTest extends GridDeclarativeTestBase { + "<colgroup>" + " <col sortable='' width='100' property-id='Column1'>" + " <col sortable=false max-width='200' expand='2' property-id='Column2'>" - + " <col sortable='' editable=false min-width='15' expand='1' property-id='Column3'>" + + " <col sortable='' editable=false resizable=false min-width='15' expand='1' property-id='Column3'>" + " <col sortable='' hidable='' hiding-toggle-caption='col 4' property-id='Column4'>" + " <col sortable='' hidden='' property-id='Column5'>" + "</colgroup>" // @@ -38,9 +38,9 @@ public class GridColumnDeclarativeTest extends GridDeclarativeTestBase { grid.addColumn("Column2", String.class).setMaximumWidth(200) .setExpandRatio(2).setSortable(false); grid.addColumn("Column3", String.class).setMinimumWidth(15) - .setExpandRatio(1).setEditable(false); + .setExpandRatio(1).setEditable(false).setResizable(false); grid.addColumn("Column4", String.class).setHidable(true) - .setHidingToggleCaption("col 4"); + .setHidingToggleCaption("col 4").setResizable(true); grid.addColumn("Column5", String.class).setHidden(true); // Remove the default header |