I have the following code and the listener works when I click the ‘X’ in the modal window, but when I close the modal window with this code
((Window) getWindow().getParent()).removeWindow(getWindow());
the Window Close event never fires, how can I detect when the window was closed with either user clicking on the ‘X’ or the code?
// modal window code
subwindow = new Window("My Modal Window");
subwindow.setModal(true);
//
// create window close listener so we can refresh the grid after user closes the modal window
//
subwindow.addListener(new Window.CloseListener() {
@Override
public void windowClose(CloseEvent e) {
doDataGrid();
}
});
VerticalLayout layout = (VerticalLayout) subwindow.getContent();
layout.setMargin(true);
layout.setSpacing(true);
layout.setSizeUndefined();
MyForm ff = new MyForm();
subwindow.addComponent(ff);
getWindow().addWindow(subwindow);
Removing the window from code will not fire the close event. What you would like to do is to call window.close() which should be public but is currently protected (see
#3865 ). So the options are basically:
Extend Window, make close public and call it.
Manually call the close listener after you close the window using removeWindow.