From ef729f355b559edf38b3ba7c0a78c17c61602703 Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 9 Jan 2017 11:18:49 +0200 Subject: [PATCH] Correctly detach components in merged cells when a static row is removed (#8142) Fixes #8140 --- server/src/main/java/com/vaadin/ui/Grid.java | 3 + .../component/grid/GridChildrenTest.java | 61 ++++++++++++++++--- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index 2cccc51212..7dd4c00609 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -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(); + } } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridChildrenTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridChildrenTest.java index 028b13f997..374a93a98c 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridChildrenTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridChildrenTest.java @@ -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 i = grid.iterator(); Assert.assertEquals(label, i.next()); Assert.assertFalse(i.hasNext()); + Assert.assertEquals(grid, label.getParent()); } } -- 2.39.5