From b6ece49bf437b68a4a31ca787e16118215f72832 Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Thu, 26 Aug 2021 12:49:22 +0300 Subject: [PATCH] Fix compatibility Grid column reorder with partially hidden joined cells (#12385) Fixes #12377 --- .../com/vaadin/v7/client/widgets/Grid.java | 9 ++-- .../components/grid/GridReorderMerged.java | 45 +++++++++++++++++++ .../grid/GridReorderMergedTest.java | 27 +++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReorderMerged.java create mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridReorderMergedTest.java diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java b/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java index f889954e3f..717acc1793 100755 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java @@ -4629,11 +4629,14 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, } final boolean isDraggedCellRow = row.equals(draggedCellRow); for (int cellColumnIndex = frozenColumns; cellColumnIndex < getColumnCount(); cellColumnIndex++) { - StaticCell cell = row.getCell(getColumn(cellColumnIndex)); - int colspan = cell.getColspan(); - if (colspan <= 1) { + // some of the columns might be hidden, use cell groups + // rather than cell spans to determine actual span + Set> cellGroup = row + .getCellGroupForColumn(getColumn(cellColumnIndex)); + if (cellGroup == null) { continue; } + int colspan = cellGroup.size(); final int cellColumnRightIndex = cellColumnIndex + colspan; final Range cellRange = Range.between(cellColumnIndex, cellColumnRightIndex); diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReorderMerged.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReorderMerged.java new file mode 100644 index 0000000000..6a3e01427e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReorderMerged.java @@ -0,0 +1,45 @@ +package com.vaadin.v7.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.Column; +import com.vaadin.v7.ui.Grid.HeaderRow; + +@SuppressWarnings("deprecation") +public class GridReorderMerged extends AbstractTestUI { + + @SuppressWarnings("unchecked") + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + HeaderRow headerRow = grid.prependHeaderRow(); + for (int i = 1; i < 10; ++i) { + String propertyId = "" + i; + Column column = grid.addColumn(propertyId); + column.setHidable(true); + if (i == 5) { + column.setHidden(true); + } + // add one value per row for easier visualization + grid.getContainerDataSource().addItem(i).getItemProperty(propertyId) + .setValue(propertyId); + } + headerRow.join("1", "2", "3").setText("1"); + headerRow.join("4", "5", "6").setText("2"); // middle column hidden + headerRow.join("7", "8", "9").setText("3"); + grid.setColumnReorderingAllowed(true); + addComponent(grid); + } + + @Override + protected Integer getTicketNumber() { + return 12377; + } + + @Override + protected String getTestDescription() { + return "Reordering columns should respect joined cells " + + "even when some columns are hidden."; + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridReorderMergedTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridReorderMergedTest.java new file mode 100644 index 0000000000..bab2ae2bb2 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridReorderMergedTest.java @@ -0,0 +1,27 @@ +package com.vaadin.v7.tests.components.grid; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridReorderMergedTest extends MultiBrowserTest { + + @Test + public void dragMerged() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + GridCellElement headerCell0_0 = grid.getHeaderCell(0, 0); + GridCellElement headerCell0_4 = grid.getHeaderCell(0, 4); + new Actions(driver).dragAndDrop(headerCell0_0, headerCell0_4).perform(); + + // ensure the first merged block got dragged over the entire second + // merged block + assertEquals("Unexpected column order,", "6", + grid.getHeaderCell(1, 1).getText()); + } +} -- 2.39.5