From 8539ddec70fd1fb89ab2e2c73ca94e9dee217b86 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Thu, 4 Jan 2024 12:58:51 -0500 Subject: [PATCH] More tweaking of PropertiesPane. --- .../perfin/control/AccountViewController.java | 26 ++++++++------ .../perfin/view/component/PropertiesPane.java | 36 +++++++++++++------ src/main/resources/account-view.fxml | 3 -- src/main/resources/transaction-view.fxml | 19 +++++----- 4 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/andrewlalis/perfin/control/AccountViewController.java b/src/main/java/com/andrewlalis/perfin/control/AccountViewController.java index bfe1ec7..b41dc4a 100644 --- a/src/main/java/com/andrewlalis/perfin/control/AccountViewController.java +++ b/src/main/java/com/andrewlalis/perfin/control/AccountViewController.java @@ -12,9 +12,7 @@ import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.fxml.FXML; import javafx.scene.Node; -import javafx.scene.control.Alert; import javafx.scene.control.Button; -import javafx.scene.control.ButtonType; import javafx.scene.control.Label; import javafx.scene.layout.VBox; @@ -87,15 +85,14 @@ public class AccountViewController implements RouteSelectionListener { @FXML public void archiveAccount() { - var confirmResult = new Alert( - Alert.AlertType.CONFIRMATION, + boolean confirmResult = Popups.confirm( "Are you sure you want to archive this account? It will no " + "longer show up in the app normally, and you won't be " + "able to add new transactions to it. You'll still be " + "able to view the account, and you can un-archive it " + "later if you need to." - ).showAndWait(); - if (confirmResult.isPresent() && confirmResult.get() == ButtonType.OK) { + ); + if (confirmResult) { Profile.getCurrent().getDataSource().useAccountRepository(repo -> repo.archive(account.id)); router.getHistory().clear(); router.navigate("accounts"); @@ -103,20 +100,27 @@ public class AccountViewController implements RouteSelectionListener { } @FXML public void unarchiveAccount() { - System.out.println("Unarchiving"); + boolean confirm = Popups.confirm( + "Are you sure you want to restore this account from its archived " + + "status?" + ); + if (confirm) { + Profile.getCurrent().getDataSource().useAccountRepository(repo -> repo.unarchive(account.id)); + router.getHistory().clear(); + router.navigate("accounts"); + } } @FXML public void deleteAccount() { - var confirmResult = new Alert( - Alert.AlertType.CONFIRMATION, + boolean confirm = Popups.confirm( "Are you sure you want to permanently delete this account and " + "all data directly associated with it? This cannot be " + "undone; deleted accounts are not recoverable at all. " + "Consider archiving this account instead if you just " + "want to hide it." - ).showAndWait(); - if (confirmResult.isPresent() && confirmResult.get() == ButtonType.OK) { + ); + if (confirm) { Profile.getCurrent().getDataSource().useAccountRepository(repo -> repo.delete(account)); router.getHistory().clear(); router.navigate("accounts"); diff --git a/src/main/java/com/andrewlalis/perfin/view/component/PropertiesPane.java b/src/main/java/com/andrewlalis/perfin/view/component/PropertiesPane.java index eb5745c..a8e9c69 100644 --- a/src/main/java/com/andrewlalis/perfin/view/component/PropertiesPane.java +++ b/src/main/java/com/andrewlalis/perfin/view/component/PropertiesPane.java @@ -13,19 +13,21 @@ import java.util.List; /** * A specially-formatted {@link GridPane} that arranges its children into a - * two-column grid representing key-value pairs. + * two-column grid representing key-value pairs. It will use a default set of + * {@link ColumnConstraints} unless they are already defined by the user. */ public class PropertiesPane extends GridPane { + private final ColumnConstraints defaultKeyColumnConstraints; + private final ColumnConstraints defaultValueColumnConstraints; + private boolean columnConstraintsSet = false; + public PropertiesPane() { - ColumnConstraints keyConstraints = new ColumnConstraints(); - keyConstraints.setHgrow(Priority.NEVER); - keyConstraints.setHalignment(HPos.LEFT); - keyConstraints.setMinWidth(10.0); - ColumnConstraints valueConstraints = new ColumnConstraints(); - valueConstraints.setHgrow(Priority.ALWAYS); - valueConstraints.setHalignment(HPos.LEFT); - valueConstraints.setMinWidth(10.0); - getColumnConstraints().setAll(keyConstraints, valueConstraints); + defaultKeyColumnConstraints = new ColumnConstraints(); + defaultKeyColumnConstraints.setHgrow(Priority.NEVER); + defaultKeyColumnConstraints.setHalignment(HPos.LEFT); + defaultValueColumnConstraints = new ColumnConstraints(); + defaultValueColumnConstraints.setHgrow(Priority.ALWAYS); + defaultValueColumnConstraints.setHalignment(HPos.LEFT); } @Override @@ -34,6 +36,17 @@ public class PropertiesPane extends GridPane { // key 1 value 1 // key 2 value 2 // ... and so on. + + // Set column restraints if they weren't set already. + if (!columnConstraintsSet) { + if (getColumnConstraints().isEmpty()) { + // No preexisting constraints, so we set our defaults. + getColumnConstraints().setAll(defaultKeyColumnConstraints, defaultValueColumnConstraints); + } + columnConstraintsSet = true; + } + + // Set row constraints for each row. int rowCount = getManagedChildren().size() / 2; List rows = new ArrayList<>(rowCount); for (int i = 0; i < rowCount; i++) { @@ -43,6 +56,8 @@ public class PropertiesPane extends GridPane { rows.add(c); } getRowConstraints().setAll(rows); + + // Set child row and column indices. for (int i = 0; i < getManagedChildren().size(); i++) { Node child = getManagedChildren().get(i); int column = i % 2; @@ -50,6 +65,7 @@ public class PropertiesPane extends GridPane { GridPane.setRowIndex(child, row); GridPane.setColumnIndex(child, column); } + super.layoutChildren(); } } diff --git a/src/main/resources/account-view.fxml b/src/main/resources/account-view.fxml index d4316e9..3e188bf 100644 --- a/src/main/resources/account-view.fxml +++ b/src/main/resources/account-view.fxml @@ -43,9 +43,6 @@