I'm using Eclipse RAP and have the following use case:
Text
field and start searchLabel
text to "searching...."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:
Text
field and start searchLabel
text to "searching...."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 ....);
}