null window parent, but shouldn't be

I’m attaching a sub-window to the main window of my application to display a dialog box. I’ve got an listener for when the dialog is closed, and when it’s called, I process whatever the user set in the dialog and save it back to the main application.

The problem is I can’t get back to the main application. getApplication() returns null, getParent() returns null, and getWindow() returns the dialog window, not it’s parent as the javadocs suggest it does.

What’s the catch here? I realize as a workaround I can pass in my main application to the dialog, but I should not need to do that.

Thanks.

Michael

Umm, yeah. It looks like a sub-window is detached from the parent window and hence from the application
before
the close event is fired. Therefore, the getApplication() and getParent() return null for a sub-window in a close listener.

You can store the reference to the application-level window (usually the main window) and use it from the close listener, for example as follows:

// The sub-window will be attached to the main window
final Window main = getWindow();

// Create a sub-window and add it to the main window
Window sub = new Window("Close Me");
sub.center();
main.addWindow(sub);

sub.addListener(new CloseListener() {
    public void windowClose(CloseEvent e) {
        layout.addComponent(new Label("Sub-window of "+
                main.getCaption() + " was closed"));
    }
});

See the
on-line example
.

Ok, thanks, I appreciate the clarification.