summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-03-09 08:37:54 +0200
committerPekka Hyvönen <pekka@vaadin.com>2017-03-09 08:37:54 +0200
commitd03e6a5817affc701069faabc59a0f959a104170 (patch)
treee24e2730358881499772471a0ef7aed175910e6e /server
parent0c5414744b720da51aedace58b9efa21ecd4bd0e (diff)
downloadvaadin-framework-d03e6a5817affc701069faabc59a0f959a104170.tar.gz
vaadin-framework-d03e6a5817affc701069faabc59a0f959a104170.zip
Correctly detach header/footer components when column is removed (#8645)
* Correctly detach header/footer components when column is removed Fixes #8638 * Merge branch '7.7' into _detach-header-components-on-remove-column * Merge branch '7.7' into _detach-header-components-on-remove-column * Merge branch '7.7' into _detach-header-components-on-remove-column
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java8
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/grid/GridChildrenTest.java92
2 files changed, 98 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index 17ffab017f..5bdb76938f 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -2370,6 +2370,8 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
Set<CELLTYPE> cellGroupForCell = getCellGroupForCell(cell);
if (cellGroupForCell != null) {
removeCellFromGroup(cell, cellGroupForCell);
+ } else {
+ cell.detach();
}
rowState.cells.remove(cell.getCellState());
}
@@ -2385,11 +2387,13 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
CELLTYPE mergedCell = cellGroups.remove(cellGroup);
cellGroup.remove(cell);
cellGroups.put(cellGroup, mergedCell);
-
group.remove(columnId);
} else {
+ // Only one cell remaining in the group, disband it
+ // The contents of the group if removed
rowState.cellGroups.remove(group);
- cellGroups.remove(cellGroup);
+ CELLTYPE mergedCell = cellGroups.remove(cellGroup);
+ mergedCell.detach();
}
return;
}
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 374a93a98c..91da107b3b 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
@@ -21,10 +21,15 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import com.vaadin.data.Container.Indexed;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.FooterCell;
+import com.vaadin.ui.Grid.FooterRow;
import com.vaadin.ui.Grid.HeaderCell;
+import com.vaadin.ui.Grid.HeaderRow;
import com.vaadin.ui.Label;
public class GridChildrenTest {
@@ -74,6 +79,93 @@ public class GridChildrenTest {
}
@Test
+ public void removeHeaderFooterComponentWhenColumnIsRemoved() {
+ HeaderRow h1 = grid.prependHeaderRow();
+ FooterRow f1 = grid.addFooterRowAt(0);
+ Button headerButton = new Button("This is a button, mkay?");
+ Button footerButton = new Button("This is a button, mkay?");
+ h1.getCell("foo").setComponent(headerButton);
+ f1.getCell("foo").setComponent(footerButton);
+
+ Assert.assertEquals(grid, headerButton.getParent());
+ Assert.assertEquals(grid, footerButton.getParent());
+ grid.removeColumn("foo");
+ Assert.assertNull(headerButton.getParent());
+ Assert.assertNull(footerButton.getParent());
+ }
+
+ @Test
+ public void joinedHeaderComponentDetachedWhenLastColumnIsRemoved() {
+ HeaderRow h1 = grid.prependHeaderRow();
+ FooterRow f1 = grid.addFooterRowAt(0);
+ Button headerButton = new Button("This is a button, mkay?");
+ Button footerButton = new Button("This is a button, mkay?");
+
+ HeaderCell mergedHeader = h1.join("foo", "bar", "baz");
+ FooterCell mergedFooter = f1.join("foo", "bar", "baz");
+
+ mergedHeader.setComponent(headerButton);
+ mergedFooter.setComponent(footerButton);
+
+ Assert.assertEquals(grid, headerButton.getParent());
+ Assert.assertEquals(grid, footerButton.getParent());
+ grid.removeColumn("foo");
+ Assert.assertEquals(grid, headerButton.getParent());
+ Assert.assertEquals(grid, footerButton.getParent());
+ Assert.assertEquals(headerButton, mergedHeader.getComponent());
+ Assert.assertEquals(footerButton, mergedFooter.getComponent());
+
+ grid.removeColumn("bar");
+ // Component is not moved from merged cell to the last remaining cell
+ Assert.assertNull(headerButton.getParent());
+ Assert.assertNull(footerButton.getParent());
+ }
+
+ @Test
+ public void joinedHeaderComponentDetachedWhenLastColumnIsRemovedReverseOrder() {
+ HeaderRow h1 = grid.prependHeaderRow();
+ FooterRow f1 = grid.addFooterRowAt(0);
+ Button headerButton = new Button("This is a button, mkay?");
+ Button footerButton = new Button("This is a button, mkay?");
+
+ HeaderCell mergedHeader = h1.join("foo", "bar", "baz");
+ FooterCell mergedFooter = f1.join("foo", "bar", "baz");
+
+ mergedHeader.setComponent(headerButton);
+ mergedFooter.setComponent(footerButton);
+
+ Assert.assertEquals(grid, headerButton.getParent());
+ Assert.assertEquals(grid, footerButton.getParent());
+ grid.removeColumn("baz");
+ Assert.assertEquals(grid, headerButton.getParent());
+ Assert.assertEquals(grid, footerButton.getParent());
+ Assert.assertEquals(headerButton, mergedHeader.getComponent());
+ Assert.assertEquals(footerButton, mergedFooter.getComponent());
+
+ grid.removeColumn("bar");
+ // Component is not moved from merged cell to the last remaining cell
+ Assert.assertNull(headerButton.getParent());
+ Assert.assertNull(footerButton.getParent());
+ }
+
+ @Test
+ public void removeHeaderComponentWhenColumnIsRemovedFromDataSource() {
+ Indexed i = new IndexedContainer();
+ i.addContainerProperty("c1", String.class, "does not matter 1");
+ i.addContainerProperty("c2", String.class, "does not matter 2");
+ Grid grid = new Grid();
+ grid.setContainerDataSource(i);
+
+ HeaderRow h1 = grid.prependHeaderRow();
+ Button button = new Button("This is a button, mkay?");
+ h1.getCell("c1").setComponent(button);
+
+ Assert.assertEquals(grid, button.getParent());
+ i.removeContainerProperty("c1");
+ Assert.assertNull(button.getParent());
+ }
+
+ @Test
public void removeComponentInMergedFooterCell() {
FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz");
Label label = new Label();