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

working edit and add function to budget

parent 2cbc8a7b
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
......@@ -58,8 +58,34 @@ public class AddBudgetController {
String description = descriptionVariable.getText();
newBudgetItem = new BudgetItem(amount, description, category);
}
if(chosenBudgetItem != null){
chosenBudgetItem.setBudgetAmount(Double.parseDouble(amountVariable.getText()));
chosenBudgetItem.setBudgetDescription(descriptionVariable.getText());
chosenBudgetItem.setBudgetCategory(categoryVariable.getValue());
}
final Node source = (Node) event.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
@FXML
public void setBudget(BudgetItem item){
chosenBudgetItem = new BudgetItem(item.getBudgetAmount(), item.getBudgetDescription(), item.getBudgetCategory());
chosenBudgetItem.getAmountProperty().bindBidirectional(item.getAmountProperty());
chosenBudgetItem.getDescriptionProperty().bindBidirectional(item.getDescriptionProperty());
chosenBudgetItem.getCategoryProperty().bindBidirectional(item.getCategoryProperty());
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();
stage.close();
}
}
......@@ -2,6 +2,7 @@ package no.ntnu.idatt1002.demo.controller;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
......@@ -11,6 +12,7 @@ import javafx.stage.Modality;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Budget.BudgetItem;
import no.ntnu.idatt1002.demo.data.Budget.GeneralBudget;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
......@@ -32,6 +34,9 @@ public class BudgetController {
@FXML
private Button addBudget;
@FXML
private Button editBudget;
@FXML
private TableColumn<BudgetItem, Double> amountColumn;
......@@ -65,9 +70,9 @@ public class BudgetController {
budgetList = FXCollections.observableArrayList(listOfBudgetItems);
budgetTableView.setItems(budgetList);
categoryColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, ExpenseCategory>("category"));
categoryColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, ExpenseCategory>("budgetCategory"));
amountColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, Double>("budgetAmount"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, String>("description"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, String>("budgetDescription"));
}
@FXML
public void switchAddBudget(javafx.event.ActionEvent event) throws IOException {
......@@ -90,6 +95,14 @@ public class BudgetController {
dialogTitle = "New Budget";
}
else if (event.getSource().equals(editBudget)) {
dialogMode = DialogMode.EDIT;
dialogTitle = "Edit expense";
item = budgetTableView.getSelectionModel().getSelectedItem();
budgetController.setBudget(item);
} else {
return;
}
dialog.setTitle(dialogTitle);
dialog.showAndWait();
......@@ -97,8 +110,8 @@ public class BudgetController {
item = budgetController.getNewBudgetItem();
if(item != null && dialogMode == DialogMode.ADD){
listOfBudgetItems.add(item);
refreshObservableList();
}
refreshObservableList();
}
@FXML
......
......@@ -47,7 +47,7 @@
</VBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="15.0" GridPane.columnIndex="3" GridPane.rowIndex="1">
<children>
<Button fx:id="cancelButton" mnemonicParsing="false" text="Cancel" />
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#closeButton" text="Cancel" />
<Button fx:id="addButton" mnemonicParsing="false" onAction="#addBudget" text="Add New Budget" />
</children>
</HBox>
......
......@@ -36,7 +36,7 @@
<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 minHeight="60.0" minWidth="100.0" mnemonicParsing="false" prefWidth="100.0" text="Edit/Remove" />
<Button fx:id="editBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#switchAddBudget" prefWidth="100.0" text="Edit/Remove" />
<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