]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix removal of hidden Grid columns (#8071)
authorArtur <artur@vaadin.com>
Fri, 23 Dec 2016 06:30:41 +0000 (08:30 +0200)
committerHenri Sara <henri.sara@gmail.com>
Fri, 23 Dec 2016 06:30:41 +0000 (08:30 +0200)
Fixes #8018

client/src/main/java/com/vaadin/client/widgets/Grid.java
uitest/src/main/java/com/vaadin/tests/components/grid/RemoveHiddenColumn.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/grid/RemoveHiddenColumnTest.java [new file with mode: 0644]

index 8c71b3fe6662f0d404c9b495869315d15a4466ae..b0735a595e51823083f36e49cb670832b07a6c9b 100644 (file)
@@ -6463,8 +6463,14 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
         int columnIndex = columns.indexOf(column);
 
         // Remove from column configuration
-        escalator.getColumnConfiguration()
-                .removeColumns(getVisibleColumns().indexOf(column), 1);
+        int visibleColumnIndex = getVisibleColumns().indexOf(column);
+        if (visibleColumnIndex < 0) {
+            assert column.isHidden();
+            // Hidden columns are not included in Escalator
+        } else {
+            getEscalator().getColumnConfiguration().removeColumns(visibleColumnIndex,
+                    1);
+        }
 
         updateFrozenColumns();
 
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/RemoveHiddenColumn.java b/uitest/src/main/java/com/vaadin/tests/components/grid/RemoveHiddenColumn.java
new file mode 100644 (file)
index 0000000..bb80ac0
--- /dev/null
@@ -0,0 +1,60 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.tests.data.bean.Sex;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.Column;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.VerticalLayout;
+
+public class RemoveHiddenColumn extends AbstractTestUIWithLog {
+
+    private final Grid testGrid = new Grid();
+    private final Button testBtn = new Button("updateGrid");
+    private final Button testBtn2 = new Button("show/hide Grid");
+    private final HorizontalLayout buttonBar = new HorizontalLayout(testBtn,
+            testBtn2);
+    private final VerticalLayout mainLayout = new VerticalLayout(testGrid,
+            buttonBar);
+
+    @Override
+    protected void setup(final VaadinRequest request) {
+        final Grid grid = new Grid();
+        final BeanItemContainer<Person> bic = new BeanItemContainer<Person>(
+                Person.class);
+        grid.setContainerDataSource(bic);
+        grid.setColumns("firstName", "lastName", "email", "age");
+
+        grid.getColumn("firstName").setHidden(true);
+        grid.getColumn("email").setHidden(true);
+
+        Button addRow = new Button("Add data row", new ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent e) {
+                bic.addBean(new Person("first", "last", "email", 42, Sex.FEMALE,
+                        null));
+
+            }
+        });
+        addRow.setId("add");
+        Button removeColumn = new Button("Remove first column",
+                new ClickListener() {
+                    @Override
+                    public void buttonClick(ClickEvent e) {
+                        Column column = grid.getColumns().get(0);
+                        log("Removed column '" + column.getHeaderCaption() + "'"
+                                + (column.isHidden() ? " (hidden)" : ""));
+                        grid.removeColumn(column.getPropertyId());
+                    }
+                });
+        removeColumn.setId("remove");
+
+        addComponents(grid, addRow, removeColumn);
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/RemoveHiddenColumnTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/RemoveHiddenColumnTest.java
new file mode 100644 (file)
index 0000000..1d54388
--- /dev/null
@@ -0,0 +1,45 @@
+package com.vaadin.tests.components.grid;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class RemoveHiddenColumnTest extends SingleBrowserTest {
+
+    @Test
+    public void removeHiddenColumnInEmptyGrid() {
+        openTestURL("debug");
+        removeColumns();
+    }
+
+    @Test
+    public void removeHiddenColumnInPopulatedGrid() {
+        openTestURL("debug");
+        ButtonElement add = $(ButtonElement.class).id("add");
+        add.click();
+        removeColumns();
+
+    }
+
+    private void removeColumns() {
+        ButtonElement remove = $(ButtonElement.class).id("remove");
+        remove.click();
+        Assert.assertEquals("1. Removed column 'First Name' (hidden)",
+                getLogRow(0));
+        assertNoErrorNotifications();
+
+        remove.click();
+        Assert.assertEquals("2. Removed column 'Last Name'", getLogRow(0));
+        assertNoErrorNotifications();
+        remove.click();
+        Assert.assertEquals("3. Removed column 'Email' (hidden)", getLogRow(0));
+        assertNoErrorNotifications();
+        remove.click();
+        Assert.assertEquals("4. Removed column 'Age'", getLogRow(0));
+        assertNoErrorNotifications();
+
+    }
+
+}