From: Artur Date: Mon, 6 Mar 2017 11:20:35 +0000 (+0200) Subject: Fix exception when no columns are shown (#8733) X-Git-Tag: 8.1.0.alpha1~61 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=42064ade8f01440432792b27ecd16a98f29fb74d;p=vaadin-framework.git Fix exception when no columns are shown (#8733) * Fix exception when no columns are shown or all columns are frozen Fixes #8329 --- diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index 239ed9b90b..7eb99badf7 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -701,13 +701,13 @@ public class Escalator extends Widget /*-{ var vScroll = esc.@com.vaadin.client.widgets.Escalator::verticalScrollbar; var vScrollElem = vScroll.@com.vaadin.client.widget.escalator.ScrollbarBundle::getElement()(); - + var hScroll = esc.@com.vaadin.client.widgets.Escalator::horizontalScrollbar; var hScrollElem = hScroll.@com.vaadin.client.widget.escalator.ScrollbarBundle::getElement()(); - + return $entry(function(e) { var target = e.target; - + // in case the scroll event was native (i.e. scrollbars were dragged, or // the scrollTop/Left was manually modified), the bundles have old cache // values. We need to make sure that the caches are kept up to date. @@ -728,29 +728,29 @@ public class Escalator extends Widget return $entry(function(e) { var deltaX = e.deltaX ? e.deltaX : -0.5*e.wheelDeltaX; var deltaY = e.deltaY ? e.deltaY : -0.5*e.wheelDeltaY; - + // Delta mode 0 is in pixels; we don't need to do anything... - + // A delta mode of 1 means we're scrolling by lines instead of pixels // We need to scale the number of lines by the default line height if(e.deltaMode === 1) { var brc = esc.@com.vaadin.client.widgets.Escalator::body; deltaY *= brc.@com.vaadin.client.widgets.Escalator.AbstractRowContainer::getDefaultRowHeight()(); } - + // Other delta modes aren't supported if((e.deltaMode !== undefined) && (e.deltaMode >= 2 || e.deltaMode < 0)) { var msg = "Unsupported wheel delta mode \"" + e.deltaMode + "\""; - + // Print warning message esc.@com.vaadin.client.widgets.Escalator::logWarning(*)(msg); } - + // IE8 has only delta y if (isNaN(deltaY)) { deltaY = -0.5*e.wheelDelta; } - + @com.vaadin.client.widgets.Escalator.JsniUtil::moveScrollFromEvent(*)(esc, deltaX, deltaY, e); }); }-*/; @@ -4097,6 +4097,10 @@ public class Escalator extends Widget */ @Override public void removeColumns(final int index, final int numberOfColumns) { + if (numberOfColumns == 0) { + return; + } + // Validate assertArgumentsAreValidAndWithinRange(index, numberOfColumns); @@ -4225,6 +4229,10 @@ public class Escalator extends Widget */ @Override public void insertColumns(final int index, final int numberOfColumns) { + if (numberOfColumns == 0) { + return; + } + // Validate if (index < 0 || index > getColumnCount()) { throw new IndexOutOfBoundsException("The given index(" + index diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java index 1c0a662abb..d040aa54f3 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java @@ -26,6 +26,7 @@ import com.vaadin.tests.data.bean.Person; import com.vaadin.tests.util.PortableRandom; import com.vaadin.tests.util.TestDataGenerator; import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; import com.vaadin.ui.renderers.NumberRenderer; public class GridInitiallyHiddenColumns extends AbstractTestUIWithLog { @@ -36,8 +37,11 @@ public class GridInitiallyHiddenColumns extends AbstractTestUIWithLog { grid.addColumn(Person::getFirstName).setHidden(true).setHidable(true) .setCaption("First Name"); - grid.addColumn(Person::getLastName).setHidable(true) - .setCaption("Last Name"); + Column col2 = grid.addColumn(Person::getLastName) + .setHidable(true).setCaption("Last Name"); + if (request.getParameter("allHidden") != null) { + col2.setHidden(true); + } grid.addColumn(Person::getAge, new NumberRenderer()).setHidden(true) .setHidable(true).setCaption("Age"); diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/InitialFrozenColumns.java b/uitest/src/main/java/com/vaadin/tests/components/grid/InitialFrozenColumns.java new file mode 100644 index 0000000000..ec49d24dc1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/InitialFrozenColumns.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.tests.data.bean.Sex; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; + +public class InitialFrozenColumns extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid<>(Person.class); + grid.setSelectionMode(SelectionMode.NONE); + grid.setColumns(); + grid.addColumn("firstName").setWidth(200); + grid.addColumn("lastName").setWidth(200); + grid.addColumn("email").setWidth(200); + + grid.setItems( + new Person("First", "last", "email", 242, Sex.UNKNOWN, null)); + + int frozen = 2; + if (request.getParameter("frozen") != null) { + frozen = Integer.parseInt(request.getParameter("frozen")); + } + grid.setFrozenColumnCount(frozen); + + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumns.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumns.java deleted file mode 100644 index 07a41337f2..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumns.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class InitialFrozenColumns extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.NONE); - - grid.addColumn("foo").setWidth(200); - grid.addColumn("bar").setWidth(200); - grid.addColumn("baz").setWidth(200); - - grid.addRow("a", "b", "c"); - - grid.setFrozenColumnCount(2); - - addComponent(grid); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java index 017ef14e2b..1a909e7a32 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java @@ -50,6 +50,26 @@ public class GridInitiallyHiddenColumnsTest extends SingleBrowserTest { } + @Test + public void ensureCorrectlyRenderedAllInitiallyHidden() { + openTestURL("debug&allHidden"); + GridElement grid = $(GridElement.class).first(); + + getSidebarOpenButton(grid).click(); + getColumnHidingToggle(grid, "First Name").click(); + getColumnHidingToggle(grid, "Last Name").click(); + getColumnHidingToggle(grid, "Age").click(); + getSidebarOpenButton(grid).click(); + + Assert.assertEquals("Umberto", grid.getCell(0, 0).getText()); + Assert.assertEquals("Rowling", grid.getCell(0, 1).getText()); + Assert.assertEquals("40", grid.getCell(0, 2).getText()); + Assert.assertEquals("Alex", grid.getCell(1, 0).getText()); + Assert.assertEquals("Barks", grid.getCell(1, 1).getText()); + Assert.assertEquals("25", grid.getCell(1, 2).getText()); + + } + // TODO: as to the getX methods reuse ones from GridBasicFeaturesTest? protected WebElement getSidebarOpenButton(GridElement grid) { diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/InitialFrozenColumnsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/InitialFrozenColumnsTest.java new file mode 100644 index 0000000000..58abe75731 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/InitialFrozenColumnsTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import static org.junit.Assert.assertTrue; + +import java.util.logging.Level; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class InitialFrozenColumnsTest extends MultiBrowserTest { + @Test + public void testInitialFrozenColumns() { + setDebug(true); + openTestURL(); + + Assert.assertFalse("Notification was present", + isElementPresent(NotificationElement.class)); + + WebElement cell = $(GridElement.class).first().getCell(0, 0); + assertTrue(cell.getAttribute("class").contains("frozen")); + } + + @Test + public void testInitialAllColumnsFrozen() { + setDebug(true); + openTestURL("frozen=3"); + + Assert.assertFalse("Notification was present", + isElementPresent(NotificationElement.class)); + assertNoDebugMessage(Level.SEVERE); + WebElement cell = $(GridElement.class).first().getCell(0, 2); + assertTrue(cell.getAttribute("class").contains("frozen")); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumnsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumnsTest.java deleted file mode 100644 index fec0087168..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumnsTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import static org.junit.Assert.assertTrue; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.elements.GridElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class InitialFrozenColumnsTest extends MultiBrowserTest { - @Test - public void testInitialFrozenColumns() { - setDebug(true); - openTestURL(); - - Assert.assertFalse("Notification was present", - isElementPresent(NotificationElement.class)); - - WebElement cell = $(GridElement.class).first().getCell(0, 0); - assertTrue(cell.getAttribute("class").contains("frozen")); - } -}