From 96e0e2ed125a05d58373e1a6c11d8bfe39659e89 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 1 Jun 2015 22:17:10 +0300 Subject: [PATCH] Only set height when at least one header cell is shown (#18000) Change-Id: I252a8223804b5ba45abb20061c3d65d0b80603dc --- .../src/com/vaadin/client/widgets/Grid.java | 33 ++++++++----------- .../basicfeatures/GridColumnHidingTest.java | 24 ++++++++++++++ 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 079207a999..67220b6e07 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -3238,27 +3238,22 @@ public class Grid extends ResizeComposite implements } private void setHeightToHeaderCellHeight() { - try { - double height = WidgetUtil - .getRequiredHeightBoundingClientRectDouble(grid.escalator - .getHeader().getRowElement(0) - .getFirstChildElement()) - - (WidgetUtil.measureVerticalBorder(getElement()) / 2); - openCloseButton.setHeight(height + "px"); - } catch (NullPointerException npe) { - getLogger() - .warning( - "Got null header first row or first row cell when calculating sidebar button height"); - openCloseButton.setHeight(grid.escalator.getHeader() - .getDefaultRowHeight() + "px"); - } catch (IndexOutOfBoundsException ioobe) { - // happens when escalator doesn't have any headers rendered yet. + RowContainer header = grid.escalator.getHeader(); + if (header.getRowCount() == 0 + || !header.getRowElement(0).hasChildNodes()) { getLogger() - .warning( - "No header cell available when calculating sidebar button height"); - openCloseButton.setHeight(grid.escalator.getHeader() - .getDefaultRowHeight() + "px"); + .info("No header cell available when calculating sidebar button height"); + openCloseButton.setHeight(header.getDefaultRowHeight() + "px"); + + return; } + + Element firstHeaderCell = header.getRowElement(0) + .getFirstChildElement(); + double height = WidgetUtil + .getRequiredHeightBoundingClientRectDouble(firstHeaderCell) + - (WidgetUtil.measureVerticalBorder(getElement()) / 2); + openCloseButton.setHeight(height + "px"); } private void updateVisibility() { diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnHidingTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnHidingTest.java index c4ad2ea347..9f63c2b177 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnHidingTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnHidingTest.java @@ -840,6 +840,30 @@ public class GridColumnHidingTest extends GridBasicClientFeaturesTest { .getDetails(1)); } + @Test + public void testHideShowAllColumns() { + selectMenuPath("Component", "State", "Width", "1000px"); + int colCount = 12; + for (int i = 0; i < colCount; i++) { + toggleHidableColumnAPI(i); + } + clickSidebarOpenButton(); + for (int i = 0; i < colCount; i++) { + getColumnHidingToggle(i).click(); + } + + clickSidebarOpenButton(); + // All columns hidden + assertEquals(0, getGridHeaderRowCells().size()); + clickSidebarOpenButton(); + for (int i = 0; i < colCount; i++) { + getColumnHidingToggle(i).click(); + } + + assertEquals(colCount, getGridHeaderRowCells().size()); + + } + private void loadSpannedCellsFixture() { selectMenuPath("Component", "State", "Width", "1000px"); appendHeaderRow(); -- 2.39.5