* </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() {
} else {
// subwindow is removed from parent
parent.removeWindow(this);
- fireClose();
}
}
* 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 {
* 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
/**
* 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();
}
--- /dev/null
+<?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>
--- /dev/null
+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