Skip to content
Snippets Groups Projects
Commit 7edba9f2 authored by Anders Emil Bergan's avatar Anders Emil Bergan Committed by Harry Linrui XU
Browse files

functioning delete button for budget window

parent e960cd63
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
......@@ -52,9 +52,7 @@ public class AddBudgetController {
public void addBudget(ActionEvent event) {
if(newBudgetItem == null){
ExpenseCategory category = getCategory();
System.out.println(category.toString());
double amount = Double.parseDouble(amountVariable.getText());
System.out.println(amount);
String description = descriptionVariable.getText();
newBudgetItem = new BudgetItem(amount, description, category);
}
......@@ -77,12 +75,8 @@ public class AddBudgetController {
amountVariable.textProperty().set(String.valueOf(item.getBudgetAmount()));
descriptionVariable.textProperty().set(item.getBudgetDescription());
categoryVariable.setValue(item.getBudgetCategory());
}
public void closeButton(ActionEvent actionEvent) {
final Node source = (Node) actionEvent.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
......
......@@ -19,6 +19,7 @@ import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
enum DialogMode{
ADD, EDIT, DELETE
......@@ -121,6 +122,28 @@ public class BudgetController {
stage.close();
}
@FXML
public void deleteButton(ActionEvent event) {
BudgetItem item = budgetTableView.getSelectionModel().getSelectedItem();
if (item == null) {
return;
}
Optional<ButtonType> isConfirmed = showConfirmationDialog();
if (isConfirmed.isPresent() && isConfirmed.get() == ButtonType.OK) {
general.deleteItemFromBudget(item.getBudgetCategory());
refreshObservableList();
}
}
private Optional<ButtonType> showConfirmationDialog() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Confirm Delete");
alert.setHeaderText("Delete Confirmation");
alert.setContentText("Are you sure you would like to delete the selected entry?");
return alert.showAndWait();
}
protected void refreshObservableList(){
budgetTableView.setItems(budgetList);
......
......@@ -35,8 +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 Budget Item" />
<Button fx:id="editBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#switchAddBudget" prefWidth="100.0" text="Edit/Remove" />
<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 minHeight="60.0" minWidth="100.0" mnemonicParsing="false" prefWidth="100.0" text="Save/Back" />
</children>
</HBox>
......
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