Native window CloseListener not working

Hello :slight_smile:

I’ve got a problem with CloseListener, that is not working. I’ve tried a few demos and in those demos it did work, so I guess, the problem is somewhere in my code :frowning:

I have a class calles Isis (which extends the Application, therefore is an entry-point class).
It looks like this:

public class Isis extends Application {
	@Override
	public void init() {
		Window mainWindow = new Window("Isis Application");
		Label label = new Label("Hello Vaadin user");
		mainWindow.addComponent(label);

		Button btn = new Button("Start test app");
		btn.addListener(new ClickListener() {

			@Override
			public void buttonClick(ClickEvent event) {
				MyTestApp app = new MyTestApp(Isis.this);
				app.open(true);

			}
		});

		Button btn2 = new Button("Count windows");
		btn2.addListener(new ClickListener() {

			@Override
			public void buttonClick(ClickEvent event) {
				getMainWindow().showNotification(
						"I have " + getWindows().size() + " windows opened");

			}
		});

		mainWindow.addComponent(btn);
		mainWindow.addComponent(btn2);
		setMainWindow(mainWindow);
		mainWindow.addListener((CloseListener) this);

	}

}

Then, I have an abstract class IsisApplication, which extends Window and contains methods like Open and Close. In my design, each IsisApplication (class that will extend this one) should open in new browser-native window with some modifications. IsisApplication looks like this:


public abstract class IsisApplication extends Window implements CloseListener {
...
public IsisApplication(Isis isis) {
		this.isis = isis;
		...
                ....
		addListener((CloseListener) this);
	}
        ...
        public void open(boolean centerOnScreen) {
		if (isis.getWindow(getName()) == this) { 
			return;
		}
		while (isis.getWindow(getName()) != null) { 
			setRandomName();
		}

		isis.addWindow(this); //add myself to the Application

		if (centerOnScreen) { //this is irrelevant for native windows, I know :)
			center();
		}
		Dimension dim = getDefaultWindowDimension(); //my custom property
		isis.getMainWindow().open(new ExternalResource(getURL()), "_blank",
				dim.getWidth(), dim.getHeight(), Window.BORDER_NONE);


		setContent(isisApplicationRootView); //reference to the CustomComponent that will be displayed in part of this window's layout
	}
        ...
@Override
	public void windowClose(CloseEvent e) {
                boolean foo = false; //bogus line  for setting breakpoint in Eclipse
		applicationClosing(); //abstract method for signalling IsisApplications to destroy everything they should
		if ((isis.getWindows().contains(this))
				|| (isis.getWindow(getName()) == this)) {
			isis.removeWindow(this);
		}

	}

...
}

When I close the secondary native window, the event is not fired (breakpoint in Eclipse is not triggered) and there’s also no delay after pressing the X button on the window (which occurs when there is a window-close handler, to notify the server before the window actually closes).
I want to implement the WindowClose listener, so that I properly remove IsisApplications from the main application (removeWindow()) once their windows are closed, to avoid memory leaks.

What am I doing wrong here?