When I click a button, I want to do 2 things: first, to open a Dialog, and second, to execute a method (which is in a jar file). The problem is that, when I click the button, first it is executed the method and after that, the Dialog is opened. The code is something like this:
button.addClickListener(event -> start());
public void start() {
dialog.open(); //Second, it opens the Dialog
methodInJar(); //First it executes this method
}
Note: The same thing happens regardless of whether it is a Dialog, a Notification or any change in the interface.
Does anyone know where is the problem?
Thank you.
PD. This is the whole class:
package com.example.test;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.page.Push;
import com.vaadin.flow.router.Route;
@Route("myView")
@Push
public class MyView extends VerticalLayout {
private UI ui;
private Dialog dialog = new Dialog();
public MyView(){
addAttachListener(event -> {
this.ui = event.getUI();
});
add(new Button("some button", click -> start()));
}
private void start(){
this.ui.access(() -> {
dialog.open();
});
methodInJarTest();
}
private void methodInJarTest() {
try {
System.out.println("JAR test - 10 seconds pause");
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}