From 610c6522da483b7b05cba1a71d7451642e916dc5 Mon Sep 17 00:00:00 2001 From: Artur Date: Thu, 9 Mar 2017 11:35:45 +0200 Subject: Correctly detach components in merged cells (#8773) * Correctly detach components in merged cells This was already once fixed in 7.7 in #8142 --- .../vaadin/ui/components/grid/StaticSection.java | 7 +++++++ .../server/component/grid/GridChildrenTest.java | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'server') diff --git a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java index 840fa7b115..dcf27fb357 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java @@ -388,6 +388,13 @@ public abstract class StaticSection> for (CELL cell : cells.values()) { cell.detach(); } + for (CellState cellState : rowState.cellGroups.keySet()) { + if (cellState.type == GridStaticCellType.WIDGET + && cellState.connector != null) { + ((Component) cellState.connector).setParent(null); + cellState.connector = null; + } + } } void checkIfAlreadyMerged(String columnId) { 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 4959169cf8..97cfe6ebc7 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 @@ -63,6 +63,17 @@ public class GridChildrenTest { 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"); @@ -73,6 +84,16 @@ public class GridChildrenTest { 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() { FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz"); -- cgit v1.2.3