From c0d552da92ac32d5238d98143df540b0ca71ef07 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Mon, 12 Jul 2021 10:34:36 +0200 Subject: [PATCH] Add CheckState icon to check detail view --- .../ui/health/CheckDetailController.java | 11 ++++ .../cryptomator/ui/health/CheckListCell.java | 33 +---------- .../ui/health/CheckStateIconView.java | 55 +++++++++++++++++++ .../resources/fxml/health_check_details.fxml | 9 ++- 4 files changed, 76 insertions(+), 32 deletions(-) create mode 100644 src/main/java/org/cryptomator/ui/health/CheckStateIconView.java diff --git a/src/main/java/org/cryptomator/ui/health/CheckDetailController.java b/src/main/java/org/cryptomator/ui/health/CheckDetailController.java index 666ff2ce3..6e7e50200 100644 --- a/src/main/java/org/cryptomator/ui/health/CheckDetailController.java +++ b/src/main/java/org/cryptomator/ui/health/CheckDetailController.java @@ -3,6 +3,7 @@ package org.cryptomator.ui.health; import com.tobiasdiez.easybind.EasyBind; import com.tobiasdiez.easybind.EasyObservableList; import com.tobiasdiez.easybind.Subscription; +import com.tobiasdiez.easybind.optional.ObservableOptionalValue; import com.tobiasdiez.easybind.optional.OptionalBinding; import org.cryptomator.cryptofs.health.api.DiagnosticResult; import org.cryptomator.ui.common.FxController; @@ -21,6 +22,7 @@ import java.util.stream.Stream; public class CheckDetailController implements FxController { private final EasyObservableList results; + private final ObjectProperty check; private final OptionalBinding checkState; private final Binding checkName; private final Binding checkRunning; @@ -34,6 +36,7 @@ public class CheckDetailController implements FxController { private final Binding countOfCritSeverity; private final ResultListCellFactory resultListCellFactory; + public CheckStateIconView checkStateIconView; public ListView resultsListView; private Subscription resultSubscription; @@ -41,6 +44,7 @@ public class CheckDetailController implements FxController { public CheckDetailController(ObjectProperty selectedTask, ResultListCellFactory resultListCellFactory) { this.resultListCellFactory = resultListCellFactory; this.results = EasyBind.wrapList(FXCollections.observableArrayList()); + this.check = selectedTask; this.checkState = EasyBind.wrapNullable(selectedTask).mapObservable(Check::stateProperty); this.checkName = EasyBind.wrapNullable(selectedTask).map(Check::getLocalizedName).orElse(""); this.checkRunning = checkState.map(Check.CheckState.RUNNING::equals).orElse(false); @@ -156,4 +160,11 @@ public class CheckDetailController implements FxController { return checkCancelled; } + public ObjectProperty checkProperty() { + return check; + } + + public Check getCheck() { + return check.get(); + } } diff --git a/src/main/java/org/cryptomator/ui/health/CheckListCell.java b/src/main/java/org/cryptomator/ui/health/CheckListCell.java index ef8a0a686..a1c05efb8 100644 --- a/src/main/java/org/cryptomator/ui/health/CheckListCell.java +++ b/src/main/java/org/cryptomator/ui/health/CheckListCell.java @@ -1,10 +1,5 @@ package org.cryptomator.ui.health; -import com.tobiasdiez.easybind.EasyBind; -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.geometry.Insets; import javafx.geometry.Pos; @@ -15,7 +10,7 @@ import javafx.scene.layout.StackPane; class CheckListCell extends ListCell { - private final FontAwesome5IconView stateIcon = new FontAwesome5IconView(); + private final CheckStateIconView stateIcon = new CheckStateIconView(); private CheckBox checkBox = new CheckBox(); private final StackPane graphicContainer = new StackPane(stateIcon, checkBox); @@ -27,11 +22,6 @@ class CheckListCell extends ListCell { graphicContainer.minWidth(20); graphicContainer.maxWidth(20); graphicContainer.setAlignment(Pos.CENTER); - - EasyBind.includeWhen(stateIcon.getStyleClass(), "glyph-icon-muted", stateIcon.glyphProperty().isEqualTo(FontAwesome5Icon.INFO_CIRCLE)); - EasyBind.includeWhen(stateIcon.getStyleClass(), "glyph-icon-primary", stateIcon.glyphProperty().isEqualTo(FontAwesome5Icon.CHECK)); - EasyBind.includeWhen(stateIcon.getStyleClass(), "glyph-icon-orange", stateIcon.glyphProperty().isEqualTo(FontAwesome5Icon.EXCLAMATION_TRIANGLE)); - EasyBind.includeWhen(stateIcon.getStyleClass(), "glyph-icon-red", stateIcon.glyphProperty().isEqualTo(FontAwesome5Icon.TIMES)); } @Override @@ -40,36 +30,19 @@ class CheckListCell extends ListCell { if (item != null) { setText(item.getLocalizedName()); setGraphic(graphicContainer); + stateIcon.setCheck(item); checkBox.visibleProperty().bind(Bindings.createBooleanBinding(() -> item.getState() == Check.CheckState.RUNNABLE, item.stateProperty())); stateIcon.visibleProperty().bind(Bindings.createBooleanBinding(() -> item.getState() != Check.CheckState.RUNNABLE, item.stateProperty())); - stateIcon.glyphProperty().bind(Bindings.createObjectBinding(() -> glyphForState(item), item.stateProperty(), item.highestResultSeverityProperty())); checkBox.selectedProperty().bindBidirectional(item.chosenForExecutionProperty()); } else { graphicProperty(); checkBox.visibleProperty().unbind(); stateIcon.visibleProperty().unbind(); + stateIcon.setCheck(null); setGraphic(null); setText(null); checkBox.selectedProperty().unbind(); } } - private FontAwesome5Icon glyphForState(Check item) { - return switch (item.getState()) { - case RUNNABLE -> null; - case SKIPPED -> FontAwesome5Icon.FAST_FORWARD; - case SCHEDULED -> FontAwesome5Icon.CLOCK; - case RUNNING -> FontAwesome5Icon.SPINNER; - case ERROR -> FontAwesome5Icon.TIMES; - case CANCELLED -> FontAwesome5Icon.BAN; - case SUCCEEDED -> { - if (item.getHighestResultSeverity() == DiagnosticResult.Severity.INFO || item.getHighestResultSeverity() == DiagnosticResult.Severity.GOOD) { - yield FontAwesome5Icon.CHECK; - } else { - yield FontAwesome5Icon.EXCLAMATION_TRIANGLE; - } - } - }; - } - } diff --git a/src/main/java/org/cryptomator/ui/health/CheckStateIconView.java b/src/main/java/org/cryptomator/ui/health/CheckStateIconView.java new file mode 100644 index 000000000..cd4408fb5 --- /dev/null +++ b/src/main/java/org/cryptomator/ui/health/CheckStateIconView.java @@ -0,0 +1,55 @@ +package org.cryptomator.ui.health; + +import com.tobiasdiez.easybind.EasyBind; +import com.tobiasdiez.easybind.optional.OptionalBinding; +import org.cryptomator.cryptofs.health.api.DiagnosticResult; +import org.cryptomator.ui.controls.FontAwesome5Icon; +import org.cryptomator.ui.controls.FontAwesome5IconView; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import java.util.Optional; + +public class CheckStateIconView extends FontAwesome5IconView { + + private final ObjectProperty check = new SimpleObjectProperty<>(); + private final OptionalBinding state; + private final OptionalBinding severity; + + public CheckStateIconView() { + super(); + this.getStyleClass().remove("glyph-icon"); + this.state = EasyBind.wrapNullable(check).mapObservable(Check::stateProperty); + this.severity = EasyBind.wrapNullable(check).mapObservable(Check::highestResultSeverityProperty); + glyphProperty().bind(EasyBind.combine(state, severity, this::glyphForState)); + EasyBind.includeWhen(getStyleClass(), "glyph-icon-muted", glyphProperty().isEqualTo(FontAwesome5Icon.INFO_CIRCLE)); + EasyBind.includeWhen(getStyleClass(), "glyph-icon-primary", glyphProperty().isEqualTo(FontAwesome5Icon.CHECK)); + EasyBind.includeWhen(getStyleClass(), "glyph-icon-orange", glyphProperty().isEqualTo(FontAwesome5Icon.EXCLAMATION_TRIANGLE)); + EasyBind.includeWhen(getStyleClass(), "glyph-icon-red", glyphProperty().isEqualTo(FontAwesome5Icon.TIMES)); + } + + private FontAwesome5Icon glyphForState(Optional state, Optional severity) { + return state.map(s -> switch (s) { + case RUNNABLE -> null; + case SKIPPED -> FontAwesome5Icon.FAST_FORWARD; + case SCHEDULED -> FontAwesome5Icon.CLOCK; + case RUNNING -> FontAwesome5Icon.SPINNER; + case ERROR -> FontAwesome5Icon.TIMES; + case CANCELLED -> FontAwesome5Icon.BAN; + case SUCCEEDED -> severity.map(se -> DiagnosticResult.Severity.GOOD.compareTo(se) >= 0 ? FontAwesome5Icon.CHECK : FontAwesome5Icon.EXCLAMATION_TRIANGLE).orElse(null); + }).orElse(null); + } + + public ObjectProperty checkProperty() { + return check; + } + + public void setCheck(Check c) { + check.set(c); + } + + public Check getCheck() { + return check.get(); + } + +} diff --git a/src/main/resources/fxml/health_check_details.fxml b/src/main/resources/fxml/health_check_details.fxml index 0692c746b..9fa451e97 100644 --- a/src/main/resources/fxml/health_check_details.fxml +++ b/src/main/resources/fxml/health_check_details.fxml @@ -4,12 +4,17 @@ + - + + + + + \ No newline at end of file