summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcuong-phan <39257573+cuong-phan@users.noreply.github.com>2019-05-20 15:00:38 +0300
committerZhe Sun <31067185+ZheSun88@users.noreply.github.com>2019-05-22 16:31:31 +0300
commit05297a109ffd6aa1895fe3a1cf4293bfa08ed8b2 (patch)
tree7d790640328cbcd8c4066ad2959988e1b59315a1
parent06624b2d9cbcca187140b11bce01174e3d2e393f (diff)
downloadvaadin-framework-05297a109ffd6aa1895fe3a1cf4293bfa08ed8b2.tar.gz
vaadin-framework-05297a109ffd6aa1895fe3a1cf4293bfa08ed8b2.zip
Fix Grid reordering when there are hidden columns
* Fix grid column reordering Fix grid column reordering when there are hidden columns and footerRow.join * Add test
-rwxr-xr-xclient/src/main/java/com/vaadin/client/widgets/Grid.java13
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridReorderHiddenColumnsJoinedFooter.java76
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridReorderHiddenColumnsJoinedFooterTest.java34
3 files changed, 122 insertions, 1 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 cb43bdd7d1..ae63749c5f 100755
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -639,6 +639,16 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
return null;
}
+ protected int getSizeOfCellGroup(Column<?, ?> column) {
+ for (Entry<CELLTYPE, Set<Column<?, ?>>> entry : cellGroups
+ .entrySet()) {
+ if (entry.getValue().contains(column)) {
+ return entry.getValue().size();
+ }
+ }
+ return 0;
+ }
+
void calculateColspans() {
// Reset all cells
for (CELLTYPE cell : this.cells.values()) {
@@ -4697,7 +4707,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
if (colspan <= 1) {
continue;
}
- final int cellColumnRightIndex = cellColumnIndex + colspan;
+ final int cellColumnRightIndex = cellColumnIndex + row
+ .getSizeOfCellGroup(getColumn(cellColumnIndex));
final Range cellRange = Range.between(cellColumnIndex,
cellColumnRightIndex);
final boolean intersects = draggedCellRange
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridReorderHiddenColumnsJoinedFooter.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridReorderHiddenColumnsJoinedFooter.java
new file mode 100644
index 0000000000..5d3527ea0a
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridReorderHiddenColumnsJoinedFooter.java
@@ -0,0 +1,76 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.data.provider.DataProvider;
+import com.vaadin.data.provider.ListDataProvider;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.components.grid.FooterCell;
+import com.vaadin.ui.components.grid.FooterRow;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class GridReorderHiddenColumnsJoinedFooter extends AbstractTestUI {
+ @Override
+ protected void setup(VaadinRequest request) {
+ getLayout().setSpacing(true);
+
+ Grid<String> grid = createGrid();
+
+ addComponents(grid);
+ }
+
+ private Grid<String> createGrid() {
+ Grid<String> grid = new Grid<>();
+ grid.addColumn(t -> t + "1").setId("col1").setCaption("caption1")
+ .setHidable(true);
+ grid.addColumn(t -> t + "2").setId("col2").setCaption("caption2")
+ .setHidable(true);
+ grid.addColumn(t -> t + "3").setId("col3").setCaption("caption3")
+ .setHidable(true);
+ grid.addColumn(t -> t + "4").setId("col4").setCaption("caption4")
+ .setHidable(true);
+ grid.addColumn(t -> t + "5").setId("col5").setCaption("caption5")
+ .setHidable(true);
+ grid.addColumn(t -> t + "6").setId("col6").setCaption("caption6")
+ .setHidable(true);
+ grid.addColumn(t -> t + "7").setId("col7").setCaption("caption7")
+ .setHidable(true);
+ grid.addColumn(t -> t + "8").setId("col8").setCaption("caption8")
+ .setHidable(true);
+
+ grid.setColumnReorderingAllowed(true);
+ grid.setSizeFull();
+
+ // join FooterRow together
+ FooterRow footerRow = grid.appendFooterRow();
+ Grid.Column[] columns = grid.getColumns().toArray(new Grid.Column[0]);
+ FooterCell footerCell = footerRow.join(columns);
+ footerCell.setText("test");
+
+ // hide columns
+ grid.getColumn("col2").setHidden(true);
+ grid.getColumn("col4").setHidden(true);
+ grid.getColumn("col5").setHidden(true);
+ grid.getColumn("col6").setHidden(true);
+
+ List<String> items = new ArrayList<>();
+ items.add("content");
+ ListDataProvider<String> dataProvider = DataProvider
+ .ofCollection(items);
+ grid.setDataProvider(dataProvider);
+ return grid;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 11478;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Column reordering with hidden columns and joined footer should not "
+ + "be blocked by hidden columns.";
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridReorderHiddenColumnsJoinedFooterTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridReorderHiddenColumnsJoinedFooterTest.java
new file mode 100644
index 0000000000..bae0808280
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridReorderHiddenColumnsJoinedFooterTest.java
@@ -0,0 +1,34 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.interactions.Actions;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.junit.Assert.assertThat;
+
+public class GridReorderHiddenColumnsJoinedFooterTest extends MultiBrowserTest {
+ @Test
+ public void test() {
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).get(0);
+ GridElement.GridCellElement headerCell1 = grid
+ .getHeaderCellByCaption("caption1");
+ GridElement.GridCellElement headerCell8 = grid
+ .getHeaderCellByCaption("caption8");
+
+ assertThat(grid.getHeaderCell(0, 0), is(headerCell1));
+
+ new Actions(getDriver()).clickAndHold(headerCell1)
+ .moveToElement(headerCell8, 2, 0).release().perform();
+
+ waitForElementNotPresent(By.className("dragged-column-header"));
+
+ assertThat(grid.getHeaderCell(0, 0), not(is(headerCell1)));
+ assertThat(grid.getHeaderCell(0, 0).getText(), is("caption3"));
+ }
+}