Skip to content

Commit c834f3c

Browse files
committed
Radio button event handlers set labels; Added TableView functionality for Product scenes; AddPart save button adds part to inventory, all save buttons navigate to MainWindow
1 parent 1a4f0cf commit c834f3c

5 files changed

Lines changed: 112 additions & 26 deletions

File tree

src/main/java/sealey/javafxinventorysystem/AddPart.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import javafx.scene.control.TextField;
1313
import javafx.scene.control.ToggleGroup;
1414
import javafx.stage.Stage;
15+
import sealey.javafxinventorysystem.models.InHouse;
16+
import sealey.javafxinventorysystem.models.Inventory;
17+
import sealey.javafxinventorysystem.models.OutSourced;
18+
import sealey.javafxinventorysystem.models.Part;
1519

1620
import java.io.IOException;
1721
import java.net.URL;
@@ -67,15 +71,39 @@ void onActionCancel(ActionEvent event) throws IOException {
6771
stage.setScene(new Scene(scene));
6872
stage.show();
6973
}
74+
@FXML
75+
void onActionSave(ActionEvent event) throws IOException {
76+
int id = Integer.parseInt(partIDText.getText());
77+
String name = partNameText.getText();
78+
int inv = Integer.parseInt(inventoryText.getText());
79+
double price = Double.parseDouble(priceText.getText());
80+
int max = Integer.parseInt(maxText.getText());
81+
int min = Integer.parseInt(minText.getText());
82+
boolean isInHouse = !outsourcedRadio.isSelected();
83+
84+
if(isInHouse){
85+
InHouse newPart = new InHouse(id,name,price,inv,max,min);
86+
newPart.setMachineId(Integer.parseInt(machineIDText.getText()));
87+
Inventory.addPart(newPart);
88+
} else {
89+
OutSourced newPart = new OutSourced(id,name,price,inv,max,min);
90+
newPart.setCompanyName(machineIDText.getText());
91+
Inventory.addPart(newPart);
92+
}
93+
94+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
95+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
96+
stage.setScene(new Scene(scene));
97+
stage.show();
98+
}
7099

