diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java index b366b962ec94f51210f0f973fb4c4987d3afbe9e..da50a50b39b3f886043c229cb409a2187c34d679 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java @@ -75,8 +75,7 @@ public class BudgetController { /** - * Initializes the budget register, the observable budget list and the tableview, along with all dynamic fields that relates to the tableview. - * The method is called each time the FXML of this scene is loaded. + * Initializes the budget register, the observable budget list and the tableview, along with the values of the dropbox used for filtering the tableview. * @throws IOException If there occurs any exception when loading the budget register from a file. */ @FXML @@ -95,13 +94,17 @@ public class BudgetController { sum.setText(String.valueOf(general.totalSum())); } + @FXML + protected void handleAddButton(ActionEvent event) { + handleEditButton(event); + } /** * Adds or edits a budget item, depending on what mode the DialogMode enum is at. The method brings up a dialog box popup in which the user can fill and choose * values that the budget item will have. Open exiting the popup, the changes the saved to the tableview. * @param event A button click on either the add or delete button. */ @FXML - public void switchAddBudget(ActionEvent event) { + public void handleEditButton(ActionEvent event) { BudgetItem item = null; String dialogTitle = ""; DialogMode dialogMode; @@ -124,7 +127,6 @@ public class BudgetController { if(event.getSource().equals(addBudget)){ dialogMode = DialogMode.ADD; dialogTitle = "New Budget"; - } else if (event.getSource().equals(editBudget) && budgetTableView.getSelectionModel().getSelectedItem() != null) { dialogMode = DialogMode.EDIT; @@ -138,6 +140,7 @@ public class BudgetController { } dialog.setTitle(dialogTitle); + // Show the Dialog and wait for the user to close it dialog.showAndWait(); //Adds the new item to the register @@ -153,23 +156,13 @@ public class BudgetController { refreshTableView(); } - /** - * Closes the popup window. - * @param event A button click on the close button - */ - @FXML - public void closeButton(ActionEvent event) { - final Node source = (Node) event.getSource(); - final Stage stage = (Stage) source.getScene().getWindow(); - stage.close(); - } /** * Deletes an entry from the tableview, if an entry has been selected. The method brings up a popup window, asking for confirmation for deleting the entry. * @param event A button click on the delete button */ @FXML - public void deleteButton(ActionEvent event) { + public void handleDeleteBtn(ActionEvent event) { //Gets the selected item from the tableview BudgetItem item = budgetTableView.getSelectionModel().getSelectedItem(); //Exits the method if nothing is selected @@ -184,9 +177,19 @@ public class BudgetController { } } + /** + * Method for synching the register with the tableview. The observable list to which the tableview is set, is being refilled with all the entries + * in the register, keeping it updated with new changes. + */ + protected void refreshTableView(){ + this.budgetList.setAll(general.getBudgetItems()); + //Refreshing the sum of the amounts of the budget + this.sum.setText(String.valueOf(general.totalSum())); + } + /** * Returns an optional, which is a popup alert box, asking for confirmation for deleting an entry. - * @return An alertbox, asking for confirmation for deleting the selected entry of the tableview. + * @return An alert box, asking for confirmation for deleting the selected entry of the tableview. */ private Optional<ButtonType> showConfirmationDialog() { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); @@ -240,17 +243,6 @@ public class BudgetController { fileHandlingBudget.writeGeneralBudgetToFile(fileName, general); } - - /** - * Method for synching the register with the tableview. The observable list to which the tableview is set, is being refilled with all the entries - * in the register, keeping it updated with new changes. - */ - protected void refreshTableView(){ - this.budgetList.setAll(general.getBudgetItems()); - //Refreshing the sum of the amounts of the budget - this.sum.setText(String.valueOf(general.totalSum())); - } - /** * Switches scenes from the budget scene to another, by loading a new FXML file and setting the scene to this location. * The destination depends entirely on which button is pressed. diff --git a/src/main/resources/view/Budget.fxml b/src/main/resources/view/Budget.fxml index 461014f8b2813ee9470742d01fcaef55932fa6b0..9b1f0cf23ba191c8a0b4dc9d0f92d13a64b50b07 100644 --- a/src/main/resources/view/Budget.fxml +++ b/src/main/resources/view/Budget.fxml @@ -35,9 +35,9 @@ <children> <HBox alignment="TOP_CENTER" prefHeight="98.0" prefWidth="600.0" spacing="40.0" GridPane.rowIndex="3"> <children> - <Button fx:id="addBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#switchAddBudget" prefWidth="100.0" text="Add" /> - <Button fx:id="editBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#switchAddBudget" prefWidth="100.0" text="Edit" /> - <Button fx:id="deleteBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#deleteButton" prefWidth="100.0" text="Delete" /> + <Button fx:id="addBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#handleEditButton" prefWidth="100.0" text="Add" /> + <Button fx:id="editBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#handleEditButton" prefWidth="100.0" text="Edit" /> + <Button fx:id="deleteBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#handleDeleteBtn" prefWidth="100.0" text="Delete" /> <Button minHeight="60.0" minWidth="100.0" mnemonicParsing="false" prefWidth="100.0" text="Save/Back" /> </children> </HBox> diff --git a/src/main/resources/view/BudgetNew.fxml b/src/main/resources/view/BudgetNew.fxml index 9cda09ce93bc33a044ecfe2a71fc3ff5e4e7edbd..c92fd969abd3faa625d300dd7bc2104fedb61cad 100644 --- a/src/main/resources/view/BudgetNew.fxml +++ b/src/main/resources/view/BudgetNew.fxml @@ -76,7 +76,7 @@ <children> <HBox alignment="BOTTOM_LEFT" prefWidth="410.0" spacing="5.0"> <children> - <Button fx:id="addBudget" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#switchAddBudget" text="Add" textAlignment="CENTER"> + <Button fx:id="addBudget" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleAddButton" text="Add" textAlignment="CENTER"> <graphic> <ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true"> <image> @@ -85,7 +85,7 @@ </ImageView> </graphic> </Button> - <Button fx:id="editBudget" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#switchAddBudget" text="Edit" textAlignment="CENTER"> + <Button fx:id="editBudget" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleEditButton" text="Edit" textAlignment="CENTER"> <graphic> <ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true"> <image> @@ -94,7 +94,7 @@ </ImageView> </graphic> </Button> - <Button fx:id="deleteBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#deleteButton" text="Delete" textAlignment="CENTER"> + <Button fx:id="deleteBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete" textAlignment="CENTER"> <graphic> <ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true"> <image>