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

Made handelAddBtn and handleEditBtn essentially be the same method, and...

Made handelAddBtn and handleEditBtn essentially be the same method, and differentitated them with enums
parent 13810b51
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
......@@ -38,6 +38,7 @@ public class ExpensesController {
@FXML
private Button add;
@FXML
private TextField descriptionField;
@FXML
......@@ -77,40 +78,58 @@ public class ExpensesController {
categoryColumn.setCellValueFactory(new PropertyValueFactory<Expense, ExpenseCategory>("category"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<Expense, String>("description"));
recurringColumn.setCellValueFactory(new PropertyValueFactory<Expense, Boolean>("recurring"));
expenseTableView.setItems(expenses);
ObservableList<String> filter = FXCollections.observableArrayList("All", "Other", "Food");
show.setItems(filter);
}
@FXML
private void handeEditButton(ActionEvent event) {
public void handleAddButton(ActionEvent event) {
handleEditButton(event);
}
@FXML
private void handleAddButton(ActionEvent event) {
private void handleEditButton(ActionEvent event) {
Expense newExpense = null;
String dialogTitle = "";
// Load the FXML file for your dialog box
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/AddExpense.fxml"));
Dialog<Expense> dialog = new Dialog<>();
dialog.initModality(Modality.APPLICATION_MODAL);
if (event.getSource().equals(add)) {
mode = DialogMode.ADD;
dialogTitle = "Add expense";
newExpense = new Expense(1.1, false, ExpenseCategory.FOOD, "1/1/23");
} else if (event.getSource().equals(edit)) {
mode = DialogMode.EDIT;
dialogTitle = "Edit expense";
newExpense = expenseTableView.getSelectionModel().getSelectedItem();
} else {
return;
}
try {
// Set the Dialog's content to the loaded FXML file
dialog.getDialogPane().setContent(loader.load());
dialog.setTitle(dialogTitle);
} catch (IOException e) {
e.printStackTrace();
}
// Get the controller for the loaded FXML file
AddExpenseController dialogController = loader.getController();
dialogController.setExpense(newExpense);
// Get the controller for the loaded FXML file
// Show the Dialog and wait for the user to close it
dialog.showAndWait();
//Get the newwly created expense from the dialog pane
Expense newExpense = dialogController.getNewExpense();
//Get the newly created expense from the dialog pane
newExpense = dialogController.getNewExpense();
//Only add the expense to the tableview, if the expense is not null
if (newExpense != null) {
if (newExpense != null && mode == DialogMode.ADD) {
expenseTableView.getItems().add(newExpense);
} else {
System.out.println("expense is null");
......@@ -119,11 +138,6 @@ public class ExpensesController {
}
@FXML
private void handleEditButton(ActionEvent event) throws IOException {
//
}
public void handleDeleteButton(ActionEvent event) throws IOException {
}
......
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