瀏覽代碼

Add icon to severity column

Armin Schrenk 4 年之前
父節點
當前提交
a7133dbebe

+ 4 - 2
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<DiagnosticResultAction> resultsTableView;
 	public TableColumn<DiagnosticResultAction, String> resultDescriptionColumn;
-	public TableColumn<DiagnosticResultAction, String> resultSeverityColumn;
+	public TableColumn<DiagnosticResultAction, DiagnosticResult.Severity> resultSeverityColumn;
 	public TableColumn<DiagnosticResultAction, Runnable> 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());
 	}

+ 34 - 0
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<DiagnosticResultAction, DiagnosticResult.Severity> {
+
+	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());
+		}
+	}
+}