From 64caee7afa90ac8b16ba48e768204aa36248ecbe Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Mon, 28 Jul 2014 16:26:01 +0300 Subject: Allow merging header and footer cells again #13334 This changeset adds the possibility to merge header and footer cells by using HeaderRow.join(). Note: Currently this does not support hidden columns, support for it should be added in a later changeset. Change-Id: I42e089ef2ac6eea304e355423b274159a79baa89 --- .../grid/basicfeatures/GridFooterTest.java | 55 +++++++++++++++ .../grid/basicfeatures/GridHeaderTest.java | 51 ++++++++++++++ .../client/grid/GridBasicClientFeatures.java | 79 ++++++++++++++++++++-- 3 files changed, 181 insertions(+), 4 deletions(-) (limited to 'uitest/src') diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridFooterTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridFooterTest.java index f7dd85e3c3..e117ed5fbb 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridFooterTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridFooterTest.java @@ -16,9 +16,13 @@ package com.vaadin.tests.components.grid.basicfeatures; 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.tests.components.grid.GridElement.GridCellElement; + public class GridFooterTest extends GridStaticSectionTest { @Test @@ -85,6 +89,57 @@ public class GridFooterTest extends GridStaticSectionTest { assertFooterCount(0); } + @Test + public void joinColumnsByCells() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + selectMenuPath("Component", "Footer", "Row 1", "Join column cells 0, 1"); + + GridCellElement spannedCell = getGridElement().getFooterCell(0, 0); + assertTrue(spannedCell.isDisplayed()); + assertEquals("2", spannedCell.getAttribute("colspan")); + + GridCellElement hiddenCell = getGridElement().getFooterCell(0, 1); + assertFalse(hiddenCell.isDisplayed()); + } + + @Test + public void joinColumnsByColumns() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2"); + + GridCellElement spannedCell = getGridElement().getFooterCell(0, 1); + assertTrue(spannedCell.isDisplayed()); + assertEquals("2", spannedCell.getAttribute("colspan")); + + GridCellElement hiddenCell = getGridElement().getFooterCell(0, 2); + assertFalse(hiddenCell.isDisplayed()); + } + + @Test + public void joinAllColumnsInRow() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + selectMenuPath("Component", "Footer", "Row 1", "Join all columns"); + + GridCellElement spannedCell = getGridElement().getFooterCell(0, 0); + assertTrue(spannedCell.isDisplayed()); + assertEquals("11", spannedCell.getAttribute("colspan")); + + for (int columnIndex = 1; columnIndex < 11; columnIndex++) { + GridCellElement hiddenCell = getGridElement().getFooterCell(0, + columnIndex); + assertFalse(hiddenCell.isDisplayed()); + } + } + private void assertFooterCount(int count) { assertEquals("footer count", count, getGridElement().getFooterCount()); } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridHeaderTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridHeaderTest.java index 1b27350f25..771c0da810 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridHeaderTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridHeaderTest.java @@ -159,6 +159,57 @@ public class GridHeaderTest extends GridStaticSectionTest { assertFalse(hasClassName(headerCell, "sort-desc")); } + @Test + public void joinHeaderColumnsByCells() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Header", "Append row"); + + selectMenuPath("Component", "Header", "Row 2", "Join column cells 0, 1"); + + GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0); + assertTrue(spannedCell.isDisplayed()); + assertEquals("2", spannedCell.getAttribute("colspan")); + + GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 1); + assertFalse(hiddenCell.isDisplayed()); + } + + @Test + public void joinHeaderColumnsByColumns() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Header", "Append row"); + + selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); + + GridCellElement spannedCell = getGridElement().getHeaderCell(1, 1); + assertTrue(spannedCell.isDisplayed()); + assertEquals("2", spannedCell.getAttribute("colspan")); + + GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 2); + assertFalse(hiddenCell.isDisplayed()); + } + + @Test + public void joinAllColumnsInHeaderRow() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Header", "Append row"); + + selectMenuPath("Component", "Header", "Row 2", "Join all columns"); + + GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0); + assertTrue(spannedCell.isDisplayed()); + assertEquals("11", spannedCell.getAttribute("colspan")); + + for (int columnIndex = 1; columnIndex < 11; columnIndex++) { + GridCellElement hiddenCell = getGridElement().getHeaderCell(1, + columnIndex); + assertFalse(hiddenCell.isDisplayed()); + } + } + private void assertHeaderCount(int count) { assertEquals("header count", count, getGridElement().getHeaderCount()); } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java index e013306dc0..b6dfdc8635 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java @@ -311,13 +311,13 @@ public class GridBasicClientFeatures extends addMenuCommand("Prepend row", new ScheduledCommand() { @Override public void execute() { - setHeaderTexts(header.prependRow()); + configureHeaderRow(header.prependRow()); } }, menuPath); addMenuCommand("Append row", new ScheduledCommand() { @Override public void execute() { - setHeaderTexts(header.appendRow()); + configureHeaderRow(header.appendRow()); } }, menuPath); addMenuCommand("Remove top row", new ScheduledCommand() { @@ -332,6 +332,42 @@ public class GridBasicClientFeatures extends header.removeRow(header.getRowCount() - 1); } }, menuPath); + + } + + private void configureHeaderRow(final HeaderRow row) { + final GridHeader header = grid.getHeader(); + setHeaderTexts(row); + String rowTitle = "Row " + header.getRowCount(); + final String[] menuPath = { "Component", "Header", rowTitle }; + + addMenuCommand("Join column cells 0, 1", new ScheduledCommand() { + + @Override + public void execute() { + row.join(row.getCell(0), row.getCell(1)); + + } + }, menuPath); + + addMenuCommand("Join columns 1, 2", new ScheduledCommand() { + + @Override + public void execute() { + row.join(grid.getColumn(1), grid.getColumn(2)); + + } + }, menuPath); + + addMenuCommand("Join all columns", new ScheduledCommand() { + + @Override + public void execute() { + row.join(grid.getColumns().toArray( + new GridColumn[grid.getColumnCount()])); + + } + }, menuPath); } private void createFooterMenu() { @@ -348,13 +384,13 @@ public class GridBasicClientFeatures extends addMenuCommand("Prepend row", new ScheduledCommand() { @Override public void execute() { - setFooterTexts(footer.prependRow()); + configureFooterRow(footer.prependRow()); } }, menuPath); addMenuCommand("Append row", new ScheduledCommand() { @Override public void execute() { - setFooterTexts(footer.appendRow()); + configureFooterRow(footer.appendRow()); } }, menuPath); addMenuCommand("Remove top row", new ScheduledCommand() { @@ -371,6 +407,41 @@ public class GridBasicClientFeatures extends }, menuPath); } + private void configureFooterRow(final FooterRow row) { + final GridFooter footer = grid.getFooter(); + setFooterTexts(row); + String rowTitle = "Row " + footer.getRowCount(); + final String[] menuPath = { "Component", "Footer", rowTitle }; + + addMenuCommand("Join column cells 0, 1", new ScheduledCommand() { + + @Override + public void execute() { + row.join(row.getCell(0), row.getCell(1)); + + } + }, menuPath); + + addMenuCommand("Join columns 1, 2", new ScheduledCommand() { + + @Override + public void execute() { + row.join(grid.getColumn(1), grid.getColumn(2)); + + } + }, menuPath); + + addMenuCommand("Join all columns", new ScheduledCommand() { + + @Override + public void execute() { + row.join(grid.getColumns().toArray( + new GridColumn[grid.getColumnCount()])); + + } + }, menuPath); + } + /** * Creates a a renderer for a {@link Renderers} */ -- cgit v1.2.3