From 9d89efc98c79547c9e2705937865494c6e552b9a Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 18 May 2021 09:09:53 +0200 Subject: [PATCH] Unify interface: * move all buttons to one button bar * switch between runAll and runSelected, depending on list selection * add a little localization --- .../ui/health/CheckController.java | 37 ++++++++++++++----- .../src/main/resources/fxml/health_check.fxml | 22 ++++++----- .../main/resources/i18n/strings.properties | 2 + 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/health/CheckController.java b/main/ui/src/main/java/org/cryptomator/ui/health/CheckController.java index cd5c44a40..b7115e2d5 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/health/CheckController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/health/CheckController.java @@ -12,6 +12,9 @@ import javafx.beans.binding.Binding; import javafx.beans.binding.BooleanBinding; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.concurrent.Worker; @@ -19,6 +22,7 @@ import javafx.fxml.FXML; import javafx.scene.control.ListView; import java.io.IOException; import java.util.Collection; +import java.util.ResourceBundle; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -32,27 +36,31 @@ public class CheckController implements FxController { private final ReportWriter reportWriter; private final ExecutorService executorService; private final ObjectProperty selectedTask; + private final ResourceBundle resourceBundle; private final SimpleObjectProperty> runningTask; private final Binding running; private final Binding finished; private final BooleanBinding anyCheckSelected; private final BooleanBinding readyToRun; + private final StringProperty runButtonDescription; /* FXML */ public ListView checksListView; @Inject - public CheckController(Lazy> tasks, ReportWriter reportWriteTask, ObjectProperty selectedTask, ExecutorService executorService) { + public CheckController(Lazy> tasks, ReportWriter reportWriteTask, ObjectProperty selectedTask, ExecutorService executorService, ResourceBundle resourceBundle) { this.tasks = FXCollections.observableArrayList(tasks.get()); this.reportWriter = reportWriteTask; this.executorService = executorService; this.selectedTask = selectedTask; + this.resourceBundle = resourceBundle; this.runningTask = new SimpleObjectProperty<>(); this.running = EasyBind.wrapNullable(runningTask).mapObservable(Worker::runningProperty).orElse(false); this.finished = EasyBind.wrapNullable(runningTask).mapObservable(Worker::stateProperty).map(endStates::contains).orElse(false); this.readyToRun = runningTask.isNull(); this.anyCheckSelected = selectedTask.isNotNull(); + this.runButtonDescription = new SimpleStringProperty(resourceBundle.getString("health.check.runAllButton")); } @FXML @@ -60,24 +68,33 @@ public class CheckController implements FxController { checksListView.setItems(tasks); checksListView.setCellFactory(ignored -> new CheckListCell()); selectedTask.bind(checksListView.getSelectionModel().selectedItemProperty()); + selectedTask.addListener(this::updateRunButtonDescription); + } + + private void updateRunButtonDescription(ObservableValue observable, HealthCheckTask oldTask, HealthCheckTask newTask) { + if (newTask == null) { + runButtonDescription.set(resourceBundle.getString("health.check.runSingleButton")); + } else if (oldTask == null && newTask != null) { + runButtonDescription.set(resourceBundle.getString("health.check.runAllButton")); + } } @FXML public synchronized void runSelectedChecks() { - Preconditions.checkState(runningTask.get() == null); - var batch = new BatchService(checksListView.getSelectionModel().getSelectedItems()); - batch.setExecutor(executorService); - batch.start(); - runningTask.set(batch); + startBatch(checksListView.getSelectionModel().getSelectedItems()); } @FXML public synchronized void runAllChecks() { + startBatch(checksListView.getItems()); + } + + private void startBatch(Iterable batch) { Preconditions.checkState(runningTask.get() == null); - var batch = new BatchService(checksListView.getItems()); - batch.setExecutor(executorService); - batch.start(); - runningTask.set(batch); + var batchService = new BatchService(batch); + batchService.setExecutor(executorService); + batchService.start(); + runningTask.set(batchService); } @FXML diff --git a/main/ui/src/main/resources/fxml/health_check.fxml b/main/ui/src/main/resources/fxml/health_check.fxml index 84c7d66c4..75efd0465 100644 --- a/main/ui/src/main/resources/fxml/health_check.fxml +++ b/main/ui/src/main/resources/fxml/health_check.fxml @@ -18,20 +18,24 @@ - - + +