summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/com/vaadin/client/connectors/GridConnector.java2
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java80
-rw-r--r--server/src/com/vaadin/ui/Grid.java97
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java6
-rw-r--r--shared/src/com/vaadin/shared/ui/grid/GridColumnState.java9
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java25
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java87
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java11
8 files changed, 260 insertions, 57 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java
index 237d026e5a..82fe3d9279 100644
--- a/client/src/com/vaadin/client/connectors/GridConnector.java
+++ b/client/src/com/vaadin/client/connectors/GridConnector.java
@@ -1005,6 +1005,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements
column.setSortable(state.sortable);
+ column.setResizable(state.resizable);
+
column.setHeaderCaption(state.headerCaption);
column.setHidden(state.hidden);
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index 506b3fc876..1e1c89234b 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -4559,6 +4559,8 @@ public class Grid<T> extends ResizeComposite implements
private boolean editable = true;
+ private boolean resizable = true;
+
private boolean hidden = false;
private boolean hidable = false;
@@ -4817,13 +4819,14 @@ public class Grid<T> extends ResizeComposite implements
}
/**
- * Enables sort indicators for the grid.
- * <p>
- * <b>Note:</b>The API can still sort the column even if this is set to
- * <code>false</code>.
+ * 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
+ * not affected by this setting.
*
* @param sortable
- * <code>true</code> when column sort indicators are visible.
+ * {@code true} if the user should be able to sort the
+ * column, {@code false} otherwise
* @return the column itself
*/
public Column<C, T> setSortable(boolean sortable) {
@@ -4833,20 +4836,59 @@ public class Grid<T> extends ResizeComposite implements
grid.refreshHeader();
}
}
-
return this;
}
/**
- * Are sort indicators shown for the 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 <code>true</code> if the column is sortable
+ * @return {@code true} if the column is sortable by the user,
+ * {@code false} otherwise
*/
public boolean isSortable() {
return sortable;
}
/**
+ * 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<C, T> setResizable(boolean resizable) {
+ if (this.resizable != resizable) {
+ this.resizable = resizable;
+ if (grid != null) {
+ grid.refreshHeader();
+ }
+ }
+ 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 resizable;
+ }
+
+ /**
* Hides or shows the column. By default columns are visible before
* explicitly hiding them.
*
@@ -4855,8 +4897,9 @@ public class Grid<T> extends ResizeComposite implements
* <code>true</code> to hide the column, <code>false</code>
* to show
*/
- public void setHidden(boolean hidden) {
+ public Column<C, T> setHidden(boolean hidden) {
setHidden(hidden, false);
+ return this;
}
private void setHidden(boolean hidden, boolean userOriginated) {
@@ -4895,11 +4938,11 @@ public class Grid<T> extends ResizeComposite implements
}
/**
- * 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,
- * <code>false</code> otherwise
+ * @return {@code true} if the column is currently hidden, {@code false}
+ * otherwise
*/
public boolean isHidden() {
return hidden;
@@ -4914,14 +4957,15 @@ public class Grid<T> extends ResizeComposite implements
*
* @since 7.5.0
* @param hidable
- * <code>true</code> if the user can hide this column,
- * <code>false</code> if not
+ * {@code true} the user can hide this column, {@code false}
+ * otherwise
*/
- public void setHidable(boolean hidable) {
+ public Column<C, T> setHidable(boolean hidable) {
if (this.hidable != hidable) {
this.hidable = hidable;
grid.columnHider.updateColumnHidable(this);
}
+ return this;
}
/**
@@ -4951,11 +4995,12 @@ public class Grid<T> extends ResizeComposite implements
* @param hidingToggleCaption
* the caption for the hiding toggle for this column
*/
- public void setHidingToggleCaption(String hidingToggleCaption) {
+ public Column<C, T> setHidingToggleCaption(String hidingToggleCaption) {
this.hidingToggleCaption = hidingToggleCaption;
if (isHidable()) {
grid.columnHider.updateHidingToggle(this);
}
+ return this;
}
/**
@@ -5512,7 +5557,8 @@ public class Grid<T> extends ResizeComposite implements
// XXX: Should add only once in preAttach/postAttach or when
// resizable status changes
// Only add resize handles to default header row for now
- if (staticRow instanceof HeaderRow
+ if (columns.get(cell.getColumn()).isResizable()
+ && staticRow instanceof HeaderRow
&& ((HeaderRow) staticRow).isDefault()) {
final int column = cell.getColumn();
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
diff --git a/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java b/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java
index 547a4a84ca..98fa553330 100644
--- a/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java
+++ b/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java
@@ -58,7 +58,7 @@ public class GridColumnState implements Serializable {
public Connector editorConnector;
/**
- * Are sorting indicators shown for a column. Default is false.
+ * Whether this column is sortable by the user
*/
public boolean sortable = false;
@@ -77,10 +77,10 @@ public class GridColumnState implements Serializable {
*/
public double minWidth = GridConstants.DEFAULT_MIN_WIDTH;
- /** Is the column currently hidden. */
+ /** Whether this column is currently hidden. */
public boolean hidden = false;
- /** Can the column be hidden by the UI. */
+ /** Whether the column can be hidden by the user. */
public boolean hidable = false;
/** The caption for the column hiding toggle. */
@@ -88,4 +88,7 @@ public class GridColumnState implements Serializable {
/** Column header caption */
public String headerCaption;
+
+ /** Whether this column is resizable by the user. */
+ public boolean resizable = true;
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
index 04d7cbbb09..e761df2b20 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
@@ -1008,6 +1008,18 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
}, c);
+ createBooleanAction("Resizable", getColumnProperty(c), true,
+ new Command<Grid, Boolean>() {
+
+ @Override
+ public void execute(Grid grid, Boolean value,
+ Object columnIndex) {
+ Object propertyId = getColumnProperty((Integer) columnIndex);
+ Column column = grid.getColumn(propertyId);
+ column.setResizable(value);
+ }
+ }, c);
+
createBooleanAction("Hidable", getColumnProperty(c),
isColumnHidableByDefault(c), new Command<Grid, Boolean>() {
@Override
@@ -1165,6 +1177,19 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}, c);
}
+
+ createBooleanAction("All columns resizable", "Columns", false,
+ new Command<Grid, Boolean>() {
+
+ @Override
+ public void execute(Grid c, Boolean value, Object data) {
+ for (Column col : grid.getColumns()) {
+ col.setResizable(value);
+ }
+
+ }
+ });
+
createBooleanAction("All columns hidable", "Columns", false,
new Command<Grid, Boolean>() {
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java
new file mode 100644
index 0000000000..827a132eb9
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid.basicfeatures.server;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.testbench.parallel.TestCategory;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+
+@TestCategory("grid")
+public class GridColumnResizeTest extends GridBasicFeaturesTest {
+
+ @Before
+ public void before() {
+ openTestURL();
+ }
+
+ @Test
+ public void testResizeHandlesPresentInDefaultHeader() {
+ for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
+ assertResizable(i, true);
+ }
+ }
+
+ @Test
+ public void testResizeHandlesNotInNonDefaultHeader() {
+ selectMenuPath("Component", "Header", "Prepend row");
+
+ for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
+ assertResizable(getGridElement().getHeaderCell(0, i), false);
+ assertResizable(getGridElement().getHeaderCell(1, i), true);
+ }
+ }
+
+ @Test
+ public void testResizeHandlesNotInFooter() {
+ selectMenuPath("Component", "Footer", "Visible");
+ for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
+ assertResizable(getGridElement().getFooterCell(0, i), false);
+ }
+ }
+
+ @Test
+ public void testToggleSetResizable() {
+ selectMenuPath("Component", "Columns", "Column 1", "Resizable");
+
+ for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
+ assertResizable(i, i != 1);
+ }
+
+ selectMenuPath("Component", "Columns", "Column 1", "Resizable");
+
+ for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
+ assertResizable(i, true);
+ }
+ }
+
+ private void assertResizable(int columnIndex, boolean resizable) {
+ assertResizable(getGridElement().getHeaderCell(0, columnIndex),
+ resizable);
+ }
+
+ private void assertResizable(GridCellElement cell, boolean resizable) {
+ assertEquals("Header resize handle present", resizable,
+ cell.isElementPresent(By
+ .cssSelector("div.v-grid-column-resize-handle")));
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java
index 024e54260a..eb3d8672b3 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java
@@ -40,17 +40,6 @@ import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
public class GridStructureTest extends GridBasicFeaturesTest {
@Test
- public void testResizeHandlesPresent() {
- openTestURL();
-
- // Test that all column headers contain resize handles
- for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
- assertFalse(getGridElement().getHeaderCell(0, i).findElement(
- By.cssSelector("div.v-grid-column-resize-handle")) == null);
- }
- }
-
- @Test
public void testRemovingAllColumns() {
setDebug(true);
openTestURL();