diff options
4 files changed, 34 insertions, 4 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index d289ee4897..b42cff2cab 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -4753,4 +4753,19 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, } } + @Override + public void setVisible(boolean visible) { + if (getEditor().isOpen() && !visible) { + getEditor().cancel(); + } + super.setVisible(visible); + } + + @Override + public void detach() { + if (getEditor().isOpen()) { + getEditor().cancel(); + } + super.detach(); + } } diff --git a/server/src/main/java/com/vaadin/ui/TabSheet.java b/server/src/main/java/com/vaadin/ui/TabSheet.java index a9ed1e9e02..5600745334 100644 --- a/server/src/main/java/com/vaadin/ui/TabSheet.java +++ b/server/src/main/java/com/vaadin/ui/TabSheet.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import org.jsoup.nodes.Attributes; import org.jsoup.nodes.Element; @@ -584,6 +585,10 @@ public class TabSheet extends AbstractComponentContainer */ private void setSelected(Component component) { Tab tab = tabs.get(selected); + if (tab != null && !Objects.equals(tab.getComponent(), component) && tab.getComponent() != null && tab.getComponent().isAttached()) { + tab.getComponent().detach(); + tab.getComponent().attach(); // ugly hack + } selected = component; // Repaint of the selected component is needed as only the selected 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 0deb5b1b3a..484452b6ac 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 @@ -792,6 +792,8 @@ public class GridBasics extends AbstractTestUIWithLog { editorMenu.addItem("Save", i -> grid.getEditor().save()); editorMenu.addItem("Cancel edit", i -> grid.getEditor().cancel()); + editorMenu.addItem("Hide grid", i -> grid.setVisible(false)); + editorMenu.addItem("Show grid", i -> grid.setVisible(true)); Stream.of(0, 5, 100).forEach(i -> editorMenu.addItem("Edit row " + i, menuItem -> grid.getEditor().editRow(i))); diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java index 832e5e6651..cd36a59d14 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java @@ -15,10 +15,6 @@ */ package com.vaadin.tests.components.grid.basics; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; @@ -32,6 +28,8 @@ import com.vaadin.testbench.TestBenchElement; import com.vaadin.testbench.elements.GridElement.GridCellElement; import com.vaadin.testbench.elements.GridElement.GridEditorElement; +import static org.junit.Assert.*; + public abstract class GridEditorTest extends GridBasicsTest { protected static final org.openqa.selenium.By BY_EDITOR_CANCEL = By @@ -58,6 +56,16 @@ public abstract class GridEditorTest extends GridBasicsTest { assertEditorClosed(); } + public void testEditorReopenAfterHide() { + editRow(5); + assertEditorOpen(); + selectMenuPath("Component", "Editor", "Hide grid"); + selectMenuPath("Component", "Editor", "Show grid"); + assertEditorClosed(); + editRow(5); + assertEditorOpen(); + } + @Test public void testKeyboardOpeningClosing() { |