]> source.dussan.org Git - vaadin-framework.git/commitdiff
Correctly detach components in merged cells when a static row is removed (#8142)
authorArtur <artur@vaadin.com>
Mon, 9 Jan 2017 09:18:49 +0000 (11:18 +0200)
committerAleksi Hietanen <aleksi@vaadin.com>
Mon, 9 Jan 2017 09:18:49 +0000 (11:18 +0200)
Fixes #8140

server/src/main/java/com/vaadin/ui/Grid.java
server/src/test/java/com/vaadin/tests/server/component/grid/GridChildrenTest.java

index 2cccc51212faf902da75ab60a567ea10082138b2..7dd4c006092443b6ec6384873e667f1da404af17 100644 (file)
@@ -2506,6 +2506,9 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
                 for (CELLTYPE cell : cells.values()) {
                     cell.detach();
                 }
+                for (CELLTYPE cell : cellGroups.values()) {
+                    cell.detach();
+                }
             }
         }
 
index 028b13f99784336ec171b05428ae9a110cfe5028..374a93a98c707265bc5acf265dc351e0915b1072 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.tests.server.component.grid;
 import java.util.Iterator;
 
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
 import com.vaadin.ui.Component;
@@ -28,12 +29,19 @@ import com.vaadin.ui.Label;
 
 public class GridChildrenTest {
 
-    @Test
-    public void componentsInMergedHeader() {
-        Grid grid = new Grid();
+    private Grid grid;
+
+    @Before
+    public void createGrid() {
+        grid = new Grid();
         grid.addColumn("foo");
         grid.addColumn("bar");
         grid.addColumn("baz");
+
+    }
+
+    @Test
+    public void iteratorFindsComponentsInMergedHeader() {
         HeaderCell merged = grid.getDefaultHeaderRow().join("foo", "bar",
                 "baz");
         Label label = new Label();
@@ -43,17 +51,56 @@ public class GridChildrenTest {
         Assert.assertFalse(i.hasNext());
     }
 
+    @Test
+    public void removeComponentInMergedHeaderCell() {
+        HeaderCell merged = grid.getDefaultHeaderRow().join("foo", "bar",
+                "baz");
+        Label label = new Label();
+        merged.setComponent(label);
+        Assert.assertEquals(grid, label.getParent());
+        merged.setText("foo");
+        Assert.assertNull(label.getParent());
+    }
+
+    @Test
+    public void removeHeaderWithComponentInMergedHeaderCell() {
+        HeaderCell merged = grid.getDefaultHeaderRow().join("foo", "bar",
+                "baz");
+        Label label = new Label();
+        merged.setComponent(label);
+        Assert.assertEquals(grid, label.getParent());
+        grid.removeHeaderRow(0);
+        Assert.assertNull(label.getParent());
+    }
+
+    @Test
+    public void removeComponentInMergedFooterCell() {
+        FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz");
+        Label label = new Label();
+        merged.setComponent(label);
+        Assert.assertEquals(grid, label.getParent());
+        merged.setText("foo");
+        Assert.assertNull(label.getParent());
+    }
+
+    @Test
+    public void removeFooterWithComponentInMergedFooterCell() {
+        FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz");
+        Label label = new Label();
+        merged.setComponent(label);
+        Assert.assertEquals(grid, label.getParent());
+        grid.removeFooterRow(0);
+        Assert.assertNull(label.getParent());
+    }
+
     @Test
     public void componentsInMergedFooter() {
-        Grid grid = new Grid();
-        grid.addColumn("foo");
-        grid.addColumn("bar");
-        grid.addColumn("baz");
         FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz");
         Label label = new Label();
         merged.setComponent(label);
         Iterator<Component> i = grid.iterator();
         Assert.assertEquals(label, i.next());
         Assert.assertFalse(i.hasNext());
+        Assert.assertEquals(grid, label.getParent());
     }
 }