71100
@FXML
72101
void onActionCompanyLabel(ActionEvent event) {
73-
System.out.println("Change machine id label to company name");
102+
machineIDLabel.setText("Company Name");
74103
}
75-
76104
@FXML
77-
void onActionSave(ActionEvent event) {
78-
System.out.println("Save button pressed");
105+
public void onActionMachineLabel(ActionEvent actionEvent) {
106+
machineIDLabel.setText("Machine ID");
79107
}
80108

81109
@Override

src/main/java/sealey/javafxinventorysystem/AddProduct.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javafx.scene.control.TableView;
1212
import javafx.scene.control.TextField;
1313
import javafx.stage.Stage;
14+
import sealey.javafxinventorysystem.models.Part;
1415

1516
import java.io.IOException;
1617
import java.net.URL;
@@ -55,34 +56,34 @@ public class AddProduct implements Initializable {
5556
private TextField searchPartText;
5657

5758
@FXML
58-
private TableView<?> table1;
59+
private TableView<Part> table1;
5960

6061
@FXML
61-
private TableColumn<?, ?> table1IDCol;
62+
private TableColumn<Part, Integer> table1IDCol;
6263

6364
@FXML
64-
private TableColumn<?, ?> table1InvCol;
65+
private TableColumn<Part, Integer> table1InvCol;
6566

6667
@FXML
67-
private TableColumn<?, ?> table1NameCol;
68+
private TableColumn<Part, String> table1NameCol;
6869

6970
@FXML
70-
private TableColumn<?, ?> table1PriceCol;
71+
private TableColumn<Part, Double> table1PriceCol;
7172

7273
@FXML
73-
private TableView<?> table2;
74+
private TableView<Part> table2;
7475

7576
@FXML
76-
private TableColumn<?, ?> table2IDCol;
77+
private TableColumn<Part, Integer> table2IDCol;
7778

7879
@FXML
79-
private TableColumn<?, ?> table2InvCol;
80+
private TableColumn<Part, Integer> table2InvCol;
8081

8182
@FXML
82-
private TableColumn<?, ?> table2NameCol;
83+
private TableColumn<Part, String> table2NameCol;
8384

8485
@FXML
85-
private TableColumn<?, ?> table2PriceCol;
86+
private TableColumn<Part, Double> table2PriceCol;
8687

8788
@FXML
8889
void onActionCancel(ActionEvent event) throws IOException {
@@ -91,6 +92,20 @@ void onActionCancel(ActionEvent event) throws IOException {
9192
stage.setScene(new Scene(scene));
9293
stage.show();
9394
}
95+
@FXML
96+
void onActionSave(ActionEvent event) throws IOException {
97+
int id = Integer.parseInt(productIDText.getText());
98+
String name = productNameText.getText();
99+
int inv = Integer.parseInt(inventoryText.getText());
100+
double price = Double.parseDouble(priceText.getText());
101+
int max = Integer.parseInt(maxText.getText());
102+
int min = Integer.parseInt(minText.getText());
103+
104+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
105+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
106+
stage.setScene(new Scene(scene));
107+
stage.show();
108+
}
94109

95110
@Override
96111
public void initialize(URL url, ResourceBundle resourceBundle) {

src/main/java/sealey/javafxinventorysystem/ModifyPart.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,37 @@ public class ModifyPart implements Initializable {
6161
@FXML
6262
private Button saveButton;
6363

64+
@FXML
65+
void onActionCompanyLabel(ActionEvent event) {
66+
machineIDLabel.setText("Company Name");
67+
}
68+
@FXML
69+
public void onActionMachineLabel(ActionEvent actionEvent) {
70+
machineIDLabel.setText("Machine ID");
71+
}
72+
6473
@FXML
6574
void onActionCancel(ActionEvent event) throws IOException {
6675
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
6776
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
6877
stage.setScene(new Scene(scene));
6978
stage.show();
7079
}
80+
@FXML
81+
void onActionSave(ActionEvent event) throws IOException {
82+
/*int id = Integer.parseInt(partIDText.getText());
83+
String name = partNameText.getText();
84+
int inv = Integer.parseInt(inventoryText.getText());
85+
double price = Double.parseDouble(priceText.getText());
86+
int max = Integer.parseInt(maxText.getText());
87+
int min = Integer.parseInt(minText.getText());
88+
boolean isInHouse = !outsourcedRadio.isSelected();*/
89+
90+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
91+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
92+
stage.setScene(new Scene(scene));
93+
stage.show();
94+
}
7195

7296
@Override
7397
public void initialize(URL url, ResourceBundle resourceBundle) {

src/main/java/sealey/javafxinventorysystem/ModifyProduct.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import javafx.scene.control.TextField;
1313
import javafx.stage.Stage;
1414

15+
import sealey.javafxinventorysystem.models.Part;
16+
1517
import java.io.IOException;
1618
import java.net.URL;
1719
import java.util.Objects;
@@ -55,34 +57,34 @@ public class ModifyProduct implements Initializable {
5557
private TextField searchProductText;
5658

5759
@FXML
58-
private TableView<?> table1;
60+
private TableView<Part> table1;
5961

6062
@FXML
61-
private TableColumn<?, ?> table1IDCol;
63+
private TableColumn<Part, Integer> table1IDCol;
6264

6365
@FXML
64-
private TableColumn<?, ?> table1InvCol;
66+
private TableColumn<Part, Integer> table1InvCol;
6567

6668
@FXML
67-
private TableColumn<?, ?> table1NameCol;
69+
private TableColumn<Part, String> table1NameCol;
6870

6971
@FXML
70-
private TableColumn<?, ?> table1PriceCol;
72+
private TableColumn<Part, Double> table1PriceCol;
7173

7274
@FXML
73-
private TableView<?> table2;
75+
private TableView<Part> table2;
7476

7577
@FXML
76-
private TableColumn<?, ?> table2IDCol;
78+
private TableColumn<Part, Integer> table2IDCol;
7779

7880
@FXML
79-
private TableColumn<?, ?> table2InvCol;
81+
private TableColumn<Part, Integer> table2InvCol;
8082

8183
@FXML
82-
private TableColumn<?, ?> table2NameCol;
84+
private TableColumn<Part, String> table2NameCol;
8385

8486
@FXML
85-
private TableColumn<?, ?> table2PriceCol;
87+
private TableColumn<Part, Double> table2PriceCol;
8688

8789
@FXML
8890
void onActionCancel(ActionEvent event) throws IOException {
@@ -91,6 +93,20 @@ void onActionCancel(ActionEvent event) throws IOException {
9193
stage.setScene(new Scene(scene));
9294
stage.show();
9395
}
96+
@FXML
97+
void onActionSave(ActionEvent event) throws IOException {
98+
int id = Integer.parseInt(productIDText.getText());
99+
String name = productNameText.getText();
100+
int inv = Integer.parseInt(inventoryText.getText());
101+
double price = Double.parseDouble(priceText.getText());
102+
int max = Integer.parseInt(maxText.getText());
103+
int min = Integer.parseInt(minText.getText());
104+
105+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
106+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
107+
stage.setScene(new Scene(scene));
108+
stage.show();
109+
}
94110

95111
@Override
96112
public void initialize(URL url, ResourceBundle resourceBundle) {

src/main/java/sealey/javafxinventorysystem/models/Part.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
package sealey.javafxinventorysystem.models;
1+
package sealey.javafxinventorysystem.models; /**
2+
* Supplied class Part.java
3+
*/
24

35
/**
6+
*
47
* @author Max Sealey
58
*/
69
public abstract class Part {
@@ -19,7 +22,6 @@ public Part(int id, String name, double price, int stock, int min, int max) {
1922
this.max = max;
2023
}
2124

22-
// Getters and Setters
2325
/**
2426
* @return the id
2527
*/
@@ -103,4 +105,5 @@ public int getMax() {
103105
public void setMax(int max) {
104106
this.max = max;
105107
}
108+
106109
}

0 commit comments

Comments
 (0)