]> source.dussan.org Git - vaadin-framework.git/commitdiff
#3865 closing sub-windows from code should send close event, test for window closing
authorHenri Sara <henri.sara@itmill.com>
Thu, 28 Oct 2010 08:58:56 +0000 (08:58 +0000)
committerHenri Sara <henri.sara@itmill.com>
Thu, 28 Oct 2010 08:58:56 +0000 (08:58 +0000)
svn changeset:15758/svn branch:6.5

WebContent/release-notes.html
src/com/vaadin/ui/Window.java
tests/src/com/vaadin/tests/components/window/CloseSubWindow.html [new file with mode: 0644]
tests/src/com/vaadin/tests/components/window/CloseSubWindow.java [new file with mode: 0644]

index 308b1417d05a1ca2c037ea75b0ba337e59ca6ccc..727eaac791e99f7e0426317daf5e35d7f602ba51 100644 (file)
@@ -51,6 +51,9 @@ contains a number of significant enhancements.</p>
 
 <ul>
   <li>Table.setColumnCollapsed throws IllegalStateException instead of IllegalAccessException is collapsing is not allowed.</li>
+  <li>Window.removeWindow(Window) now triggers window close listeners also when called explicitly.
+      See <a href="http://dev.vaadin.com/ticket/3865">#3865</a> for more info.
+  </li>
 </ul>
 
 <ul>
index fde6058f9305e12f2ddc8119db66b79fc4751309..fed7dabd3674b2c4b422c6295f193eee40c76896 100644 (file)
@@ -1102,11 +1102,9 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
      * </p>
      * 
      * <p>
-     * If one wants change the default behavior, register a window close
-     * listenter and do something else. For example, you could re-open the
-     * browser-level window with mainWindow.open(), re-add the removed
-     * sub-window back to its parent or remove browser-level window
-     * automatically from the application.
+     * To explicitly close a sub-window, use {@link #removeWindow(Window)}. To
+     * react to a window being closed (after it is closed), register a
+     * {@link CloseListener}.
      * </p>
      */
     protected void close() {
@@ -1116,7 +1114,6 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
         } else {
             // subwindow is removed from parent
             parent.removeWindow(this);
-            fireClose();
         }
     }
 
@@ -1250,8 +1247,8 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
      * user closes the window.
      * 
      * <p>
