aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ahlroos <john@vaadin.com>2014-07-31 15:34:58 +0300
committerJohn Ahlroos <john@vaadin.com>2014-07-31 16:21:16 +0300
commitb51f6ebc0d0e60d20f40f4492e865d990b80ceb2 (patch)
treef7d74ee4cbaf5f2d497bf2aee4b00a9ac04f733b
parent6aeee90ccab579052452862e322b1c3ce0e0e51e (diff)
downloadvaadin-framework-b51f6ebc0d0e60d20f40f4492e865d990b80ceb2.tar.gz
vaadin-framework-b51f6ebc0d0e60d20f40f4492e865d990b80ceb2.zip
Fixes setting width before adding column to grid #13334
Change-Id: Iddc16a9b84b2d52b39d44280b3d73a656c971fd0
-rw-r--r--client/src/com/vaadin/client/ui/grid/Grid.java9
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridClientColumnPropertiesTest.java58
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java26
3 files changed, 83 insertions, 10 deletions
diff --git a/client/src/com/vaadin/client/ui/grid/Grid.java b/client/src/com/vaadin/client/ui/grid/Grid.java
index d946be3d9e..dbfaf15813 100644
--- a/client/src/com/vaadin/client/ui/grid/Grid.java
+++ b/client/src/com/vaadin/client/ui/grid/Grid.java
@@ -1193,14 +1193,7 @@ public class Grid<T> extends Composite implements
* @return pixel width of the column
*/
public int getWidth() {
- if (grid == null) {
- return width;
- } else {
- int index = findIndexOfColumn();
- ColumnConfiguration conf = grid.escalator
- .getColumnConfiguration();
- return conf.getColumnWidth(index);
- }
+ return width;
}
/**
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridClientColumnPropertiesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridClientColumnPropertiesTest.java
new file mode 100644
index 0000000000..c9e048cc7f
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridClientColumnPropertiesTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeatures;
+
+public class GridClientColumnPropertiesTest extends GridBasicClientFeaturesTest {
+
+ @Test
+ public void initialColumnWidths() {
+ openTestURL();
+
+ for (int col = 0; col < GridBasicClientFeatures.COLUMNS; col++) {
+ int width = getGridElement().getCell(0, col).getSize().getWidth();
+ if (col <= 6) {
+ // Growing column widths
+ assertEquals(50 + col * 25, width);
+ } else {
+ assertEquals(100, width);
+ }
+ }
+ }
+
+ @Test
+ public void testChangingColumnWidth() {
+ openTestURL();
+
+ selectMenuPath("Component", "Columns", "Column 0", "Width", "50px");
+ int width = getGridElement().getCell(0, 0).getSize().getWidth();
+ assertEquals(50, width);
+
+ selectMenuPath("Component", "Columns", "Column 0", "Width", "200px");
+ width = getGridElement().getCell(0, 0).getSize().getWidth();
+ assertEquals(200, width);
+
+ selectMenuPath("Component", "Columns", "Column 0", "Width", "auto");
+ width = getGridElement().getCell(0, 0).getSize().getWidth();
+ assertEquals(100, width);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java
index 7d4b29ba5d..1c9758b669 100644
--- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java
+++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java
@@ -145,13 +145,17 @@ public class GridBasicClientFeatures extends
final int c = col;
- grid.addColumn(new GridColumn<String, List<Data>>(
+ GridColumn<String, List<Data>> column = new GridColumn<String, List<Data>>(
createRenderer(Renderers.TEXT_RENDERER)) {
@Override
public String getValue(List<Data> row) {
return (String) row.get(c).value;
}
- });
+ };
+
+ column.setWidth(50 + c * 25);
+
+ grid.addColumn(column);
}
@@ -273,6 +277,24 @@ public class GridBasicClientFeatures extends
!grid.getColumn(index).isSortable());
}
}, "Component", "Columns", "Column " + i);
+ addMenuCommand("auto", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getColumn(index).setWidth(-1);
+ }
+ }, "Component", "Columns", "Column " + i, "Width");
+ addMenuCommand("50px", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getColumn(index).setWidth(50);
+ }
+ }, "Component", "Columns", "Column " + i, "Width");
+ addMenuCommand("200px", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getColumn(index).setWidth(200);
+ }
+ }, "Component", "Columns", "Column " + i, "Width");
}
}