diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-08-01 11:41:39 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-08-01 11:41:39 +0300 |
commit | 7cf466fa7f0a1fbf48664a6c8211809f9932a997 (patch) | |
tree | 20b03e17583c38479481a09013e9a4db360b7991 | |
parent | 2af2783f502aac67ff01460b4bd00cd5a2e8a88c (diff) | |
download | vaadin-framework-7cf466fa7f0a1fbf48664a6c8211809f9932a997.tar.gz vaadin-framework-7cf466fa7f0a1fbf48664a6c8211809f9932a997.zip |
Add header and footer visibility setting to Grid (#9706)
6 files changed, 107 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java index 34913910cb..61c0957d03 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java @@ -343,6 +343,8 @@ public class GridConnector extends AbstractListingConnector updateStaticRow(rowState, row); } + + grid.setHeaderVisible(state.visible); } @OnStateChange("rowHeight") @@ -423,6 +425,8 @@ public class GridConnector extends AbstractListingConnector updateStaticRow(rowState, row); } + + grid.setFooterVisible(state.visible); } @OnStateChange({ "sortColumns", "sortDirs" }) diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index dbaff46181..70e947ccd8 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -3207,6 +3207,29 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, } /** + * Sets the visibility of the Header in this Grid. + * + * @param headerVisible + * {@code true} if visible; {@code false} if not + * + * @since 8.1.1 + */ + public void setHeaderVisible(boolean headerVisible) { + getHeader().setVisible(headerVisible); + } + + /** + * Gets the visibility of the Header in this Grid. + * + * @return {@code true} if visible; {@code false} if not + * + * @since 8.1.1 + */ + public boolean isHeaderVisible() { + return getHeader().isVisible(); + } + + /** * Returns the current default row of the header. * * @return the default row or null if no default row set @@ -3357,6 +3380,29 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, } /** + * Sets the visibility of the Footer in this Grid. + * + * @param footerVisible + * {@code true} if visible; {@code false} if not + * + * @since 8.1.1 + */ + public void setFooterVisible(boolean footerVisible) { + getFooter().setVisible(footerVisible); + } + + /** + * Gets the visibility of the Footer in this Grid. + * + * @return {@code true} if visible; {@code false} if not + * + * @since 8.1.1 + */ + public boolean isFooterVisible() { + return getFooter().isVisible(); + } + + /** * Returns the footer section of this grid. * * @return the footer section diff --git a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java index 947be8f522..da5cafb9d6 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java @@ -798,4 +798,28 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>> return Collections.unmodifiableList(rows); } + /** + * Sets the visibility of this section. + * + * @param visible + * {@code true} if visible; {@code false} if not + * + * @since 8.1.1 + */ + public void setVisible(boolean visible) { + if (getState(false).visible != visible) { + getState(true).visible = visible; + } + } + + /** + * Gets the visibility of this section. + * + * @return {@code true} if visible; {@code false} if not + * + * @since 8.1.1 + */ + public boolean isVisible() { + return getState(false).visible; + } } diff --git a/shared/src/main/java/com/vaadin/shared/ui/grid/SectionState.java b/shared/src/main/java/com/vaadin/shared/ui/grid/SectionState.java index 74eb7bee04..e6c488c011 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/grid/SectionState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/grid/SectionState.java @@ -79,4 +79,7 @@ public class SectionState implements Serializable { /** The rows in this section. */ public List<RowState> rows = new ArrayList<>(); + + /** Visibility of this section. */ + public boolean visible = true; } diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java index 944f729efe..c5b6dbd490 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java @@ -603,6 +603,9 @@ public class GridBasics extends AbstractTestUIWithLog { } private void createHeaderMenu(MenuItem headerMenu) { + headerMenu.addItem("Toggle header visibility", + menuitem -> grid.setHeaderVisible(!grid.isHeaderVisible())); + headerMenu.addItem("Append header row", menuItem -> { HeaderRow row = grid.appendHeaderRow(); @@ -662,6 +665,9 @@ public class GridBasics extends AbstractTestUIWithLog { } private void createFooterMenu(MenuItem footerMenu) { + footerMenu.addItem("Toggle footer visibility", + menuitem -> grid.setFooterVisible(!grid.isFooterVisible())); + footerMenu.addItem("Add default footer row", menuItem -> { FooterRow defaultFooter = grid.appendFooterRow(); grid.getColumns().forEach( diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java index 45dba45954..b7ba76ea73 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java @@ -380,6 +380,30 @@ public class GridHeaderFooterTest extends GridBasicsTest { } + @Test + public void testHideAndShowHeader() { + assertEquals("There should be one header row", 1, + getGridElement().getHeaderCount()); + selectMenuPath("Component", "Header", "Toggle header visibility"); + assertEquals("There should be no header rows", 0, + getGridElement().getHeaderCount()); + selectMenuPath("Component", "Header", "Toggle header visibility"); + assertEquals("There should be one header row again", 1, + getGridElement().getHeaderCount()); + } + + @Test + public void testHideAndShowFooter() { + assertEquals("There should be one footer row", 1, + getGridElement().getFooterCount()); + selectMenuPath("Component", "Footer", "Toggle footer visibility"); + assertEquals("There should be no footer rows", 0, + getGridElement().getFooterCount()); + selectMenuPath("Component", "Footer", "Toggle footer visibility"); + assertEquals("There should be one footer row again", 1, + getGridElement().getFooterCount()); + } + private void toggleColumnHidable(int index) { selectMenuPath("Component", "Columns", "Column " + index, "Hidable"); } |