Window Return

Good afternoon, it is possible to create a personal “form Window” and make the procedure that called wait for some kind of return …
I’m wanting to use it to create a query screen, where the procedure that has called the return

I think your question is missing the explanation half… What was your use case?

…and now that I actually have some time, I could hazard some generic answers, too…

The usual way would be to use listeners (say, CloseListener or ClickListener) to determine if/when you want to move on to the next method in your procedure, just like you would if the form was in your main layout. You can’t put the main thread on halt or the communication stops completely, but if your form in the window requires some external service calls, for example, you could use Futures to wait for the service call to complete or fail in their own thread and then deal with the results accordingly. If the resulting action demands UI changes from another thread you’ll also need some push/poll solution to alert the main thread. The positive side of the threaded version is that you can do other things in the main thread while you wait for the Futures to resolve, but it’s also a much more complex way to do it than just using listeners so I wouldn’t recommend going there without some actual need for threads.

Hi Anna,

What Haroldo mentioned is exactly what I need to do. Open a window, kick off a new thread that runs a query (while some kind of progress bar is running), and also having the option of killing the thread if needed via a button. I want to be able to stop the execution on the main thread and just wait until the new thread has finished.

Here is the code that created the new window:

Window sw = new Window("Receipt"); QueryRun qr = new QueryRun(this.transManager,transInfo,sw,myUi); sw.setImmediate(true); sw.setClosable(false); sw.setModal(true); sw.setContent(qr); sw.center(); sw.setHeight("250px"); sw.setWidth("350px"); sw.center(); myUi.addWindow(sw); Here is the code in the window (omitting some parts):

public QueryRun(TransactionManager transManager, TransactionInfo transInfo, final Window wi, MyPortletUI mUi)
.
.
.
this.mUi_This.setPollInterval(1000);
final Thread tr = new Thread(new Loader());
tr.start();




class Loader extends Thread {

        @Override
        public synchronized void run() {
            try {
                // Run the query here
            } catch (Exception e) {
            }

            mUi_This.access(new Runnable() {
                @Override
                public void run() {
                    addComponent(new Label("This is the real content"));
                    mUi_This.setPollInterval(-1);
                    //wi_This.close();
                }
            });
        }
    }

The polling aspect works correctly, the window is getting updated from the new thread. I just cannot get the main thread to wait for the new thread. I have also tried the typical Java “wait” and “notify” approach, but I am getting issues with when the window appears.

Thanks in advance!