Skip to content
Snippets Groups Projects
Commit 892b0cf3 authored by Harry Linrui XU's avatar Harry Linrui XU
Browse files

Refactored edit method, such that expenses are not edited if cancel button is...

Refactored edit method, such that expenses are not edited if cancel button is hit. Delete button will now not do anything unless expense is selected
parent ec9afb45
No related branches found
No related tags found
10 merge requests!43Merging frontend-testing into master,!38"Made progressbar dynamic in accordance to spending. Added balance field....,!37Made the sub progress bars respond to changes in expense,!32Added input validation to add dialog boxes.,!30Redesigned scenes,!29Redesigned scenes,!28Redesigned scenes,!26Redesigned Main menu and expense/income windows,!24Merging frontend-testing with master,!23Merging frontend-testing and master
...@@ -69,22 +69,41 @@ public class AddExpenseController { ...@@ -69,22 +69,41 @@ public class AddExpenseController {
} }
public void setExpense(Expense expense) { //TODO NEED CANCEL BUTTON TO REMOVE THE CHANGES IF CANCEL IS PRESSED public void setExpense(Expense expense) { //TODO NEED CANCEL BUTTON TO REMOVE THE CHANGES IF CANCEL IS PRESSED
dateField.textProperty().bindBidirectional(new SimpleStringProperty(expense.getDate().toString())); chosenExpense = new Expense(expense.getDescription(), expense.getAmount(), expense.isRecurring(), expense.getCategory(), expense.getDate());
amountField.textProperty().bindBidirectional(expense.amountProperty(), NumberFormat.getNumberInstance()); //TODO AMOUNT IS STORED WITH COMMA, WHICH IS NOT ALLOWED chosenExpense.descriptionProperty().bindBidirectional(expense.descriptionProperty());
chosenExpense.amountProperty().bindBidirectional(expense.amountProperty());
chosenExpense.recurringProperty().bindBidirectional(expense.recurringProperty());
//chosenExpense.().bindBidirectional(expense.descriptionProperty());
//chosenExpense.().bindBidirectional(expense.descriptionProperty());
descriptionField.textProperty().set(expense.getDescription());
amountField.textProperty().setValue(String.valueOf(expense.getAmount()));
recurringBox.setValue(expense.isRecurring());
//new SimpleStringProperty(datePicker.getValue().toString()).bindBidirectional(new SimpleStringProperty(expense.getDate().toString()));
//Bind this expense's fields with the argument object's fields. If cancel is pressed - do nothing. If ok is pressed, bind the textfields with this expsense
/*amountField.textProperty().bindBidirectional(expense.amountProperty(), NumberFormat.getNumberInstance()); //TODO AMOUNT IS STORED WITH COMMA, WHICH IS NOT ALLOWED
descriptionField.textProperty().bindBidirectional(expense.descriptionProperty()); descriptionField.textProperty().bindBidirectional(expense.descriptionProperty());
//categoryBox.valueProperty().bindBidirectional(expense.getCategory()); //categoryBox.valueProperty().bindBidirectional(expense.getCategory());
recurringBox.valueProperty().bindBidirectional(expense.recurringProperty()); recurringBox.valueProperty().bindBidirectional(expense.recurringProperty());*/
} }
@FXML @FXML
public void pressOkBtn(ActionEvent event) { public void pressOkBtn(ActionEvent event) {
LocalDate date = LocalDate.parse(dateField.getText()); if (newExpense == null) {
double amount = Double.parseDouble(amountField.getText()); LocalDate date = datePicker.getValue();
String description = descriptionField.getText(); double amount = Double.parseDouble(amountField.getText());
ExpenseCategory category = getCategory(); String description = descriptionField.getText();
boolean recurring = isRecurring(); ExpenseCategory category = getCategory();
newExpense = new Expense(description, amount, recurring, category, date); boolean recurring = isRecurring();
System.out.println(date + " " + amount + " " + description + " " + category + " " + recurring); newExpense = new Expense(description, amount, recurring, category, date);
}
if (chosenExpense != null) {
chosenExpense.setDescription((descriptionField.getText()));
chosenExpense.setAmount(Double.parseDouble(amountField.getText()));
chosenExpense.setRecurring(recurringBox.getValue());
}
final Node source = (Node) event.getSource(); final Node source = (Node) event.getSource();
((Stage) source.getScene().getWindow()).close(); ((Stage) source.getScene().getWindow()).close();
......
...@@ -160,10 +160,12 @@ public class ExpensesController { ...@@ -160,10 +160,12 @@ public class ExpensesController {
@FXML @FXML
public void handleDeleteBtn(ActionEvent event) { public void handleDeleteBtn(ActionEvent event) {
Optional<ButtonType> isConfirmed = showConfirmationDialog( Expense chosenExpense = expenseTableView.getSelectionModel().getSelectedItem();
); if (chosenExpense == null) {
return;
}
Optional<ButtonType> isConfirmed = showConfirmationDialog();
if (isConfirmed.isPresent() && isConfirmed.get() == ButtonType.OK) { if (isConfirmed.isPresent() && isConfirmed.get() == ButtonType.OK) {
Expense chosenExpense = expenseTableView.getSelectionModel().getSelectedItem();
expenseRegister.removeItem(chosenExpense); expenseRegister.removeItem(chosenExpense);
refreshObservableList(); refreshObservableList();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment