]> source.dussan.org Git - vaadin-framework.git/commitdiff
Render initially hidden columns correctly (#18030)
authorArtur Signell <artur@vaadin.com>
Mon, 1 Jun 2015 22:21:46 +0000 (01:21 +0300)
committerArtur Signell <artur@vaadin.com>
Fri, 5 Jun 2015 22:15:50 +0000 (22:15 +0000)
Change-Id: I2d21daac01fc8c61290997bf37b4109a07676135

client/src/com/vaadin/client/widgets/Grid.java
uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java [new file with mode: 0644]

index 67220b6e076458095d8667e470669d4a3fcedb73..1837f4c951ae13b8e17d0e07b4341799c62cbdd8 100644 (file)
@@ -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 (file)
index 0000000..49b344b
--- /dev/null
@@ -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 (file)
index 0000000..a3e9410
--- /dev/null
@@ -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);
+    }
+
+}