Search code examples
vaadinvaadin7

Pause program while waiting for input from a subwindow


I'm new to Vaadin and could use some help.

Scenario: My webapp has a button called "import" and when you click it, you can pick a file to import and then it opens a new window which shows the progress. During the import, the program reads the content of the file and in some cases it needs some additional info from the user before it can continue. In this case I would like to open an aditional window (a simple textfield for input and an enter-button) in which the user can input the missing info. Only when the user hits the enter-button should be program continue to handle the import of the file.

What I have tried: I have created a class "ImportWindow" which extends Window. From this class I call a method called "handleFileContent()" in a class called "FileReader", which reads through the content of the file. I have created an additional class "AdditionalInfoPopUp" with extends Window. When "handleFileContent()" reaches a part of the file where it needs more info, I have the following code:

AdditionalInfoPopUp apwindow = new AdditionalInfoPopUp();
UI.getCurrent().addWindow(apwindow);

while (!apwindow.isCompleted()){
    // wait for user input
    try {
        Thread.sleep(5000);
    } catch(InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
}

"isCompleted()" is a method that returns the value of a boolean, which I set to true when the enter-button in the new AdditionalInfoPopUp is clicked.

Problem: The AdditionalInfoPopUp is never opened. If I remove the while-loop then it opens when the program has read the rest of the file. But I need it to open right away, so I can get the aditional info before I continue.

I've tried searching for help, but I haven't been able to find anything. So I hope someone on here can help.


Solution

  • You need to first read all the uploadfile.

    Then afterward you can add your logic to ask the user for additional informations.

    If processing is done in a background thread, read this.