diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-04-30 14:31:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-30 14:31:09 +0300 |
commit | 35e441f2ecf19b779fb99ccc58d658dc29c03d80 (patch) | |
tree | 283089da74a1632264b287c36157b24f28a183a4 | |
parent | 4c9a5405a555785dc2b38e82b3d1cda0336491e0 (diff) | |
download | vaadin-framework-35e441f2ecf19b779fb99ccc58d658dc29c03d80.tar.gz vaadin-framework-35e441f2ecf19b779fb99ccc58d658dc29c03d80.zip |
Allow replacing all columns at once when some of them are frozen. (#11978)
Fixes #11824
3 files changed, 89 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index 6d22dfc5ca..2faddaf68d 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -7398,8 +7398,17 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, } private void updateFrozenColumns() { - escalator.getColumnConfiguration() - .setFrozenColumnCount(getVisibleFrozenColumnCount()); + int visibleFrozenColumnCount = getVisibleFrozenColumnCount(); + ColumnConfiguration columnConfiguration = escalator + .getColumnConfiguration(); + if (columnConfiguration.getColumnCount() < visibleFrozenColumnCount) { + // new columns may not have got added yet, delay and check the + // correct count again + Scheduler.get().scheduleFinally(() -> columnConfiguration + .setFrozenColumnCount(getVisibleFrozenColumnCount())); + } else { + columnConfiguration.setFrozenColumnCount(visibleFrozenColumnCount); + } } private int getVisibleFrozenColumnCount() { diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridFrozenColumnReplace.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridFrozenColumnReplace.java new file mode 100644 index 0000000000..7ddb35784a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridFrozenColumnReplace.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; + +public class GridFrozenColumnReplace extends SimpleGridUI { + + @Override + protected void setup(VaadinRequest request) { + Grid<String> grid = new Grid<>(); + grid.addColumn(String::toString).setId("id1").setCaption("Frozen 1"); + grid.addColumn(String::toString).setId("id2").setCaption("Col 2"); + grid.setSelectionMode(SelectionMode.MULTI); + grid.setFrozenColumnCount(1); + + Button button = new Button("Replace columns"); + button.addClickListener(e -> { + grid.removeAllColumns(); // will change frozenColumnCount to 0 + + grid.addColumn(String::toString).setId("id1") + .setCaption("New Frozen 1"); + grid.addColumn(String::toString).setId("id2") + .setCaption("New Frozen 2"); + grid.addColumn(String::toString).setId("id3") + .setCaption("New Col 3"); + grid.setFrozenColumnCount(2); + }); + + addComponents(grid, button); + } + + @Override + protected String getTestDescription() { + return "It should be possible to remove and replace columns on same round trip " + + "even if some of them are frozen."; + } + + @Override + protected Integer getTicketNumber() { + return 11824; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridFrozenColumnReplaceTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridFrozenColumnReplaceTest.java new file mode 100644 index 0000000000..4ad8a48fa2 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridFrozenColumnReplaceTest.java @@ -0,0 +1,34 @@ +package com.vaadin.tests.components.grid; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class GridFrozenColumnReplaceTest extends SingleBrowserTest { + + @Test + public void testChangingColumns() { + openTestURL("debug"); + + GridElement grid = $(GridElement.class).first(); + String caption = grid.getHeaderCell(0, 1).getText(); + assertFalse("Unexpected column caption: " + caption, + caption != null && caption.startsWith("New ")); + + $(ButtonElement.class).first().click(); + + assertEquals("Unexpected error notifications,", 0, + findElements(By.className("v-Notification-error")).size()); + + caption = grid.getHeaderCell(0, 1).getText(); + assertTrue("Unexpected column caption: " + caption, + caption != null && caption.startsWith("New ")); + } +} |