Modal Window

Hi I am new in vaadin but I think that it’s very interesting.

So my Question is about modal calls and i face problems to perform that since the calback function is not in the same class :frowning:

To explain more, we have the main window of the application that raises many modal sub-windows. In swing there is not a problem cause the tread will stop until the modal window is closed and all the actions performed after the modal window will be executed after the closing of the raised modal window. But in Vaadin it’s not the same concept, the thread continue its work even if the modal window is not closed so all the sequences of the action will be faulted and we have not the same functioning of the application as swing. The problem also is that the modal window can be raised in different stages : For example, there is a java method A that calls another method B in another class and the modal window is launched via the method B. So in swing all the methods A and B will be stopped until the modal window is closed. But in vaadin we face a problem in separating actions performed in the methods A and B since they are not in the same class.

In addition, the modal window is not closed by the “X” button but its closed by removing it from the main window so performing all the actions done after the modal window can’t be done in a “Window.closeListener” and performing all the action in a method launched after the closing of the modal window can’t be done cause some actions are performed in another class.

To help you more to understand what I am talking about I give you this example :

the class A contains the method m1 :

public class A {
public void m1() {
Action 1
Action2 : B b = new B (instance of class B)
Action 3 : (calling m2 in class B : b.m2)
Action 4
Action 5
}
}

public class B {
public void m2() {
Action 1
Action2
Action 3 : (Raises a modal window)
Action 4
Action 5
}
}

In this example, the modal window is raised by the method m2 in the class B but the method m1 in class A calls the method m2. In swing, Action 4, Action 5 in class A and Action 4, Action 5 in class B will not be run until the modal window is closed. But in Vaadin if I act like this :

public class B {
public void m2() {
Action 1
Action2
Action 3 : (Raises a modal window)
modalwindow.addListener(new Window.closeListener() {
B.Action 4
B.Action 5
});
}
}

The actions (Action 4 and Action 5) in the class A will be executed after the modal window is shown and it’s not possible to do them in the close listener cause the actions are not accessible from an another class (class B for example)

Is there any idea???

Ok, quite verbose but I think I understood what you are looking after :slight_smile:

The case behind this is the event driven nature of the components combined with the fact that we are running in a request-response communication. I’m not sure how swing handles this as basically it is the same…

Anyhow, For closing and invoking the listeners in the window: inherit the Window class and add the following function:

public void closeWindow() { super.close(); }

This is a workaround to make it invoke the CloseListeners when you call your new closeWindow function. (I think it maybe even considered as a bug in Vaadin that the close function is protected not public).

After this, I think the “action chaining pattern” you suggested might be a the way to go.

Quite true:
#3865: It should be possible to close a sub window from code

Thanks for all your responses :slight_smile:
Yes the problem is that the close method is protected and the closeListener is not activated if we close the subWindow by removing it from the main window. I found a solution by creating a class that extending from Window class in order to use the close method and it works perfectly :slight_smile:

thanks