|
@@ -10,15 +10,22 @@ import org.slf4j.LoggerFactory;
|
|
|
import javax.inject.Inject;
|
|
|
import javafx.beans.binding.Binding;
|
|
|
import javafx.beans.binding.BooleanBinding;
|
|
|
+import javafx.beans.property.BooleanProperty;
|
|
|
+import javafx.beans.property.IntegerProperty;
|
|
|
import javafx.beans.property.ObjectProperty;
|
|
|
+import javafx.beans.property.SimpleBooleanProperty;
|
|
|
+import javafx.beans.property.SimpleIntegerProperty;
|
|
|
import javafx.beans.property.SimpleObjectProperty;
|
|
|
import javafx.collections.FXCollections;
|
|
|
import javafx.collections.ObservableList;
|
|
|
import javafx.concurrent.Worker;
|
|
|
import javafx.fxml.FXML;
|
|
|
import javafx.scene.control.ListView;
|
|
|
+import javafx.scene.control.cell.CheckBoxListCell;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
@@ -35,8 +42,10 @@ public class CheckListController implements FxController {
|
|
|
private final SimpleObjectProperty<Worker<?>> runningTask;
|
|
|
private final Binding<Boolean> running;
|
|
|
private final Binding<Boolean> finished;
|
|
|
+ private final Map<HealthCheckTask, BooleanProperty> listPickIndicators;
|
|
|
+ private final IntegerProperty numberOfPickedChecks;
|
|
|
private final BooleanBinding anyCheckSelected;
|
|
|
- private final BooleanBinding readyToRun;
|
|
|
+ private final BooleanProperty showResultScreen;
|
|
|
|
|
|
/* FXML */
|
|
|
public ListView<HealthCheckTask> checksListView;
|
|
@@ -51,33 +60,35 @@ public class CheckListController implements FxController {
|
|
|
this.runningTask = new SimpleObjectProperty<>();
|
|
|
this.running = EasyBind.wrapNullable(runningTask).mapObservable(Worker::runningProperty).orElse(false);
|
|
|
this.finished = EasyBind.wrapNullable(runningTask).mapObservable(Worker::stateProperty).map(END_STATES::contains).orElse(false);
|
|
|
- this.readyToRun = runningTask.isNull();
|
|
|
+ this.listPickIndicators = new HashMap<>();
|
|
|
+ this.numberOfPickedChecks = new SimpleIntegerProperty(0);
|
|
|
+ this.tasks.forEach(task -> {
|
|
|
+ var entrySelectedProp = new SimpleBooleanProperty(false);
|
|
|
+ entrySelectedProp.addListener((observable, oldValue, newValue) -> numberOfPickedChecks.set(numberOfPickedChecks.get() + (newValue ? 1 : -1)));
|
|
|
+ listPickIndicators.put(task, entrySelectedProp);
|
|
|
+ });
|
|
|
this.anyCheckSelected = selectedTask.isNotNull();
|
|
|
+ this.showResultScreen = new SimpleBooleanProperty(false);
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
|
public void initialize() {
|
|
|
checksListView.setItems(tasks);
|
|
|
- checksListView.setCellFactory(ignored -> new CheckListCell());
|
|
|
+ checksListView.setCellFactory(CheckBoxListCell.forListView(listPickIndicators::get));
|
|
|
selectedTask.bind(checksListView.getSelectionModel().selectedItemProperty());
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
|
- public synchronized void runSelectedChecks() {
|
|
|
- startBatch(checksListView.getSelectionModel().getSelectedItems());
|
|
|
- }
|
|
|
-
|
|
|
- @FXML
|
|
|
- public synchronized void runAllChecks() {
|
|
|
- startBatch(checksListView.getItems());
|
|
|
- }
|
|
|
-
|
|
|
- private void startBatch(Iterable<HealthCheckTask> batch) {
|
|
|
+ public void runSelectedChecks() {
|
|
|
Preconditions.checkState(runningTask.get() == null);
|
|
|
+ var batch = checksListView.getItems().filtered(item -> listPickIndicators.get(item).get());
|
|
|
var batchService = new BatchService(batch);
|
|
|
batchService.setExecutor(executorService);
|
|
|
batchService.start();
|
|
|
runningTask.set(batchService);
|
|
|
+ checksListView.setCellFactory(view -> new CheckListCell());
|
|
|
+ showResultScreen.set(true);
|
|
|
+ checksListView.getSelectionModel().select(batch.getViewIndex(0));
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
@@ -95,17 +106,8 @@ public class CheckListController implements FxController {
|
|
|
LOG.error("Failed to write health check report.", e);
|
|
|
}
|
|
|
}
|
|
|
- /* Getter/Setter */
|
|
|
-
|
|
|
-
|
|
|
- public boolean isReadyToRun() {
|
|
|
- return readyToRun.get();
|
|
|
- }
|
|
|
-
|
|
|
- public BooleanBinding readyToRunProperty() {
|
|
|
- return readyToRun;
|
|
|
- }
|
|
|
|
|
|
+ /* Getter/Setter */
|
|
|
public boolean isRunning() {
|
|
|
return running.getValue();
|
|
|
}
|
|
@@ -130,4 +132,21 @@ public class CheckListController implements FxController {
|
|
|
return anyCheckSelected;
|
|
|
}
|
|
|
|
|
|
+ public boolean getShowResultScreen() {
|
|
|
+ return showResultScreen.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ public BooleanProperty showResultScreenProperty() {
|
|
|
+ return showResultScreen;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getNumberOfPickedChecks() {
|
|
|
+ return numberOfPickedChecks.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ public IntegerProperty numberOfPickedChecksProperty() {
|
|
|
+ return numberOfPickedChecks;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|