diff --git a/src/main/java/org/cryptomator/ui/health/CheckListCell.java b/src/main/java/org/cryptomator/ui/health/CheckListCell.java index ac87b56ca..76a8f3c27 100644 --- a/src/main/java/org/cryptomator/ui/health/CheckListCell.java +++ b/src/main/java/org/cryptomator/ui/health/CheckListCell.java @@ -1,13 +1,10 @@ package org.cryptomator.ui.health; +import org.cryptomator.cryptofs.health.api.DiagnosticResult; import org.cryptomator.ui.controls.FontAwesome5Icon; import org.cryptomator.ui.controls.FontAwesome5IconView; import javafx.beans.binding.Bindings; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.value.ObservableValue; import javafx.concurrent.Worker; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -15,7 +12,7 @@ import javafx.scene.Node; import javafx.scene.control.CheckBox; import javafx.scene.control.ContentDisplay; import javafx.scene.control.ListCell; -import javafx.util.Callback; +import java.util.function.Predicate; class CheckListCell extends ListCell { @@ -34,9 +31,8 @@ class CheckListCell extends ListCell { super.updateItem(item, empty); if (item != null) { setText(item.getTitle()); - item.stateProperty().addListener(this::stateChanged); graphicProperty().bind(Bindings.createObjectBinding(() -> graphicForState(item.getState()), item.stateProperty())); - stateIcon.setGlyph(glyphForState(item.getState())); + stateIcon.glyphProperty().bind(Bindings.createObjectBinding(() -> glyphForState(item), item.stateProperty())); checkBox.selectedProperty().bindBidirectional(item.chosenForExecutionProperty()); } else { graphicProperty().unbind(); @@ -46,11 +42,6 @@ class CheckListCell extends ListCell { } } - private void stateChanged(ObservableValue observable, Worker.State oldState, Worker.State newState) { - stateIcon.setGlyph(glyphForState(newState)); - stateIcon.setVisible(true); - } - private Node graphicForState(Worker.State state) { return switch (state) { case READY -> checkBox; @@ -58,15 +49,23 @@ class CheckListCell extends ListCell { }; } - private FontAwesome5Icon glyphForState(Worker.State state) { - return switch (state) { + private FontAwesome5Icon glyphForState(HealthCheckTask item) { + return switch (item.getState()) { case READY -> FontAwesome5Icon.COG; //just a placeholder case SCHEDULED -> FontAwesome5Icon.CLOCK; case RUNNING -> FontAwesome5Icon.SPINNER; case FAILED -> FontAwesome5Icon.EXCLAMATION_TRIANGLE; case CANCELLED -> FontAwesome5Icon.BAN; - case SUCCEEDED -> FontAwesome5Icon.CHECK; + case SUCCEEDED -> checkFoundProblems(item) ? FontAwesome5Icon.EXCLAMATION_TRIANGLE : FontAwesome5Icon.CHECK; }; } + private boolean checkFoundProblems(HealthCheckTask item) { + Predicate isProblem = severity -> switch (severity) { + case WARN, CRITICAL -> true; + case INFO, GOOD -> false; + }; + return item.results().stream().map(Result::diagnosis).map(DiagnosticResult::getSeverity).anyMatch(isProblem); + } + } diff --git a/src/main/resources/fxml/health_check_list.fxml b/src/main/resources/fxml/health_check_list.fxml index e5fa3dde9..30bf818d5 100644 --- a/src/main/resources/fxml/health_check_list.fxml +++ b/src/main/resources/fxml/health_check_list.fxml @@ -13,7 +13,8 @@