简体   繁体   中英

In Eclipse RAP how to push/force current UI state to the client?

I'm using Eclipse RAP and have the following use case:

  • enter search text in a Text field and start search
  • change a Label text to "searching...."
  • do actual search (async) and display result in a Table

The problem, even though the label should change to "searching...." before the actual search is started, it is changed to "searching...." after the search is done.

What I'm looking for is a way to push/force/update the current UI state to the client after the label changed, prior to searching:

  • enter search text in a Text field and start search
  • change a Label text to "searching...."
  • push current UI state to client
  • do actual search (async) and display result in a Table

Here some sample code:

    Label statusLabel = new Label(parent, SWT.NONE);
    Text searchText = new Text(parent, SWT.SEARCH);
    searchText.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // change label
            statusLabel.setText("searching...");

            // HERE force client update

            // start searching
            Display.getCurrent().asyncExec(new Runnable() {
                @Override
                public void run() {
                    // do actual search
                }
            });
        }
    });

asyncExec still runs the code in the UI thread it just delays it slightly until the next call to Display.readAndDispatch . So your search code will still block and isn't allowing the label to update.

You need to actually run the search in a separate thread.

asyncExec is intended to be used in a background thread to run a small amount of code in the UI thread when possible. (You need to use Display.getDefault() rather than Display.getCurrent() in a background thread).

So in your background thread you do something like:

while (more to do)
 {
   .... do a step of the search

   Display.getDefault().asyncExec(.... UI update code ....);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM