I have used Vaadin 7 before. There I could access UI thread from my child thread by using following code:
UI.getCurrent().access(() -> {
status.setVisible(true);
});
But currently, I am migrating from Vaadin 7 to Vaadin 8. In Vaadin 8 UI.getCurrent() returns null form the child thread. So how can we get access to UI thread from child thread?
The preferred pattern in Vaadin is to apply something MVP like (Model View Presenter).
When you create a View by extending a Layout has you can use getUI() method, which returns right UI instance when Layout & View is attached. This means that in your class implementing View you can also implement method that updates the status, say something like:
updateStatus(boolean visible) {
getUI().access(() -> {
status.setVisible(true);
});
}
If your application is prone to users closing browser eagerly, bad network conditions, etc. you may want to surround the access(..) in try catch and catch UIDetachedException, which may occur if browser connection is suddenly lost.
Your process in background thread can call this method safely, i.e. myView.updateStatus(true). Usually this is done via Presenter
presenter.getView().updateStatus(true);