Browse Source

keep more ui code in fxml

Sebastian Stenzel 4 years ago
parent
commit
e134d2f422

+ 7 - 7
main/ui/src/main/java/org/cryptomator/ui/health/CheckListController.java

@@ -21,6 +21,7 @@ import javafx.beans.value.ObservableValue;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.concurrent.Worker;
+import javafx.event.ActionEvent;
 import javafx.fxml.FXML;
 import javafx.scene.control.CheckBox;
 import javafx.scene.control.ListView;
@@ -55,7 +56,6 @@ public class CheckListController implements FxController {
 	private final BooleanProperty showResultScreen;
 
 	/* FXML */
-	public CheckBox selectAllBox;
 	public ListView<HealthCheckTask> checksListView;
 
 
@@ -96,13 +96,13 @@ public class CheckListController implements FxController {
 			}
 		}));
 		selectedTask.bind(checksListView.getSelectionModel().selectedItemProperty());
-		selectAllBox.selectedProperty().addListener(this::selectOrDeselectAll);
-		selectAllBox.visibleProperty().bind(showResultScreen.not());
-		selectAllBox.managedProperty().bind(showResultScreen.not());
 	}
 
-	public void selectOrDeselectAll(ObservableValue<? extends Boolean> observable, boolean oldValue, boolean newValue) {
-		listPickIndicators.forEach( (task, pickProperty) -> pickProperty.set(newValue));
+	@FXML
+	public void toggleSelectAll(ActionEvent event) {
+		if (event.getSource() instanceof CheckBox c) {
+			listPickIndicators.forEach( (task, pickProperty) -> pickProperty.set(c.isSelected()));
+		}
 	}
 
 	@FXML
@@ -113,9 +113,9 @@ public class CheckListController implements FxController {
 		batchService.setExecutor(executorService);
 		batchService.start();
 		runningTask.set(batchService);
-		checksListView.setCellFactory(view -> new CheckListCell());
 		showResultScreen.set(true);
 		checksListView.getSelectionModel().select(batch.get(0));
+		checksListView.setCellFactory(view -> new CheckListCell());
 		window.sizeToScene();
 	}
 

+ 1 - 1
main/ui/src/main/resources/fxml/health_check_list.fxml

@@ -25,7 +25,7 @@
 		<HBox spacing="12" VBox.vgrow="ALWAYS">
 			<VBox minWidth="80" maxWidth="200" spacing="6" HBox.hgrow="ALWAYS" >
 				<Label fx:id="listHeading" text="%health.check.listHeader"/>
-				<CheckBox fx:id="selectAllBox" text="FIX: SELECT ALL" />
+				<CheckBox onAction="#toggleSelectAll" text="FIX: SELECT ALL" visible="${!controller.showResultScreen}" managed="${!controller.showResultScreen}" />
 				<ListView fx:id="checksListView" VBox.vgrow="ALWAYS"/>
 			</VBox>
 			<StackPane visible="${controller.showResultScreen}" managed="${controller.showResultScreen}" HBox.hgrow="ALWAYS" >