From a7133dbebe775244dd95fab298bd690a426d6760 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 18 May 2021 17:12:37 +0200 Subject: [PATCH] Add icon to severity column --- .../ui/health/CheckDetailController.java | 6 ++-- .../ui/health/ResultSeverityTableCell.java | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/health/ResultSeverityTableCell.java diff --git a/main/ui/src/main/java/org/cryptomator/ui/health/CheckDetailController.java b/main/ui/src/main/java/org/cryptomator/ui/health/CheckDetailController.java index c4943d9c8..404268f8e 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/health/CheckDetailController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/health/CheckDetailController.java @@ -2,6 +2,7 @@ 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.common.FxController; import javax.inject.Inject; @@ -27,7 +28,7 @@ public class CheckDetailController implements FxController { public TableView resultsTableView; public TableColumn resultDescriptionColumn; - public TableColumn resultSeverityColumn; + public TableColumn resultSeverityColumn; public TableColumn resultActionColumn; @Inject @@ -50,7 +51,8 @@ public class CheckDetailController implements FxController { public void initialize() { resultsTableView.itemsProperty().bind(results); resultDescriptionColumn.setCellValueFactory(cellFeatures -> new SimpleStringProperty(cellFeatures.getValue().getDescription())); - resultSeverityColumn.setCellValueFactory(cellFeatures -> new SimpleStringProperty(cellFeatures.getValue().getSeverity().name())); + resultSeverityColumn.setCellValueFactory(cellFeatures -> new SimpleObjectProperty<>(cellFeatures.getValue().getSeverity())); + resultSeverityColumn.setCellFactory(column -> new ResultSeverityTableCell()); resultActionColumn.setCellValueFactory(cellFeatures -> new SimpleObjectProperty<>(cellFeatures.getValue())); resultActionColumn.setCellFactory(column -> new ResultActionTableCell()); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/health/ResultSeverityTableCell.java b/main/ui/src/main/java/org/cryptomator/ui/health/ResultSeverityTableCell.java new file mode 100644 index 000000000..34caa558d --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/health/ResultSeverityTableCell.java @@ -0,0 +1,34 @@ +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.scene.control.TableCell; + +public class ResultSeverityTableCell extends TableCell { + + private FontAwesome5IconView iconView; + + ResultSeverityTableCell() { + iconView = new FontAwesome5IconView(); + } + + @Override + protected void updateItem(DiagnosticResult.Severity item, boolean empty) { + super.updateItem(item, empty); + if (empty || item == null) { + setText(null); + setGraphic(null); + } else { + iconView.glyphProperty().set(switch (item) { + case INFO -> FontAwesome5Icon.INFO_CIRCLE; + case GOOD -> FontAwesome5Icon.CHECK; + case WARN -> FontAwesome5Icon.EXCLAMATION_TRIANGLE; + case CRITICAL -> FontAwesome5Icon.TIMES; + }); + setGraphic(iconView); + setText(item.name()); + } + } +}