Skip to content

Commit 4e13820

Browse files
Merge branch 'main' of github.com:qupath/qupath-extension-wsinfer
2 parents a049504 + 8561c22 commit 4e13820

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/main/java/qupath/ext/wsinfer/ui/WSInferController.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
import javafx.beans.binding.BooleanBinding;
2222
import javafx.beans.binding.ObjectBinding;
2323
import javafx.beans.binding.StringBinding;
24+
import javafx.beans.property.BooleanProperty;
2425
import javafx.beans.property.IntegerProperty;
2526
import javafx.beans.property.ObjectProperty;
27+
import javafx.beans.property.SimpleBooleanProperty;
2628
import javafx.beans.property.SimpleIntegerProperty;
2729
import javafx.beans.property.SimpleObjectProperty;
2830
import javafx.beans.property.StringProperty;
@@ -56,7 +58,6 @@
5658
import qupath.ext.wsinfer.WSInfer;
5759
import qupath.ext.wsinfer.models.WSInferModel;
5860
import qupath.ext.wsinfer.models.WSInferModelCollection;
59-
import qupath.ext.wsinfer.models.WSInferModelLocal;
6061
import qupath.ext.wsinfer.models.WSInferUtils;
6162
import qupath.fx.dialogs.Dialogs;
6263
import qupath.fx.dialogs.FileChoosers;
@@ -85,7 +86,6 @@
8586
import java.util.Set;
8687
import java.util.concurrent.ExecutorService;
8788
import 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

Comments
 (0)