-     * Note that removing windows using {@link #removeWindow(Window)} will not
-     * fire the CloseListener.
+     * Since Vaadin 6.5, removing windows using {@link #removeWindow(Window)}
+     * does fire the CloseListener.
      * </p>
      */
     public interface CloseListener extends Serializable {
@@ -1277,8 +1274,8 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
      * mean it will be destroyed.
      * 
      * <p>
-     * Note that removing windows using {@link #removeWindow(Window)} will not
-     * fire the CloseListener.
+     * Since Vaadin 6.5, removing windows using {@link #removeWindow(Window)}
+     * does fire the CloseListener.
      * </p>
      * 
      * @param listener
@@ -1431,12 +1428,16 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
     /**
      * Remove the given subwindow from this window.
      * 
+     * Since Vaadin 6.5, {@link CloseListener}s are called also when explicitly
+     * removing a window by calling this method.
+     * 
      * @param window
      *            Window to be removed.
      */
     public void removeWindow(Window window) {
         subwindows.remove(window);
         window.setParent(null);
+        window.fireClose();
         requestRepaint();
 
     }
diff --git a/tests/src/com/vaadin/tests/components/window/CloseSubWindow.html b/tests/src/com/vaadin/tests/components/window/CloseSubWindow.html
new file mode 100644 (file)
index 0000000..d4d404f
--- /dev/null
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>CloseSubWindow</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">CloseSubWindow</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.window.CloseSubWindow</td>
+       <td></td>
+</tr>
+<tr>
+       <td>waitForVaadin</td>
+       <td></td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentswindowCloseSubWindow::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentswindowCloseSubWindow::/VWindow[0]/ScrollPanel[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>closeNotification</td>
+       <td>//body/div[2]</td>
+       <td>0,0</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentswindowCloseSubWindow::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentswindowCloseSubWindow::/VWindow[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>4,4</td>
+</tr>
+<tr>
+       <td>closeNotification</td>
+       <td>//body/div[2]</td>
+       <td>0,0</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentswindowCloseSubWindow::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>waitForPopUp</td>
+       <td>nativewindow</td>
+       <td>30000</td>
+</tr>
+<tr>
+       <td>selectWindow</td>
+       <td>name=nativewindow</td>
+       <td></td>
+</tr>
+<tr>
+       <td>close</td>
+       <td></td>
+       <td></td>
+</tr>
+<tr>
+       <td>selectWindow</td>
+       <td>title=com.vaadin.tests.components.window.CloseSubWindow</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentswindowCloseSubWindow::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/src/com/vaadin/tests/components/window/CloseSubWindow.java b/tests/src/com/vaadin/tests/components/window/CloseSubWindow.java
new file mode 100644 (file)
index 0000000..fc8f20f
--- /dev/null
@@ -0,0 +1,103 @@
+package com.vaadin.tests.components.window;\r
+\r
+import java.net.URL;\r
+\r
+import com.vaadin.terminal.ExternalResource;\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Label;\r
+import com.vaadin.ui.Window;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.Button.ClickListener;\r
+import com.vaadin.ui.Window.CloseEvent;\r
+import com.vaadin.ui.Window.CloseListener;\r
+\r
+public class CloseSubWindow extends TestBase {\r
+\r
+    private Window browserWindow;\r
+\r
+    @Override\r
+    protected void setup() {\r
+        Button openWindowButton = new Button("Open sub-window");\r
+        openWindowButton.addListener(new ClickListener() {\r
+            public void buttonClick(ClickEvent event) {\r
+                Window sub = createClosableSubWindow("Sub-window");\r
+                getMainWindow().addWindow(sub);\r
+            }\r
+        });\r
+\r
+        addComponent(openWindowButton);\r
+\r
+        Button openBrowserWindowButton = new Button("Open browser window");\r
+        openBrowserWindowButton.addListener(new ClickListener() {\r
+            public void buttonClick(ClickEvent event) {\r
+                browserWindow = new Window("Window");\r
+                browserWindow.addComponent(new Label("Close this window"));\r
+\r
+                browserWindow.addListener(new CloseListener() {\r
+                    public void windowClose(CloseEvent e) {\r
+                        getMainWindow().showNotification(\r
+                                "Browser window closed");\r
+                        // there is no push, so the user needs to click a button\r
+                        // to see the notification\r
+\r
+                        // Opera does not send a notification about the window\r
+                        // having been closed\r
+                    }\r
+                });\r
+\r
+                addWindow(browserWindow);\r
+                URL windowUrl = browserWindow.getURL();\r
+                // named for easier access by test tools\r
+                getMainWindow().open(new ExternalResource(windowUrl),\r
+                        "nativewindow");\r
+            }\r
+        });\r
+\r
+        addComponent(openBrowserWindowButton);\r
+\r
+        addComponent(new Button("Poll server"));\r
+    }\r
+\r
+    private Window createClosableSubWindow(final String title) {\r
+        final Window window = new Window(title);\r
+        window.setSizeUndefined();\r
+        window.getContent().setSizeFull();\r
+        window.setClosable(true);\r
+\r
+        Button closeButton = new Button("Close");\r
+        closeButton.addListener(new ClickListener() {\r
+            public void buttonClick(ClickEvent event) {\r
+                window.getParent().removeWindow(window);\r
+            }\r
+        });\r
+        window.addComponent(closeButton);\r
+\r
+        Button removeButton = new Button("Remove from parent");\r
+        removeButton.addListener(new ClickListener() {\r
+            public void buttonClick(ClickEvent event) {\r
+                window.getParent().removeWindow(window);\r
+            }\r
+        });\r
+        window.addComponent(closeButton);\r
+\r
+        window.addListener(new CloseListener() {\r
+            public void windowClose(CloseEvent e) {\r
+                getMainWindow().showNotification(title + " closed");\r
+            }\r
+        });\r
+\r
+        return window;\r
+    }\r
+\r
+    @Override\r
+    protected String getDescription() {\r
+        return "Close sub-windows both from code and with the close button in the window title bar, and check for close events.";\r
+    }\r
+\r
+    @Override\r
+    protected Integer getTicketNumber() {\r
+        return 3865;\r
+    }\r
+\r
+}\r