aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-06-02 01:21:46 +0300
committerArtur Signell <artur@vaadin.com>2015-06-05 22:15:50 +0000
commit84533057435a99b0d0dfa9ea791de81921c1e260 (patch)
tree7befe919883dfb42d0a1db8689558fc19064789f
parent220b407724791d7483f21d6a27d9957beee5a843 (diff)
downloadvaadin-framework-84533057435a99b0d0dfa9ea791de81921c1e260.tar.gz
vaadin-framework-84533057435a99b0d0dfa9ea791de81921c1e260.zip
Render initially hidden columns correctly (#18030)
Change-Id: I2d21daac01fc8c61290997bf37b4109a07676135
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java13
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java36
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java78
3 files changed, 125 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index 67220b6e07..1837f4c951 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -5384,8 +5384,17 @@ public class Grid<T> extends ResizeComposite implements
// Register this grid instance with the column
((Column<?, T>) column).setGrid(this);
- // Add to escalator
- escalator.getColumnConfiguration().insertColumns(index, 1);
+ // Grid knows about hidden columns, Escalator only knows about what is
+ // visible so column indexes do not match
+ if (!column.isHidden()) {
+ int escalatorIndex = index;
+ for (int existingColumn = 0; existingColumn < index; existingColumn++) {
+ if (getColumn(existingColumn).isHidden()) {
+ escalatorIndex--;
+ }
+ }
+ escalator.getColumnConfiguration().insertColumns(escalatorIndex, 1);
+ }
// Reapply column width
column.reapplyWidth();
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java b/uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java
new file mode 100644
index 0000000000..49b344bb85
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.fieldgroup.ComplexPerson;
+import com.vaadin.ui.Grid;
+
+public class GridInitiallyHiddenColumns extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid grid = new Grid();
+ grid.setContainerDataSource(ComplexPerson.createContainer(100));
+ grid.setColumns("firstName", "lastName", "age");
+ grid.getColumn("firstName").setHidden(true).setHidable(true);
+ grid.getColumn("lastName").setHidable(true);
+ grid.getColumn("age").setHidden(true).setHidable(true);
+
+ addComponent(grid);
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java b/uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java
new file mode 100644
index 0000000000..a3e941053a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class GridInitiallyHiddenColumnsTest extends SingleBrowserTest {
+
+ @Test
+ public void ensureCorrectlyRendered() {
+ openTestURL("debug");
+ GridElement grid = $(GridElement.class).first();
+ Assert.assertEquals("Rowling", grid.getCell(0, 0).getText());
+ Assert.assertEquals("Scott", grid.getCell(1, 0).getText());
+
+ getSidebarOpenButton(grid).click();
+ getColumnHidingToggle(grid, "First Name").click();
+ getColumnHidingToggle(grid, "Age").click();
+ getSidebarOpenButton(grid).click();
+
+ Assert.assertEquals("Umberto", grid.getCell(0, 0).getText());
+ Assert.assertEquals("Rowling", grid.getCell(0, 1).getText());
+ Assert.assertEquals("25", grid.getCell(0, 2).getText());
+ Assert.assertEquals("Dan", grid.getCell(1, 0).getText());
+ Assert.assertEquals("Scott", grid.getCell(1, 1).getText());
+ Assert.assertEquals("54", grid.getCell(1, 2).getText());
+
+ }
+
+ protected WebElement getSidebarOpenButton(GridElement grid) {
+ List<WebElement> elements = grid.findElements(By
+ .className("v-grid-sidebar-button"));
+ return elements.isEmpty() ? null : elements.get(0);
+ }
+
+ /**
+ * Returns the toggle inside the sidebar for hiding the column at the given
+ * index, or null if not found.
+ */
+ protected WebElement getColumnHidingToggle(GridElement grid, String caption) {
+ WebElement sidebar = getSidebar(grid);
+ List<WebElement> elements = sidebar.findElements(By
+ .className("column-hiding-toggle"));
+ for (WebElement e : elements) {
+ if (caption.equalsIgnoreCase(e.getText())) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ protected WebElement getSidebar(GridElement grid) {
+ List<WebElement> elements = findElements(By.className("v-grid-sidebar"));
+ return elements.isEmpty() ? null : elements.get(0);
+ }
+
+}