[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: How to set input on browser widget synchronously?

Could you add a progress listener (through Browser.addProgressListener) that waits for the load to complete?

http://help.eclipse.org/help31/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/browser/Browser.html#addProgressListener(org.eclipse.swt.browser.ProgressListener)

Stefan Mücke wrote:
Hi,

I am calling the execute method on a browser widget after calling its
input method. As the excute methods depends on the DOM tree, I have to
wait for the browser to complete loading the input. So far I've used a
LocationChangedListener to achieve this.

    public void showSomeInfo() {
        browser.setInput("<html>...</html>")
        isLoading = true;
        waitForBrowser();
        browser.execute(highlightScript);
    }

    private void waitForBrowser() {
        while (isLoading) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }

    public void changed(LocationEvent event) {
        isLoading = false;
    }

The problem here is that waitForBrowser() reads the event loop, causing
some others
events to be processed too early.

(My scenario: A listener list is iterated, with one listener calling
showSomeInfo(). The call to showSomeInfo() results in some messages
being processed. When showSomeInfo() returns, the listener list has been
changed by some event, resulting in a ConcurrentModificationException
being thrown.)

Is there any other way (or trick) to wait for the setInput(..) method to
complete without using display.readAndDispatch()?


Many thanks in advance,

Stefan Mücke