2121import javafx .beans .binding .BooleanBinding ;
2222import javafx .beans .binding .ObjectBinding ;
2323import javafx .beans .binding .StringBinding ;
24+ import javafx .beans .property .BooleanProperty ;
2425import javafx .beans .property .IntegerProperty ;
2526import javafx .beans .property .ObjectProperty ;
27+ import javafx .beans .property .SimpleBooleanProperty ;
2628import javafx .beans .property .SimpleIntegerProperty ;
2729import javafx .beans .property .SimpleObjectProperty ;
2830import javafx .beans .property .StringProperty ;
5658import qupath .ext .wsinfer .WSInfer ;
5759import qupath .ext .wsinfer .models .WSInferModel ;
5860import qupath .ext .wsinfer .models .WSInferModelCollection ;
59- import qupath .ext .wsinfer .models .WSInferModelLocal ;
6061import qupath .ext .wsinfer .models .WSInferUtils ;
6162import qupath .fx .dialogs .Dialogs ;
6263import qupath .fx .dialogs .FileChoosers ;
8586import java .util .Set ;
8687import java .util .concurrent .ExecutorService ;
8788import java .util .concurrent .Executors ;
88- import java .util .concurrent .ForkJoinPool ;
8989
9090
9191/**
@@ -141,6 +141,7 @@ public class WSInferController {
141141 private final ExecutorService pool = Executors .newSingleThreadExecutor (ThreadTools .createThreadFactory ("wsinfer" , true ));
142142
143143 private final ObjectProperty <Task <?>> pendingTask = new SimpleObjectProperty <>();
144+ private final BooleanProperty downloadPending = new SimpleBooleanProperty (false );
144145
145146 @ FXML
146147 private void initialize () {
@@ -161,7 +162,7 @@ private void initialize() {
161162 configureBatchSize ();
162163
163164 configureMessageLabel ();
164- configureRunInferenceButton ();
165+ configureButtons ();
165166
166167 configurePendingTaskProperty ();
167168 }
@@ -191,8 +192,6 @@ void refreshAvailableModels() {
191192 modelChoiceBox .setConverter (new ModelStringConverter (models ));
192193 modelChoiceBox .getSelectionModel ().selectedItemProperty ().addListener (
193194 (v , o , n ) -> {
194- downloadButton .setDisable ((n == null ) || n .isValid ());
195- infoButton .setDisable ((n == null ) || (!n .isValid ()) || !checkFileExists (n .getReadMeFile ()));
196195 infoPopover .hide ();
197196 });
198197 }
@@ -216,14 +215,29 @@ private void configureAvailableDevices() {
216215 (value , oldValue , newValue ) -> WSInferPrefs .deviceProperty ().set (newValue ));
217216 }
218217
219- private void configureRunInferenceButton () {
218+ private void configureButtons () {
220219 // Disable the run button while a task is pending, or we have no model selected, or download is required
221220 runButton .disableProperty ().bind (
222221 imageDataProperty .isNull ()
223222 .or (pendingTask .isNotNull ())
224223 .or (modelChoiceBox .getSelectionModel ().selectedItemProperty ().isNull ())
225224 .or (messageTextHelper .warningText .isNotEmpty ())
226225 );
226+ downloadButton .disableProperty ().bind (
227+ Bindings .createBooleanBinding (
228+ () -> modelChoiceBox .getSelectionModel ().getSelectedItem () == null || modelChoiceBox .getSelectionModel ().getSelectedItem ().isValid (),
229+ modelChoiceBox .getSelectionModel ().selectedItemProperty (),
230+ downloadPending )
231+ );
232+ infoButton .disableProperty ().bind (
233+ Bindings .createBooleanBinding (
234+ () -> {
235+ var n = modelChoiceBox .getSelectionModel ().getSelectedItem ();
236+ return n == null || !n .isValid () || !checkFileExists (n .getReadMeFile ());
237+ },
238+ modelChoiceBox .getSelectionModel ().selectedItemProperty (),
239+ downloadPending )
240+ );
227241 }
228242
229243 private void configurePendingTaskProperty () {
@@ -357,7 +371,7 @@ public void downloadModel() {
357371 return ;
358372 }
359373
360- ForkJoinPool . commonPool ().execute (() -> {
374+ Thread . ofVirtual ().start (() -> {
361375 model .removeCache ();
362376 showDownloadingModelNotification (model .getName ());
363377 try {
@@ -367,9 +381,9 @@ public void downloadModel() {
367381 return ;
368382 }
369383 showModelAvailableNotification (model .getName ());
370- downloadButton .setDisable (true );
371- infoButton .setDisable (model instanceof WSInferModelLocal );
384+ downloadPending .set (false );
372385 });
386+ downloadPending .set (true );
373387 }
374388
375389 /**
0 commit comments