Skip to content
Snippets Groups Projects

Button validation confirmation

Merged Harry Linrui Xu requested to merge button-validation-confirmation into master
7 files
+ 169
74
Compare changes
  • Side-by-side
  • Inline
Files
7
@@ -83,10 +83,12 @@ public class BudgetController extends FinanceController {
private PieChart budgetPieChart;
@FXML
private Label daysLeftLbl;
private Label disposableAmount;
BudgetRegister budgetRegister = new BudgetRegister();
@FXML
private Label amountLeft;
BudgetRegister budgetRegister;
/**
* Initializes the budget register, the observable budget list and the tableview, along with the values of the dropbox used for filtering the tableview.
@@ -115,7 +117,7 @@ public class BudgetController extends FinanceController {
.readBudgetArchive("budgets/Archive");
}
//Refresh piecharts only if the budget is old
//Refresh pie charts only if the budget is old
if (!FileHandlingBudget.isNewBudget(
"budgets/" + FileHandlingSelectedBudget.
readSelectedBudget("budgets/SelectedBudget") + "/Budget")) {
@@ -125,7 +127,24 @@ public class BudgetController extends FinanceController {
ioe.printStackTrace();
showErrorDialogBox(ioe.getMessage(), ioe.getMessage(), ioe.getMessage());
}
double maxAmount = general.getMaxAmount();
//Set calendar, disposable amount and amount left
formatDatePicker();
disposableAmount.setText(String.valueOf(maxAmount));
amountLeft.setText(String.valueOf(maxAmount));
//Prevent proceeding until all of budget has been used up
continueBtn.addEventFilter(
ActionEvent.ACTION, event -> {
if (maxAmount - general.totalSum() != 0) {
event.consume();
showErrorDialogBox("Use up budget",
"Please distribute the entire disposable amount",
"The amount must be used up before proceeding");
}
}
);
}
/**
@@ -243,6 +262,7 @@ public class BudgetController extends FinanceController {
//Updates the tableview and pie chart using the register
refreshTableView();
refreshPieChart();
refreshAmountLeft();
}
@@ -267,6 +287,7 @@ public class BudgetController extends FinanceController {
general.deleteItemFromBudget(item.getBudgetCategory());
refreshTableView();
refreshPieChart();
refreshAmountLeft();
}
}
@@ -279,6 +300,13 @@ public class BudgetController extends FinanceController {
this.budgetList.setAll(general.getBudgetItems());
}
/**
* Method for synching the amount left to the sum of budget items in the table view.
*/
private void refreshAmountLeft() {
amountLeft.setText(String.valueOf(general.getMaxAmount() - general.totalSum()));
}
/**
* Saves the changes made to the tableview by writing the information to a file.
*
@@ -304,7 +332,6 @@ public class BudgetController extends FinanceController {
} catch(IOException ioe) {
showErrorDialogBox(ioe.getMessage(), ioe.getMessage(), ioe.getMessage());
}
}
/**
@@ -324,18 +351,26 @@ public class BudgetController extends FinanceController {
} else if (event.getSource() == continueBtn) {
//Adds unused categories to the table
general.addUnusedCategories();
updateBudgetRegister(FileHandlingSelectedBudget
.readSelectedBudget("budgets/SelectedBudget"));
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
//Always saving the data when switching to main menu
saveDataToFile();
} else if (event.getSource() == backBtn) {
loader.setLocation(getClass().getResource("/view/dualList.fxml"));
Optional<ButtonType> isConfirmed = showConfirmationDialog("Return confirmation"
, "Are you sure you want to go back?","The changes made in this and the previous"
+ " window will be reset");
if (isConfirmed.isPresent() && isConfirmed.get() == ButtonType.OK) {
loader.setLocation(getClass().getResource("/view/dualList.fxml"));
} else return;
}
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setResizable(false);
//Centralize the new screen
Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
@@ -343,7 +378,6 @@ public class BudgetController extends FinanceController {
stage.setY((primScreenBounds.getHeight() - stage.getHeight()) / 2);
stage.show();
} catch(Exception ioe) {
ioe.printStackTrace();
showErrorDialogBox("Loading error", "Error in loading", "Could not load"
Loading