Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
idatt1002_2023_9
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Kluge Svendsrud
idatt1002_2023_9
Commits
30bde2a4
Commit
30bde2a4
authored
1 year ago
by
Harry Linrui XU
Browse files
Options
Downloads
Patches
Plain Diff
Renamed method + made error dialog box customizable
parent
c5c1a6f0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!43
Merging frontend-testing into master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java
+61
-26
61 additions, 26 deletions
...a/no/ntnu/idatt1002/demo/controller/BudgetController.java
with
61 additions
and
26 deletions
src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java
+
61
−
26
View file @
30bde2a4
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 occur
red"
+
"
when reading the
registers from file"
);
showErrorDialogBox
(
"File reading error"
,
"Error in reading from file"
,
"
Could not
re
a
d"
+
" 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 scene
s 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"
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment