More tweaking of PropertiesPane.

This commit is contained in:
Andrew Lalis 2024-01-04 12:58:51 -05:00
parent 4c69cd1662
commit 8539ddec70
4 changed files with 51 additions and 33 deletions

View File

@ -12,9 +12,7 @@ import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
@ -87,15 +85,14 @@ public class AccountViewController implements RouteSelectionListener {
@FXML @FXML
public void archiveAccount() { public void archiveAccount() {
var confirmResult = new Alert( boolean confirmResult = Popups.confirm(
Alert.AlertType.CONFIRMATION,
"Are you sure you want to archive this account? It will no " + "Are you sure you want to archive this account? It will no " +
"longer show up in the app normally, and you won't be " + "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 add new transactions to it. You'll still be " +
"able to view the account, and you can un-archive it " + "able to view the account, and you can un-archive it " +
"later if you need to." "later if you need to."
).showAndWait(); );
if (confirmResult.isPresent() && confirmResult.get() == ButtonType.OK) { if (confirmResult) {
Profile.getCurrent().getDataSource().useAccountRepository(repo -> repo.archive(account.id)); Profile.getCurrent().getDataSource().useAccountRepository(repo -> repo.archive(account.id));
router.getHistory().clear(); router.getHistory().clear();
router.navigate("accounts"); router.navigate("accounts");
@ -103,20 +100,27 @@ public class AccountViewController implements RouteSelectionListener {
} }
@FXML public void unarchiveAccount() { @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 @FXML
public void deleteAccount() { public void deleteAccount() {
var confirmResult = new Alert( boolean confirm = Popups.confirm(
Alert.AlertType.CONFIRMATION,
"Are you sure you want to permanently delete this account and " + "Are you sure you want to permanently delete this account and " +
"all data directly associated with it? This cannot be " + "all data directly associated with it? This cannot be " +
"undone; deleted accounts are not recoverable at all. " + "undone; deleted accounts are not recoverable at all. " +
"Consider archiving this account instead if you just " + "Consider archiving this account instead if you just " +
"want to hide it." "want to hide it."
).showAndWait(); );
if (confirmResult.isPresent() && confirmResult.get() == ButtonType.OK) { if (confirm) {
Profile.getCurrent().getDataSource().useAccountRepository(repo -> repo.delete(account)); Profile.getCurrent().getDataSource().useAccountRepository(repo -> repo.delete(account));
router.getHistory().clear(); router.getHistory().clear();
router.navigate("accounts"); router.navigate("accounts");

View File

@ -13,19 +13,21 @@ import java.util.List;
/** /**
* A specially-formatted {@link GridPane} that arranges its children into a * 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 { public class PropertiesPane extends GridPane {
private final ColumnConstraints defaultKeyColumnConstraints;
private final ColumnConstraints defaultValueColumnConstraints;
private boolean columnConstraintsSet = false;
public PropertiesPane() { public PropertiesPane() {
ColumnConstraints keyConstraints = new ColumnConstraints(); defaultKeyColumnConstraints = new ColumnConstraints();
keyConstraints.setHgrow(Priority.NEVER); defaultKeyColumnConstraints.setHgrow(Priority.NEVER);
keyConstraints.setHalignment(HPos.LEFT); defaultKeyColumnConstraints.setHalignment(HPos.LEFT);
keyConstraints.setMinWidth(10.0); defaultValueColumnConstraints = new ColumnConstraints();
ColumnConstraints valueConstraints = new ColumnConstraints(); defaultValueColumnConstraints.setHgrow(Priority.ALWAYS);
valueConstraints.setHgrow(Priority.ALWAYS); defaultValueColumnConstraints.setHalignment(HPos.LEFT);
valueConstraints.setHalignment(HPos.LEFT);
valueConstraints.setMinWidth(10.0);
getColumnConstraints().setAll(keyConstraints, valueConstraints);
} }
@Override @Override
@ -34,6 +36,17 @@ public class PropertiesPane extends GridPane {
// key 1 value 1 // key 1 value 1
// key 2 value 2 // key 2 value 2
// ... and so on. // ... 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; int rowCount = getManagedChildren().size() / 2;
List<RowConstraints> rows = new ArrayList<>(rowCount); List<RowConstraints> rows = new ArrayList<>(rowCount);
for (int i = 0; i < rowCount; i++) { for (int i = 0; i < rowCount; i++) {
@ -43,6 +56,8 @@ public class PropertiesPane extends GridPane {
rows.add(c); rows.add(c);
} }
getRowConstraints().setAll(rows); getRowConstraints().setAll(rows);
// Set child row and column indices.
for (int i = 0; i < getManagedChildren().size(); i++) { for (int i = 0; i < getManagedChildren().size(); i++) {
Node child = getManagedChildren().get(i); Node child = getManagedChildren().get(i);
int column = i % 2; int column = i % 2;
@ -50,6 +65,7 @@ public class PropertiesPane extends GridPane {
GridPane.setRowIndex(child, row); GridPane.setRowIndex(child, row);
GridPane.setColumnIndex(child, column); GridPane.setColumnIndex(child, column);
} }
super.layoutChildren(); super.layoutChildren();
} }
} }

View File

@ -43,9 +43,6 @@
</VBox> </VBox>
<Label fx:id="accountBalanceLabel" styleClass="mono-font"/> <Label fx:id="accountBalanceLabel" styleClass="mono-font"/>
</PropertiesPane> </PropertiesPane>
<VBox HBox.hgrow="SOMETIMES">
<Label text="Panel 2"/>
</VBox>
</FlowPane> </FlowPane>
</VBox> </VBox>
</center> </center>

View File

@ -4,6 +4,7 @@
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<?import javafx.scene.text.TextFlow?> <?import javafx.scene.text.TextFlow?>
<?import com.andrewlalis.perfin.view.component.PropertiesPane?>
<BorderPane xmlns="http://javafx.com/javafx" <BorderPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml" xmlns:fx="http://javafx.com/fxml"
fx:controller="com.andrewlalis.perfin.control.TransactionViewController" fx:controller="com.andrewlalis.perfin.control.TransactionViewController"
@ -16,19 +17,20 @@
<center> <center>
<ScrollPane fitToHeight="true" fitToWidth="true"> <ScrollPane fitToHeight="true" fitToWidth="true">
<VBox styleClass="std-padding,std-spacing"> <VBox styleClass="std-padding,std-spacing">
<VBox> <PropertiesPane vgap="5" hgap="5">
<Label text="Amount" styleClass="bold-text"/> <columnConstraints>
<ColumnConstraints minWidth="100" halignment="LEFT" hgrow="NEVER"/>
<ColumnConstraints hgrow="ALWAYS" halignment="LEFT"/>
</columnConstraints>
<Label text="Amount" styleClass="bold-text" style="-fx-min-width: 100px;"/>
<Label fx:id="amountLabel" styleClass="mono-font"/> <Label fx:id="amountLabel" styleClass="mono-font"/>
</VBox>
<VBox>
<Label text="Timestamp" styleClass="bold-text"/> <Label text="Timestamp" styleClass="bold-text"/>
<Label fx:id="timestampLabel" styleClass="mono-font"/> <Label fx:id="timestampLabel" styleClass="mono-font"/>
</VBox>
<VBox>
<Label text="Description" styleClass="bold-text"/> <Label text="Description" styleClass="bold-text"/>
<Label fx:id="descriptionLabel" wrapText="true" style="-fx-min-height: 100px;" alignment="TOP_LEFT"/> <Label fx:id="descriptionLabel" wrapText="true" style="-fx-min-height: 100px;" alignment="TOP_LEFT"/>
</VBox> </PropertiesPane>
<Separator/>
<VBox> <VBox>
<TextFlow> <TextFlow>
<Text text="Debited to"/> <Text text="Debited to"/>
@ -39,7 +41,6 @@
<Hyperlink fx:id="creditAccountLink"/> <Hyperlink fx:id="creditAccountLink"/>
</TextFlow> </TextFlow>
</VBox> </VBox>
<Separator/>
<VBox fx:id="attachmentsContainer"> <VBox fx:id="attachmentsContainer">
<Label text="Attachments" styleClass="bold-text"/> <Label text="Attachments" styleClass="bold-text"/>
<ScrollPane fitToWidth="true" fitToHeight="true"> <ScrollPane fitToWidth="true" fitToHeight="true">