ciao andbin!
Sì, certo. Una soluzione: passare il Task<Void> task al execTask(). Ma non è l'unica soluzione!
intendi una cosa del genere:
codice:
public class BackgroundTask {
public void execTask(Task<Void> task) throws InterruptedException {
LoadingDialog loadingDialog = new LoadingDialog();
loadingDialog.activateProgressBar(task);
task.setOnSucceeded(event -> {
loadingDialog.getDialogStage().close();
});
task.setOnCancelled(event -> {
loadingDialog.getDialogStage().close();
});
loadingDialog.getDialogStage().show();
Thread thread = new Thread(task);
thread.start();
}
}
per poi fare:
codice:
private void updateBooks() {
try {
BackgroundTask bt = new BackgroundTask();
Task<Void> task = new Task<Void>() {
@Override
public Void call() throws InterruptedException {
try {
jsb.launchService("all_books");
jsb.launchService("all_authors");
jsb.launchService("all_editors");
jsb.launchService("graph_authors");
jsb.launchService("graph_editors");
jsb.download(UrlAndPath.JSON_LIBRI);
jsb.download(UrlAndPath.JSON_AUTORI);
jsb.download(UrlAndPath.JSON_EDITORI);
setTable();
} catch (IOException e) {
GenericDialog.showDialog(e.getMessage(), Alert.AlertType.ERROR);
}
return null;
}
};
bt.execTask(task);
} catch (InterruptedException e) {
}
}
??
Tra l'altro c'è una questione: BackgroundTask non ha "stato" (non vedo sue variabili di istanza, almeno per quanto postato). Quindi una istanza di BackgroundTask a chi/cosa serve?
uhm penso di non aver capito bene che intendi!