From 84533057435a99b0d0dfa9ea791de81921c1e260 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 2 Jun 2015 01:21:46 +0300 Subject: [PATCH] Render initially hidden columns correctly (#18030) Change-Id: I2d21daac01fc8c61290997bf37b4109a07676135 --- .../src/com/vaadin/client/widgets/Grid.java | 13 +++- .../grid/GridInitiallyHiddenColumns.java | 36 +++++++++ .../grid/GridInitiallyHiddenColumnsTest.java | 78 +++++++++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java 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 extends ResizeComposite implements // Register this grid instance with the column ((Column) 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 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 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 elements = findElements(By.className("v-grid-sidebar")); + return elements.isEmpty() ? null : elements.get(0); + } + +} -- 2.39.5