How to detect if a Window is still open?

HI,

how can I detect if a non-modal Window is still active and not closed?
Window window = new Window(“my non modal window”);
UI.getCurrent().addWindow(window);

I the user clicks twice eg on a link that would trigger the Window - how can I detect if the window is still active (and therefore prevent a 2nd duplicate window)?

window.isVisible(); does not work.

Thanks

Use a Window.CloseListener to detect when the window gets closed.

Yes I know I can detect the close ACTION with this. But how can I know - if a user clicks a link that triggers a popup - if the popup is still visible to the user?

Are there better ways apart from introducing a boolean isVisible; variable that I set/unset within Window.CloseListener?

Well you could do it in one of these ways i just had in mind:

  • Handle it through a seperate isVisible Variable in the class in which you’re adding the window.
  • Extend the Window-class and add a variable there which gets set by the attach and detach event.
  • Use Attach- and DetachEventListener in your main class
  • Check if the window is still visible by checking if it has a parent with getParent() (Not sure if this still works in Vaadin 7)
  • Set the variable/instance of the window to null when you remove it. This way you can check it if(window==null) //Not visible
  • If you open the same instance/variable of the Window in the link (i mean if you’re not recreating/creating the window every time you click it) it shouldn’t open multiple windows but maybe throw an exception

Additional: The isVisible method just checks the Visibility Property which you can set through setVisible(boolean)

Can you not use the isAttached() method?
This will give you the boolean if a window is still active or has been closed.

Check if the window’s parent is null.
if(window.getParent() == null){
// window is closed.
//open the window
}else{
//do something else
}