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

Renamed method + made error dialog box customizable

parent c5c1a6f0
No related branches found
No related tags found
1 merge request!43Merging frontend-testing into master
package no.ntnu.idatt1002.demo.controller;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
......@@ -51,6 +53,13 @@ public class BudgetController implements FinanceController {
@FXML
private Button returnBtn;
@FXML
private Button backBtn;
@FXML
private Button continueBtn;
@FXML
private TableColumn<BudgetItem, Double> amountCol;
......@@ -69,9 +78,6 @@ public class BudgetController implements FinanceController {
@FXML
private DatePicker date;
@FXML
private TableColumn<BudgetItem, Double> percentageColumn;
@FXML
private ObservableList<BudgetItem> budgetList;
......@@ -85,7 +91,6 @@ public class BudgetController implements FinanceController {
@FXML
public void initialize() {
//TODO make budget item throw exception with negative amount
//TODO specify error messgage for when amount is exceeded / duplicate exists
//todo properly close screen so things are saved
//Initialize table columns
......@@ -93,16 +98,36 @@ public class BudgetController implements FinanceController {
amountCol.setCellValueFactory(new PropertyValueFactory<BudgetItem, Double>("budgetAmount"));
descriptionCol.setCellValueFactory(new PropertyValueFactory<BudgetItem, String>("budgetDescription"));
/*FileHandlingBudget fileHandlingBudget = new FileHandlingBudget();
try {
if (fileHandlingBudget.isEmpty("Budget")) {
returnBtn.setOpacity(0);
} else {
addBtn.setDisable(true);
editBtn.setDisable(true);
deleteBtn.setDisable(true);
backBtn.setOpacity(0);
continueBtn.setOpacity(0);
}
} catch(IOException ioe) {
showErrorDialogBox("File reading error", "Error in reading file", "Could not"
+ "read from the Budget file");
}*/
try { //Initialize registers, tableview and pie charts
//if (FileHandlingBudget.hasBudgetSet - from line 4/5, so after the general amount and such) {
//add, edit and delete buttons are removed.
//hvis linje fire er tom, instansier et nytt register, hvis ikke, last ned fra fil
general = loadBudgetDataFromFile("Budget");
budgetList = FXCollections.observableArrayList(general.getBudgetItems());
budgetTableView.setItems(budgetList);
refreshPieChart();
} catch(IOException ioe) {
showErrorDialogBox("File reading error", "Error in reading from file", "An error occurred"
+ "when reading the registers from file");
showErrorDialogBox("File reading error", "Error in reading from file", "Could not read"
+ " registers from file");
}
setButtons();
......@@ -112,6 +137,10 @@ public class BudgetController implements FinanceController {
//sum.setText(String.valueOf(general.totalSum()));
}
/**
* Method that disables or removes button, based on where the budget window
* is being used.
*/
private void setButtons() {
FileHandlingBudget fileHandlingBudget = new FileHandlingBudget();
try {
......@@ -121,15 +150,13 @@ public class BudgetController implements FinanceController {
addBtn.setDisable(true);
editBtn.setDisable(true);
deleteBtn.setDisable(true);
backBtn.setOpacity(0);
continueBtn.setOpacity(0);
}
} catch(IOException ioe) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Confirm Delete");
alert.setHeaderText("Delete Confirmation");
alert.setContentText("Are you sure you would like to delete the selected entry?");
alert.show();
showErrorDialogBox("File reading error", "Error in reading file", "Could not"
+ "read from the Budget file");
}
}
......@@ -318,23 +345,31 @@ public class BudgetController implements FinanceController {
}
/**
* Switches scenes back to main menu, by loading a new FXML file and setting the scene to this location.
* Switches scene, by loading a new FXML file and setting the scene to this location.
* @param event A button click on the return to main menu button
* @throws IOException If an error occurs with loading any of the FXML files.
*/
@FXML
public void returnToMainMenu(ActionEvent event) throws IOException {
//Adds unused categories to the table
general.addUnusedCategories();
//Always saving the data when switching scenes
saveDataToFile();
public void switchScene(ActionEvent event) {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
try {
if (event.getSource() == returnBtn || event.getSource() == continueBtn) {
//Adds unused categories to the table
general.addUnusedCategories();
//Always saving the data when switching scenes
saveDataToFile();
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
} else if (event.getSource() == backBtn) {
loader.setLocation(getClass().getResource("/view/dualList.fxml"));
}
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
} catch(Exception ioe) {
showErrorDialogBox("Loading error", "Error in loading", "Could load"
+ "to FXML file");
}
}
}
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