I can not force to update the progressBar to be updated from the thread (FeederThread).
The button should be pressed,next the stream starts, the progressBar should appear. What wrong?
@SpringComponent
@UIScope
@Push
@Route("push")
public class UploadEditor extends VerticalLayout {
private FeederThread feederThread;
private ProgressBar bar;
private void progresBarChanche(boolean value) {
bar.setVisible(value);
bar.setIndeterminate(value);
}
@Override
protected void onAttach(AttachEvent attachEvent) {
}
@Override
protected void onDetach(DetachEvent detachEvent) {
// Cleanup
feederThread.interrupt();
feederThread = null;
}
public UploadEditor() {
setup();
}
private void setup() {
VerticalLayout progresLayout = new VerticalLayout();
bar = new ProgressBar();
progresLayout.add(bar);
bar.setVisible(false);
HorizontalLayout layoutBtn = new HorizontalLayout();
Button startBtn = new Button(" Start Thread", VaadinIcon.DATABASE.create());
Button cancelBtn = new Button("Отмена");
cancelBtn.setSizeFull();
startBtn.setSizeFull();
layoutBtn.add(cancelBtn, startBtn);
layoutBtn.setSizeFull();
startBtn.addClickListener((event) -> {
feederThread = new FeederThread(getUI().get(), this);
feederThread.start();
});
add(progresLayout, layoutBtn);
setAlignItems(FlexComponent.Alignment.CENTER);
}
}
private class FeederThread extends Thread {
private final UI ui;
private final UploadEditor view;
public FeederThread(UI ui, UploadEditor view) {
this.ui = ui;
this.view = view;
}
@Override
public void run() {
int count = 0;
try {
ui.access(() -> {view.progresBarChanche(true); ui.push();});
while (count < 10) {
// Sleep to emulate background work
Thread.sleep(500);
System.out.println(count++);
// ui.access(() -> view.add(new Span(message)));
}
// Inform that we are done
ui.access(() -> {
view.progresBarChanche(false);
});
}catch (InterruptedException e){
e.printStackTrace();
}
}
}
maybe the problem is that I call UploadEditor by :
Dialog dialog = new Dialog();
dialog.add(uploadEditor);
dialog.open();
from mymain page ?
maybe should turn on the push somewhere else?
If I verifying System.out.println(getUI().get().getPushConfiguration().getPushMode()); I get DISABLED