From 6431d2e97ab8b4b7c2807d03aa16f6e70188c739 Mon Sep 17 00:00:00 2001 From: Artur Date: Tue, 10 Jan 2017 15:22:31 +0200 Subject: [PATCH] Fix exception when Grid is inside a PopupView (#8157) Fixes #7695 --- .../java/com/vaadin/client/ui/VPopupView.java | 11 +++-- .../GridLayout/GridInPopupView.java | 45 +++++++++++++++++++ .../GridLayout/GridInPopupViewTest.java | 25 +++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 uitest/src/main/java/com/vaadin/tests/layouts/layouttester/GridLayout/GridInPopupView.java create mode 100644 uitest/src/test/java/com/vaadin/tests/layouts/layouttester/GridLayout/GridInPopupViewTest.java diff --git a/client/src/main/java/com/vaadin/client/ui/VPopupView.java b/client/src/main/java/com/vaadin/client/ui/VPopupView.java index 11a38b6737..28ad7d66c4 100644 --- a/client/src/main/java/com/vaadin/client/ui/VPopupView.java +++ b/client/src/main/java/com/vaadin/client/ui/VPopupView.java @@ -373,9 +373,14 @@ public class VPopupView extends HTML } } else if (popupComponentWidget2 instanceof HasWidgets) { HasWidgets hw = (HasWidgets) popupComponentWidget2; - Iterator iterator = hw.iterator(); - while (iterator.hasNext()) { - checkForRTE(iterator.next()); + try { + Iterator iterator = hw.iterator(); + while (iterator.hasNext()) { + checkForRTE(iterator.next()); + } + } catch (UnsupportedOperationException e) { + // At least Grid refuses to provide child widgets through + // iterator() } } } diff --git a/uitest/src/main/java/com/vaadin/tests/layouts/layouttester/GridLayout/GridInPopupView.java b/uitest/src/main/java/com/vaadin/tests/layouts/layouttester/GridLayout/GridInPopupView.java new file mode 100644 index 0000000000..ad76fb2ee5 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/layouts/layouttester/GridLayout/GridInPopupView.java @@ -0,0 +1,45 @@ +package com.vaadin.tests.layouts.layouttester.GridLayout; + +import com.vaadin.event.SelectionEvent; +import com.vaadin.event.SelectionEvent.SelectionListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.util.Person; +import com.vaadin.tests.util.PersonContainer; +import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; +import com.vaadin.ui.PopupView; +import com.vaadin.ui.PopupView.Content; +import com.vaadin.ui.VerticalLayout; + +public class GridInPopupView extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(PersonContainer.createWithTestData(100)); + grid.addSelectionListener(new SelectionListener() { + @Override + public void select(SelectionEvent event) { + String sel = ""; + for (Object o : event.getSelected()) { + sel += ((Person) o).getFirstName(); + } + log("Selection: " + sel); + } + }); + PopupView pv = new PopupView(new Content() { + @Override + public Component getPopupComponent() { + return new VerticalLayout(grid); + } + + @Override + public String getMinimizedValueAsHTML() { + return "foo"; + } + }); + pv.setHideOnMouseOut(false); + addComponent(pv); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/layouts/layouttester/GridLayout/GridInPopupViewTest.java b/uitest/src/test/java/com/vaadin/tests/layouts/layouttester/GridLayout/GridInPopupViewTest.java new file mode 100644 index 0000000000..6a04119c44 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/layouts/layouttester/GridLayout/GridInPopupViewTest.java @@ -0,0 +1,25 @@ +package com.vaadin.tests.layouts.layouttester.GridLayout; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.PopupViewElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class GridInPopupViewTest extends SingleBrowserTest { + + @Test + public void popupViewClosedProperly() { + openTestURL(); + PopupViewElement pv = $(PopupViewElement.class).first(); + pv.click(); + GridElement grid = $(GridElement.class).first(); + grid.getCell(5, 0).click(); + findElement(By.className("v-ui")).click(); + + Assert.assertTrue($(GridElement.class).all().isEmpty()); + Assert.assertEquals("1. Selection: Alice", getLogRow(0)); + } +} -- 2.39.5