JavaFX Product List

Assignment

FXMLDocumentController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims;

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.Initializable;

import javafx.scene.control.Label;

/**

*

* @author Davidson

*/

public class FXMLDocumentController implements Initializable {

@FXML

private Label label;

@FXML

private void handleButtonAction(ActionEvent event) {

System.out.println(“You clicked me!”);

label.setText(“Hello World!”);

}

@Override

public void initialize(URL url, ResourceBundle rb) {

// TODO

}

}

 RobDavidsonIMS.java

 /*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims;

import javafx.application.Application;

import javafx.fxml.FXMLLoader;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.stage.Stage;

/**

*

* @author Davidson

*/

public class RobDavidsonIMS extends Application {

@Override

public void start(Stage stage) throws Exception {

Parent root = FXMLLoader.load(getClass().getResource(“view_controller/MainScreen.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

launch(args);

}

}

 AddPartController.java

 /*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.Initializable;

import javafx.scene.control.Button;

import javafx.scene.control.RadioButton;

import javafx.scene.control.TextField;

import javafx.scene.control.ToggleGroup;

import javafx.scene.text.Text;

/**

* FXML Controller class

*

* @author Davidson

*/

public class AddPartController implements Initializable {

@FXML

private TextField addPartID;

@FXML

private TextField addPartName;

@FXML

private TextField addPartInv;

@FXML

private Text addPartTxtID;

@FXML

private TextField addPartPriCos;

@FXML

private TextField addPartMax;

@FXML

private TextField addPartMin;

@FXML

private Button addPartSave;

@FXML

private RadioButton inHouse;

@FXML

private ToggleGroup inOutPart;

@FXML

private RadioButton outSourced;

@FXML

private TextField addPartMachID;

@FXML

private Text machCompTxt;

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL url, ResourceBundle rb) {

// TODO

}

@FXML

void addPartSaveHandler(ActionEvent event) {

String MachID=addPartMachID.getText();

//public InHousePart (int ID, String Name, int Instock, Double Cost, int Min, int Max, int MacID)

Part newPart=new InHousePart(Integer.parseInt(int ID, String Name, int Instock, Double Cost, int Min, int Max, int MacID));

}

@FXML

void inHouseHandler(ActionEvent event) {

machCompTxt.setText(“Machine ID”);

}

@FXML

void outSourcedHandler(ActionEvent event) {

machCompTxt.setText(“Company Name”);

}

}

AddProductController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.Initializable;

import javafx.scene.control.Button;

import javafx.scene.control.TableColumn;

/**

* FXML Controller class

*

* @author Davidson

*/

public class AddProductController implements Initializable {

@FXML

private Button AddPartSave;

@FXML

private TableColumn<?, ?> addProductProductIDColumn;

@FXML

private TableColumn<?, ?> productsProductNameColumn;

@FXML

private TableColumn<?, ?> productsInventoryLevelColumn;

@FXML

private TableColumn<?, ?> productsPricePerUnitColumn;

@FXML

private TableColumn<?, ?> addProductProductIDColumn1;

@FXML

private TableColumn<?, ?> productsProductNameColumn1;

@FXML

private TableColumn<?, ?> productsInventoryLevelColumn1;

@FXML

private TableColumn<?, ?> productsPricePerUnitColumn1;

@FXML

private Button AddPartSave1;

@FXML

private Button AddPartSave11;

@FXML

private Button AddPartSave12;

@FXML

private Button AddPartSave13;

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL url, ResourceBundle rb) {

// TODO

}

@FXML

private void addPartSaveHandler(ActionEvent event) {

}

} 

MainScreenController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.io.IOException;

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.FXMLLoader;

import javafx.fxml.Initializable;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.TableColumn;

import javafx.scene.control.TableView;

import javafx.scene.control.TextField;

import javafx.stage.Stage;

/**

* FXML Controller class

*

* @author Davidson

*/

public class MainScreenController implements Initializable {

@FXML

private Button mainSearchBtn1;

@FXML

private TextField mainSearchPartTxt;

@FXML

private TableView<?> mainPartTable;

@FXML

private TableColumn<?, ?> mainPartIDColumn;

@FXML

private TableColumn<?, ?> mainPartNameColumn;

@FXML

private TableColumn<?, ?> mainInvLevelColumn1;

@FXML

private TableColumn<?, ?> mainPriCosUnitColumn;

@FXML

private Button mainDelBtn1;

@FXML

private Button mainModBtn1;

@FXML

private Button mainAddBtn1;

@FXML

private Button mainSearchBtn2;

@FXML

private TextField mainSearchProTxt;

@FXML

private TableView<?> mainProTable;

@FXML

private TableColumn<?, ?> mainProIDColumn;

@FXML

private TableColumn<?, ?> mainProNameColumn;

@FXML

private TableColumn<?, ?> mainInvLevelColumn2;

@FXML

private TableColumn<?, ?> mainPriUniColumn;

@FXML

private Button mainModBtn2;

@FXML

private Button mainAddBtn2;

@FXML

private Button mainDelBtn2;

@FXML

private Button mainExit;

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL url, ResourceBundle rb) {

// TODO

}

@FXML

void mainAddBtn1Handler(ActionEvent event)throws IOException{

Stage stage;

Parent root;

stage=(Stage) mainAddBtn1.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“AddPart.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

@FXML

void mainAddBtn2Handler(ActionEvent event) throws IOException {

Stage stage;

Parent root;

stage=(Stage) mainAddBtn2.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“AddProduct.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

@FXML

void mainDelBtn1Handler(ActionEvent event) {

}

@FXML

void mainDelBtn2Handler(ActionEvent event) {

}

@FXML

void mainExitHandler(ActionEvent event) {

Stage stage = (Stage) mainExit.getScene().getWindow();

stage.close();

}

@FXML

void mainModBtn1Handler(ActionEvent event) throws IOException {

Stage stage;

Parent root;

stage=(Stage) mainModBtn1.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“ModifyPart.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

@FXML

void mainModBtn2Handler(ActionEvent event) throws IOException {

Stage stage;

Parent root;

stage=(Stage) mainModBtn2.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“ModifyProduct.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

@FXML

void mainSearchBtn1Handler(ActionEvent event) {

}

@FXML

void mainSearchBtn2Handler(ActionEvent event) {

}

@FXML

void mainSearchPartTxtHandler(ActionEvent event) {

}

@FXML

void mainSearchProTxtHandler(ActionEvent event) {

}

}

  ModifyPartController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.Initializable;

import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.scene.control.Label;

import javafx.scene.control.TextField;

/**

* FXML Controller class

*

* @author Davidson

*/

public class ModifyPartController implements Initializable {

@FXML

private Label modPartLabel;

@FXML

private TextField modPartIDTxt;

@FXML

private Button modPartSaveBtn;

@FXML

private Button modPartCancelBtn;

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL url, ResourceBundle rb) {

// TODO

}

@FXML

void modPartCancelBtnHandler(ActionEvent event) {

}

@FXML

void modPartIDTxtHandler(ActionEvent event) {

}

@FXML

void modPartSaveBtnHandler(ActionEvent event) {

}

} 

ModifyProductController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.Initializable;

import javafx.scene.control.Button;

import javafx.scene.control.TableColumn;

/**

* FXML Controller class

*

* @author Davidson

*/

public class ModifyProductController implements Initializable {

@FXML

private Button AddPartSave;

@FXML

private TableColumn<?, ?> addProductProductIDColumn;

@FXML

private TableColumn<?, ?> productsProductNameColumn;

@FXML

private TableColumn<?, ?> productsInventoryLevelColumn;

@FXML

private TableColumn<?, ?> productsPricePerUnitColumn;

@FXML

private TableColumn<?, ?> addProductProductIDColumn1;

@FXML

private TableColumn<?, ?> productsProductNameColumn1;

@FXML

private TableColumn<?, ?> productsInventoryLevelColumn1;

@FXML

private TableColumn<?, ?> productsPricePerUnitColumn1;

@FXML

private Button AddPartSave1;

@FXML

private Button AddPartSave11;

@FXML

private Button AddPartSave12;

@FXML

private Button AddPartSave13;

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL url, ResourceBundle rb) {

// TODO

}

@FXML

private void addPartSaveHandler(ActionEvent event) {

}

}

  InHousePart.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.beans.property.IntegerProperty;

import javafx.beans.property.SimpleIntegerProperty;

/**

*

* @author Davidson

*/

public class InHousePart extends Part{

private final IntegerProperty machineID;

public InHousePart (int ID, String Name, int Instock, Double Cost, int Min, int Max, int MacID) {

super(ID, Name, Instock, Cost, Min, Max);

this.machineID=new SimpleIntegerProperty(MacID);

}

//Getter

public int getMachineID() {

return machineID.get();

}

//Setter

public void setMachineID(int ID) {

this.machineID.set(ID);

}

//Property

public IntegerProperty MachineIDProperty() {

return machineID;

}

}

 Inventory.java

 /*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.collections.FXCollections;

import javafx.collections.ObservableList;

/**

*

* @author Davidson

*/

public class Inventory {

private static ObservableList<Part> allParts=FXCollections.observableArrayList();

private static ObservableList<Product> products=FXCollections.observableArrayList();

public static ObservableList<Part> getAllParts() {

return allParts;

}

public static void setAllParts(ObservableList<Part> parts) {

allParts=parts;

}

public static void addProduct(Product p) {

//functionality is handled in the add product controller

products.add (p);

}

public static boolean removeProduct (int i) {

Product p=products.get(i);

return products.remove (p);

}

public static Product lookupProduct (int i) {

return products.get(i);

}

//public static updateProduct (int i){ } This functionality is handled in the ModifyProductController.

public static void addPart (Part p) {

allParts.add (p);

}

public static boolean deletePart (Part p) {

allParts.remove(p);

return true;

}

}

OutsourcedPart.java

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.beans.property.StringProperty;

import javafx.beans.property.SimpleStringProperty;

/**

*

* @author Davidson

*/

public class OutsourcedPart extends Part {

private final StringProperty companyName;

public OutsourcedPart (int ID, String Name, int Instock, Double Cost, int Min, int Max, String CompName) {

super(ID, Name, Instock, Cost, Min, Max);

this.companyName=new SimpleStringProperty(CompName);

}

//Getter

public String getCompanyName() {

return companyName.get();

}

//Setter

public void setCompanyName(String Name) {

this.companyName.set(Name);

}

//Property

public StringProperty CompanyNameProperty() {

return companyName;

}

}

  Part.java

 /*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.beans.property.DoubleProperty;

import javafx.beans.property.IntegerProperty;

import javafx.beans.property.SimpleDoubleProperty;

import javafx.beans.property.SimpleIntegerProperty;

import javafx.beans.property.SimpleStringProperty;

import javafx.beans.property.StringProperty;

/**

*

* @author Davidson

*/

public abstract class Part {

private final IntegerProperty partID;

private final StringProperty partName;

private final IntegerProperty partInstock;

private final DoubleProperty partCost;

private final IntegerProperty partMin;

private final IntegerProperty partMax;

//Default constructor

public Part() {

this(0, null, 0, 0.0, 0, 0);

}

//Constructor with initial data

public Part (int ID, String Name, int Instock, Double Cost, int Min, int Max) {

this.partID=new SimpleIntegerProperty(ID);

this.partName=new SimpleStringProperty(Name);

this.partInstock=new SimpleIntegerProperty(Instock);

this.partCost=new SimpleDoubleProperty(Cost);

this.partMin=new SimpleIntegerProperty(Min);

this.partMax=new SimpleIntegerProperty(Max);

}

//Getters Setters and Returning Properties

//Getter

public int getPartID() {

return partID.get();

}

//Setter

public void setPartID(int ID) {

this.partID.set(ID);

}

//Property

public IntegerProperty PartIDProperty() {

return partID;

}

//Getter

public String getPartName() {

return partName.get();

}

//Setter

public void setPartName(String Name) {

this.partName.set(Name);

}

//Property

public StringProperty PartNameProperty() {

return partName;

}

//Getter

public int getPartInstock() {

return partInstock.get();

}

//Setter

public void setPartInstock(int Instock) {

this.partInstock.set(Instock);

}

//Property

public IntegerProperty PartInstockProperty() {

return partInstock;

}

//Getter

public double getPartCost() {

return partCost.get();

}

//Setter

public void setPartCost(double Cost) {

this.partCost.set(Cost);

}

//Property

public DoubleProperty PartCostProperty() {

return partCost;

}

//Getter

public int getPartMin() {

return partMin.get();

}

//Setter

public void setPartMin(int Min) {

this.partMin.set(Min);

}

//Property

public IntegerProperty PartMinProperty() {

return partMin;

}

//Getter

public int getPartMax() {

return partMax.get();

}

//Setter

public void setPartMax(int Max) {

this.partMax.set(Max);

}

//Property

public IntegerProperty PartMaxProperty() {

return partMax;

}

}

 Product.java

 /*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.beans.property.DoubleProperty;

import javafx.beans.property.IntegerProperty;

import javafx.beans.property.SimpleDoubleProperty;

import javafx.beans.property.SimpleIntegerProperty;

import javafx.beans.property.SimpleStringProperty;

import javafx.beans.property.StringProperty;

import javafx.collections.FXCollections;

import javafx.collections.ObservableList;

/**

*

* @author Davidson

*/

public class Product {

private final IntegerProperty productID;

private final StringProperty productName;

private final IntegerProperty productInstock;

private final DoubleProperty productCost;

private final IntegerProperty productMin;

private final IntegerProperty productMax;

private ObservableList<Part> associatedParts=FXCollections.observableArrayList();

//Default constructor

public Product() {

this(0, null, 0, 0.0, 0, 0,null);

}

//Constructor with initial data

public Product (int ID, String Name, int Instock, Double Cost, int Min, int Max, ObservableList<Part> ap) {

this.productID=new SimpleIntegerProperty(ID);

this.productName=new SimpleStringProperty(Name);

this.productInstock=new SimpleIntegerProperty(Instock);

this.productCost=new SimpleDoubleProperty(Cost);

this.productMin=new SimpleIntegerProperty(Min);

this.productMax=new SimpleIntegerProperty(Max);

if(ap!=null)this.associatedParts=ap;

}

//Getters Setters and Returning Properties

//Getter

public int getProductID() {

return productID.get();

}

//Setter

public void setProductID(int ID) {

this.productID.set(ID);

}

//Property

public IntegerProperty ProductIDProperty() {

return productID;

}

//Getter

public String getProductName() {

return productName.get();

}

//Setter

public void setProductName(String Name) {

this.productName.set(Name);

}

//Property

public StringProperty ProductNameProperty() {

return productName;

}

//Getter

public int getProductInstock() {

return productInstock.get();

}

//Setter

public void setProductInstock(int Instock) {

this.productInstock.set(Instock);

}

//Property

public IntegerProperty ProductInstockProperty() {

return productInstock;

}

//Getter

public double getProductCost() {

return productCost.get();

}

//Setter

public void setProductCost(double Cost) {

this.productCost.set(Cost);

}

//Property

public DoubleProperty ProductCostProperty() {

return productCost;

}

//Getter

public int getProductMin() {

return productMin.get();

}

//Setter

public void setProductMin(int Min) {

this.productMin.set(Min);

}

//Property

public IntegerProperty PartMinProperty() {

return productMin;

}

//Getter

public int getPartMax() {

return productMax.get();

}

//Setter

public void setPartMax(int Max) {

this.productMax.set(Max);

}

//Property

public IntegerProperty PartMaxProperty() {

return productMax;

}

//Getter

public ObservableList<Part> getAssociatedParts() {

return associatedParts;

}

//Setter

public void setAssociatedParts(ObservableList<Part> parts) {

associatedParts=parts;

}

}

   Solution

 FXMLDocumentController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims;

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.Initializable;

import javafx.scene.control.Label;

/**

*

* @author Davidson

*/

public class FXMLDocumentController implements Initializable {

@FXML

private Label label;

@FXML

private void handleButtonAction(ActionEvent event) {

System.out.println(“You clicked me!”);

label.setText(“Hello World!”);

}

@Override

public void initialize(URL url, ResourceBundle rb) {

// TODO

}

} 

RobDavidsonIMS.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims;

import javafx.application.Application;

import javafx.fxml.FXMLLoader;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.stage.Stage;

import robdavidsonims.model.InHousePart;

import robdavidsonims.model.Inventory;

/**

*

* @author Davidson

*/

public class RobDavidsonIMS extends Application {

@Override

public void start(Stage stage) throws Exception {

Parent root = FXMLLoader.load(getClass().getResource(“view_controller/MainScreen.fxml”));

//        Inventory.addPart(new InHousePart(0, “test1”, 0, 22.5, 0, 1, 34));

//        Inventory.addPart(new InHousePart(1, “wertest1”, 0, 22.5, 0, 1, 34));

//        Inventory.addPart(new InHousePart(2, “werttest1”, 0, 22.5, 0, 1, 34));

//        Inventory.addPart(new InHousePart(3, “zxctest1”, 0, 22.5, 0, 1, 34));

//        Inventory.addPart(new InHousePart(4, “ztest1”, 0, 22.5, 0, 1, 34));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

launch(args);

}

}

 AddPartController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.io.IOException;

import java.net.URL;

import java.util.Optional;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.FXMLLoader;

import javafx.fxml.Initializable;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.scene.control.Alert;

import javafx.scene.control.Alert.AlertType;

import javafx.scene.control.Button;

import javafx.scene.control.ButtonType;

import javafx.scene.control.RadioButton;

import javafx.scene.control.TextField;

import javafx.scene.control.ToggleGroup;

import javafx.scene.text.Text;

import javafx.stage.Stage;

import robdavidsonims.model.InHousePart;

import robdavidsonims.model.Inventory;

import robdavidsonims.model.OutsourcedPart;

import robdavidsonims.model.Part;

/**

* FXML Controller class

*

* @author Davidson

*/

public class AddPartController implements Initializable {

// FXML Components

@FXML

private TextField addPartID;

@FXML

private TextField addPartName;

@FXML

private TextField addPartInv;

@FXML

private TextField addPartPriCos;

@FXML

private TextField addPartMax;

@FXML

private TextField addPartMin;

@FXML

private Button addPartSave;

@FXML

private Button addPartCancel;

@FXML

private RadioButton inHouse;

@FXML

private ToggleGroup inOutPart;

@FXML

private RadioButton outSourced;

@FXML

private TextField addPartMachID;

@FXML

private Text machCompTxt;

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL url, ResourceBundle rb) {

addPartID.setEditable(false);

addPartID.setDisable(true);

addPartID.setText(Part.IDCounter + “”);

}

/**

* Handler for saving new part in Add Part Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void addPartSaveHandler(ActionEvent event) throws IOException{

// Initializing part fields with default values

String partName = “”;

int partInventory = 0;

double partPrice = 0;

int partMin = 0;

int partMax = 0;

int machineId = 0;

String companyName = “”;

//////////////////////////////////

/*

Here I have deleted ID text field processing

*/

/////////////////////////////////

// Reading part name

partName = addPartName.getText();

// Trying to read part inv. If it can not be parsed, the value is set to 0, and the textfield is set to “0”

try {

partInventory = Integer.parseInt(addPartInv.getText());

}

catch (NumberFormatException nfe) {

// Setting field and textfield to default value 0

partInventory = 0;

addPartInv.setText(“0”);

}

// Trying to read part price. If it can not be parsed, the exception is thrown and dialog is shown

try {

partPrice = Double.parseDouble(addPartPriCos.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with part price error message

Alert alert = new Alert(AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Invalid part price”);

alert.showAndWait();

return;

}

// Trying to read part max. If it can not be parsed, the exception is thrown and dialog is shown

try {

partMax = Integer.parseInt(addPartMax.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with part max error message

Alert alert = new Alert(AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Invalid part max inventory”);

alert.showAndWait();

return;

}

// Trying to read part min. If it can not be parsed, the exception is thrown and dialog is shown

try {

partMin = Integer.parseInt(addPartMin.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with part min error message

Alert alert = new Alert(AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Invalid part min inventory”);

alert.showAndWait();

return;

}

if (inHouse.isSelected()) {

// If part is inHouse part, then trying to parse machine id

// Trying to read machine id. If it can not be parsed, the exception is thrown and dialog is shown

try {

machineId = Integer.parseInt(addPartMachID.getText());

} catch (NumberFormatException nfe) {

// Creating new dialog window with machine id error message

Alert alert = new Alert(AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Invalid part machine ID”);

alert.showAndWait();

return;

}

}

else {

// If part is outsourced part, then reading company name

// Reading part name

companyName = addPartMachID.getText();

}

// If price is not positive, then the dialog is shown

if (partPrice <= 0) {

// Creating new dialog window with non-positive price message

Alert alert = new Alert(AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Part price must be positive”);

alert.showAndWait();

return;

}

// If part name is empty, then the dialog is shown

if (“”.equals(partName.trim())) {

// Creating new dialog window with empty name message

Alert alert = new Alert(AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Part name must not be empty”);

alert.showAndWait();

return;

}

// If max is less than min, then the dialog is shown

if (partMax < partMin) {

// Creating new dialog window with illegal max/min message

Alert alert = new Alert(AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Part max inventory must not be less than min inventory”);

alert.showAndWait();

return;

}

// If part inv is not in range, then the dialog is shown

if ((partInventory > partMax) || (partInventory < partMin)) {

// Creating new dialog window with illegal part inv message

Alert alert = new Alert(AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Part inventory must be between min and max”);

alert.showAndWait();

return;

}

if (inHouse.isSelected()) {

// If inHouse toggle is selected, than add new part to the inventory

//////////////////////

/* Removed ID argument from constructor call*/

Inventory.addPart(new InHousePart(partName, partInventory, partPrice, partMin, partMax, machineId));

//////////////////////

}

else {

// If outcourced toggle is selected, than add new part to the inventory

//////////////////////

/* Removed ID argument from constructor call*/

Inventory.addPart(new OutsourcedPart(partName, partInventory, partPrice, partMin, partMax, companyName));

//////////////////////

}

// Returning to main screen

Stage stage;

Parent root;

stage = (Stage) addPartCancel.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“MainScreen.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* Handler for cancel in Add Part Window

* @param event action event

*/

@FXML

void addPartCancelHandler(ActionEvent event) throws IOException{

// Creating new dialog window cancelling question

Alert alert = new Alert(AlertType.CONFIRMATION);

alert.setTitle(“Add part”);

alert.setHeaderText(“Are you sure, you want to cancel part adding?”);

ButtonType yesButton = new ButtonType(“Yes”);

ButtonType noButton = new ButtonType(“No”);

alert.getButtonTypes().setAll(yesButton, noButton);

Optional<ButtonType> result = alert.showAndWait();

// If “Yes” is selected, return to main screen

if (result.get() == yesButton) {

Stage stage;

Parent root;

stage = (Stage) addPartCancel.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“MainScreen.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

}

/**

* InHouse toggle listener

* @param event action event

*/

@FXML

void inHouseHandler(ActionEvent event) {

// Changing machineID/company label, if toggle is changed

machCompTxt.setText(“Machine ID”);

}

/**

* OutSourced toggle listener

* @param event action event

*/

@FXML

void outSourcedHandler(ActionEvent event) {

// Changing machineID/company label, if toggle is changed

machCompTxt.setText(“Company Name”);

}

}

 AddProductController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.io.IOException;

import java.net.URL;

import java.util.Optional;

import java.util.ResourceBundle;

import javafx.beans.value.ChangeListener;

import javafx.beans.value.ObservableValue;

import javafx.collections.FXCollections;

import javafx.collections.ObservableList;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.FXMLLoader;

import javafx.fxml.Initializable;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.scene.control.Alert;

import javafx.scene.control.Button;

import javafx.scene.control.ButtonType;

import javafx.scene.control.TableColumn;

import javafx.scene.control.TableView;

import javafx.scene.control.TextField;

import javafx.scene.control.cell.PropertyValueFactory;

import javafx.stage.Stage;

import robdavidsonims.model.Inventory;

import robdavidsonims.model.Part;

import robdavidsonims.model.Product;

public class AddProductController implements Initializable{

// FXML Components

@FXML

private TextField addProductID;

@FXML

private Button addProductDeleteBtn;

@FXML

private TableColumn<Part, Double> addProductAddPartPriceColumn;

@FXML

private Button addProductAddBtn;

@FXML

private TableColumn<Part, String> addProductDeletePartNameColumn;

@FXML

private Button addProductSearchBtn;

@FXML

private TableView<Part> addProductAddPartTable;

@FXML

private TextField addProductMin;

@FXML

private Button addProductSaveBtn;

@FXML

private TextField addProductInv;

@FXML

private TableColumn<Part, Integer> addProductDeletePartIDColumn;

@FXML

private TableColumn<Part, String> addProductAddPartNameColumn;

@FXML

private TableColumn<Part, Integer> addProductAddPartInvColumn;

@FXML

private TextField addProductMax;

@FXML

private TableColumn<Part, Double> addProductDeletePartPriceColumn;

@FXML

private Button addProductCancelBtn;

@FXML

private TableView<Part> addProductDeletePartTable;

@FXML

private TableColumn<Part, Integer> addProductAddPartIDColumn;

@FXML

private TableColumn<Part, Integer> addProductDeletePartInvColumn;

@FXML

private TextField addProductName;

@FXML

private TextField addProductPrice;

@FXML

private TextField addProductSearchTxt;

// Parts list for new product

private ObservableList<Part> parts;

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL location, ResourceBundle resources) {

addProductID.setEditable(false);

addProductID.setDisable(true);

addProductID.setText(Product.IDCounter + “”);

// Creating new parts empty list

parts = FXCollections.observableArrayList();

// Setting value factories for each column of add part table

addProductAddPartIDColumn.setCellValueFactory(new PropertyValueFactory<>(“partID”));

addProductAddPartNameColumn.setCellValueFactory(new PropertyValueFactory<>(“partName”));

addProductAddPartInvColumn.setCellValueFactory(new PropertyValueFactory<>(“partInstock”));

addProductAddPartPriceColumn.setCellValueFactory(new PropertyValueFactory<>(“partCost”));

// Adding all parts from the inventory(empty) to the table

addProductAddPartTable.setItems(Inventory.getAllParts());

// Disabling add button, as now row is selected

addProductAddBtn.setDisable(true);

// Adding row selection listener to the add part table

addProductAddPartTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Part>() {

@Override

public void changed(ObservableValue<? extends Part> observable, Part oldValue, Part newValue) {

// If new selection contains no rows, then add button is disabled

if (newValue == null) {

addProductAddBtn.setDisable(true);

}

// Otherwise, add button is enabled

else {

addProductAddBtn.setDisable(false);

}

}

});

// Setting value factories for each column of del part table

addProductDeletePartIDColumn.setCellValueFactory(new PropertyValueFactory<>(“partID”));

addProductDeletePartNameColumn.setCellValueFactory(new PropertyValueFactory<>(“partName”));

addProductDeletePartInvColumn.setCellValueFactory(new PropertyValueFactory<>(“partInstock”));

addProductDeletePartPriceColumn.setCellValueFactory(new PropertyValueFactory<>(“partCost”));

// Disabling del button, as now row is selected

addProductDeleteBtn.setDisable(true);

// Adding row selection listener to the del part table        addProductDeletePartTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Part>() {

@Override

public void changed(ObservableValue<? extends Part> observable, Part oldValue, Part newValue) {

// If new selection contains no rows, then del button is disabled

if (newValue == null) {

addProductDeleteBtn.setDisable(true);

}

// Otherwise, del button is enabled

else {

addProductDeleteBtn.setDisable(false);

}

}

});

}

/**

* Handler for search part button in the Add Product Window

* @param event action event

*/

@FXML

void addProductSearchBtnHandler(ActionEvent event) {

// Get input name prefix

String prefix = addProductSearchTxt.getText();

// Creating empty new list for updated tables

ObservableList<Part> addParts = FXCollections.observableArrayList();

ObservableList<Part> delParts = FXCollections.observableArrayList();

// If part p is not in ‘parts’ and matches prefix, then it is available for add table

for (Part p : Inventory.getAllParts()) {

if (parts.contains(p))

continue;

if (p.getPartName().startsWith(prefix))

addParts.add(p);

}

// If part p is in ‘parts’ and matches prefix, then it is available for del table

for (Part p : Inventory.getAllParts()) {

if ((parts.contains(p)) && (p.getPartName().startsWith(prefix)))

delParts.add(p);

}

// Set updated lists to the tables

addProductAddPartTable.setItems(addParts);

addProductDeletePartTable.setItems(delParts);

}

/**

* Handler for del part button in the Add Product Window

* @param event action event

*/

@FXML

void addProductDeleteBtnHandler(ActionEvent event) {

// Removing selected part from ‘parts’

Part p = addProductDeletePartTable.getSelectionModel().getSelectedItem();

parts.remove(p);

// Creating empty new list for updated tables

ObservableList<Part> addParts = FXCollections.observableArrayList();

ObservableList<Part> delParts = FXCollections.observableArrayList();

// If part p is not in ‘parts’, then it is available for add table

for (Part pt : Inventory.getAllParts()) {

if (!parts.contains(pt))

addParts.add(pt);

}

// If part p is in ‘parts’, then it is available for del table

for (Part pt : Inventory.getAllParts()) {

if (parts.contains(pt))

delParts.add(pt);

}

// Set updated lists to the tables

addProductAddPartTable.setItems(addParts);

addProductDeletePartTable.setItems(delParts);

}

/**

* Handler for cancel in Add Product Window

* @param event action event

*/

@FXML

void addProductCancelBtn(ActionEvent event) throws IOException{

// Creating new dialog window with cancelling question

Alert alert = new Alert(Alert.AlertType.CONFIRMATION);

alert.setTitle(“Add product”);

alert.setHeaderText(“Are you sure, you want to cancel product adding?”);

ButtonType yesButton = new ButtonType(“Yes”);

ButtonType noButton = new ButtonType(“No”);

alert.getButtonTypes().setAll(yesButton, noButton);

Optional<ButtonType> result = alert.showAndWait();

// If “Yes” is selected, return to main screen

if (result.get() == yesButton) {

Stage stage;

Parent root;

stage = (Stage) addProductCancelBtn.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“MainScreen.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

}

/**

* Handler for saving new product in Add Product Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void addProductSaveBtnHandler(ActionEvent event) throws IOException{

// Initializing part fields with default values

String prodName = “”;

int prodInventory = 0;

double prodPrice = 0;

int prodMin = 0;

int prodMax = 0;

//////////////////////////////////

/*

Here I have deleted ID text field processing

*/

/////////////////////////////////

// Reading product name

prodName = addProductName.getText();

// Trying to read product inv. If it can not be parsed, the value is set to 0, and the textfield is set to “0”

try {

prodInventory = Integer.parseInt(addProductInv.getText());

}

catch (NumberFormatException nfe) {

// Setting field and textfield to default value 0

prodInventory = 0;

addProductInv.setText(“0”);

}

// Trying to read product price. If it can not be parsed, the exception is thrown and dialog is shown

try {

prodPrice = Double.parseDouble(addProductPrice.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with product price error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add product”);

alert.setHeaderText(“Add product error”);

alert.setContentText(“Invalid product price”);

alert.showAndWait();

return;

}

// Trying to read product max. If it can not be parsed, the exception is thrown and dialog is shown

try {

prodMax = Integer.parseInt(addProductMax.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with product max error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add product”);

alert.setHeaderText(“Add product error”);

alert.setContentText(“Invalid product max inventory”);

alert.showAndWait();

return;

}

// Trying to read product min. If it can not be parsed, the exception is thrown and dialog is shown

try {

prodMin = Integer.parseInt(addProductMin.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with product min error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add product”);

alert.setHeaderText(“Add product error”);

alert.setContentText(“Invalid product min inventory”);

alert.showAndWait();

return;

}

// If product price is not positive, then the dialog is shown

if (prodPrice <= 0) {

// Creating new dialog window with non-positive product price message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add product”);

alert.setHeaderText(“Add product error”);

alert.setContentText(“Product price must be positive”);

alert.showAndWait();

return;

}

// If product name is empty, then the dialog is shown

if (“”.equals(prodName.trim())) {

// Creating new dialog window with empty name message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add product”);

alert.setHeaderText(“Add product error”);

alert.setContentText(“Product name must not be empty”);

alert.showAndWait();

return;

}

// If max is less than min, then the dialog is shown

if (prodMax < prodMin) {

// Creating new dialog window with illegal max/min message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add product”);

alert.setHeaderText(“Add product error”);

alert.setContentText(“Product max inventory must not be less than min inventory”);

alert.showAndWait();

return;

}

// If product inv is not in range, then the dialog is shown

if ((prodInventory > prodMax) || (prodInventory < prodMin)) {

// Creating new dialog window with illegal product inv message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add product”);

alert.setHeaderText(“Add product error”);

alert.setContentText(“Product inventory must be between min and max”);

alert.showAndWait();

return;

}

// If product has no parts, then the dialog is shown

if (parts.isEmpty()) {

// Creating new dialog window with empty part set message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add product”);

alert.setHeaderText(“Add product error”);

alert.setContentText(“Product must have at least one part”);

alert.showAndWait();

return;

}

// Calculating product parts sum

double sum = 0;

for (Part p : parts) {

sum += p.getPartCost();

}

// If product parts part sum is greater than product price, then the dialog is shown

if (sum > prodPrice) {

// Creating new dialog window with unappropriate product set set message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add product”);

alert.setHeaderText(“Add product error”);

alert.setContentText(“Price of product can not be less than the cost of the parts”);

alert.showAndWait();

return;

}

// Add new product to the inventory

//////////////////////

/* Removed ID argument from constructor call*/

Inventory.addProduct(new Product(prodName, prodInventory, prodPrice, prodMin, prodMax, parts));

//////////////////////

// Add new product to the inventory

Stage stage;

Parent root;

stage = (Stage) addProductSaveBtn.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“MainScreen.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* Handler for add part button in the Add Product Window

* @param event action event

*/

@FXML

void addPartAddHandler(ActionEvent event) {

// Adding selected part to ‘parts’

Part p = addProductAddPartTable.getSelectionModel().getSelectedItem();

parts.add(p);

// Creating empty new list for updated tables

ObservableList<Part> addParts = FXCollections.observableArrayList();

ObservableList<Part> delParts = FXCollections.observableArrayList();

// If part p is not in ‘parts’, then it is available for add table

for (Part pt : Inventory.getAllParts()) {

if (!parts.contains(pt))

addParts.add(pt);

}

// If part p is in ‘parts’, then it is available for del table

for (Part pt : Inventory.getAllParts()) {

if (parts.contains(pt))

delParts.add(pt);

}

// Set updated lists to the tables

addProductAddPartTable.setItems(addParts);

addProductDeletePartTable.setItems(delParts);

}

}

  MainScreenController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.io.IOException;

import java.net.URL;

import java.util.Optional;

import java.util.ResourceBundle;

import javafx.beans.value.ChangeListener;

import javafx.beans.value.ObservableValue;

import javafx.collections.FXCollections;

import javafx.collections.ObservableList;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.FXMLLoader;

import javafx.fxml.Initializable;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.scene.control.Alert;

import javafx.scene.control.Alert.AlertType;

import javafx.scene.control.Button;

import javafx.scene.control.ButtonType;

import javafx.scene.control.TableColumn;

import javafx.scene.control.TableView;

import javafx.scene.control.TextField;

import javafx.scene.control.cell.PropertyValueFactory;

import javafx.stage.Stage;

import robdavidsonims.model.Inventory;

import robdavidsonims.model.Part;

import robdavidsonims.model.Product;

/**

* FXML Controller class

*

* @author Davidson

*/

public class MainScreenController implements Initializable {

// FXML Components

@FXML

private Button mainSearchBtn1;

@FXML

private TextField mainSearchPartTxt;

@FXML

private TableView<Part> mainPartTable;

@FXML

private TableColumn<Part, Integer> mainPartIDColumn;

@FXML

private TableColumn<Part, String> mainPartNameColumn;

@FXML

private TableColumn<Part, Integer> mainInvLevelColumn1;

@FXML

private TableColumn<Part, Double> mainPriCosUnitColumn;

@FXML

private Button mainDelBtn1;

@FXML

private Button mainModBtn1;

@FXML

private Button mainAddBtn1;

@FXML

private Button mainSearchBtn2;

@FXML

private TextField mainSearchProTxt;

@FXML

private TableView<Product> mainProTable;

@FXML

private TableColumn<Product, Integer> mainProIDColumn;

@FXML

private TableColumn<Product, String> mainProNameColumn;

@FXML

private TableColumn<Product, Integer> mainInvLevelColumn2;

@FXML

private TableColumn<Product, Double> mainPriUniColumn;

@FXML

private Button mainModBtn2;

@FXML

private Button mainAddBtn2;

@FXML

private Button mainDelBtn2;

@FXML

private Button mainExit;

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL url, ResourceBundle rb) {

// Setting value factories for each column of part table

mainPartIDColumn.setCellValueFactory(new PropertyValueFactory<>(“partID”));

mainPartNameColumn.setCellValueFactory(new PropertyValueFactory<>(“partName”));

mainInvLevelColumn1.setCellValueFactory(new PropertyValueFactory<>(“partInstock”));

mainPriCosUnitColumn.setCellValueFactory(new PropertyValueFactory<>(“partCost”));

// Adding all parts from the inventory(empty) to the table

mainPartTable.setItems(Inventory.getAllParts());

// Disabling mod button and del button, as the table is empty now (now row is selected)

mainModBtn1.setDisable(true);

mainDelBtn1.setDisable(true);

// Adding row selection listener to the part table

mainPartTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Part>() {

@Override

public void changed(ObservableValue<? extends Part> observable, Part oldValue, Part newValue) {

// If new selection contains no rows, then mod button and del button are disabled

if (newValue == null) {

mainModBtn1.setDisable(true);

mainDelBtn1.setDisable(true);

}

// Otherwise, mod button and del button are enabled

else {

mainModBtn1.setDisable(false);

mainDelBtn1.setDisable(false);

}

}

});

// Setting value factories for each column of product table

mainProIDColumn.setCellValueFactory(new PropertyValueFactory<>(“productID”));

mainProNameColumn.setCellValueFactory(new PropertyValueFactory<>(“productName”));

mainInvLevelColumn2.setCellValueFactory(new PropertyValueFactory<>(“productInstock”));

mainPriUniColumn.setCellValueFactory(new PropertyValueFactory<>(“productCost”));

// Adding all products from the inventory(empty) to the table

mainProTable.setItems(Inventory.getAllProducts());

// Disabling mod button and del button, as the table is empty now (now row is selected)

mainModBtn2.setDisable(true);

mainDelBtn2.setDisable(true);

// Adding row selection listener to the product table

mainProTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Product>() {

@Override

public void changed(ObservableValue<? extends Product> observable, Product oldValue, Product newValue) {

// If new selection contains no rows, then mod button and del button are disabled

if (newValue == null) {

mainModBtn2.setDisable(true);

mainDelBtn2.setDisable(true);

}

// Otherwise, mod button and del button are enabled

else {

mainModBtn2.setDisable(false);

mainDelBtn2.setDisable(false);

}

}

});

}

/**

* Handler for adding part button in the Main Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void mainAddBtn1Handler(ActionEvent event)throws IOException{

Stage stage;

Parent root;

stage=(Stage) mainAddBtn1.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“AddPart.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* Handler for adding product button in the Main Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void mainAddBtn2Handler(ActionEvent event) throws IOException {

Stage stage;

Parent root;

stage=(Stage) mainAddBtn2.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“AddProduct.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* Handler for adding part button in the Main Window

* @param event action event

*/

@FXML

void mainDelBtn1Handler(ActionEvent event) {

// Creating new dialog window deleting question

Alert alert = new Alert(AlertType.CONFIRMATION);

alert.setTitle(“Delete part”);

alert.setHeaderText(“Are you sure, you want to delete selected part?”);

ButtonType yesButton = new ButtonType(“Yes”);

ButtonType noButton = new ButtonType(“No”);

alert.getButtonTypes().setAll(yesButton, noButton);

Optional<ButtonType> result = alert.showAndWait();

// If “Yes” is selected, delete selected part from inventory

if (result.get() == yesButton) {

Part selectedPart = mainPartTable.getSelectionModel().getSelectedItem();

Inventory.deletePart(selectedPart);

mainPartTable.setItems(Inventory.getAllParts());

}

}

/**

* Handler for adding product button in the Main Window

* @param event action event

*/

@FXML

void mainDelBtn2Handler(ActionEvent event) {

// Creating new dialog window with deleting question

Alert alert = new Alert(AlertType.CONFIRMATION);

alert.setTitle(“Delete product”);

alert.setHeaderText(“Are you sure, you want to delete selected product?”);

ButtonType yesButton = new ButtonType(“Yes”);

ButtonType noButton = new ButtonType(“No”);

alert.getButtonTypes().setAll(yesButton, noButton);

Optional<ButtonType> result = alert.showAndWait();

// If “Yes” is selected, delete selected product from inventory

if (result.get() == yesButton) {

Product selectedProduct = mainProTable.getSelectionModel().getSelectedItem();

Inventory.removeProduct(selectedProduct);

mainProTable.setItems(Inventory.getAllProducts());

}

}

/**

* Handler for exit in the Main Window

* @param event action event

*/

@FXML

void mainExitHandler(ActionEvent event) {

// Creating new dialog window with exitting question

Alert alert = new Alert(AlertType.CONFIRMATION);

alert.setTitle(“Exit”);

alert.setHeaderText(“Are you sure, you want to exit application?”);

ButtonType yesButton = new ButtonType(“Yes”);

ButtonType noButton = new ButtonType(“No”);

alert.getButtonTypes().setAll(yesButton, noButton);

Optional<ButtonType> result = alert.showAndWait();

// If “Yes” is selected, finish application

if (result.get() == yesButton) {

Stage stage = (Stage) mainExit.getScene().getWindow();

stage.close();

}

}

/**

* Handler for modifying part button in the Main Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void mainModBtn1Handler(ActionEvent event) throws IOException {

Stage stage;

Parent root;

stage=(Stage) mainModBtn1.getScene().getWindow();

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(“ModifyPart.fxml”));

root = fxmlLoader.load();

ModifyPartController controller = fxmlLoader.<ModifyPartController>getController();

// Setting selected part to the controller

controller.setPart(mainPartTable.getSelectionModel().getSelectedItem());

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* Handler for modifying product button in the Main Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void mainModBtn2Handler(ActionEvent event) throws IOException {

Stage stage;

Parent root;

stage=(Stage) mainModBtn2.getScene().getWindow();

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(“ModifyProduct.fxml”));

root = fxmlLoader.load();

ModifyProductController controller = fxmlLoader.<ModifyProductController>getController();

// Setting selected product to the controller

controller.setProduct(mainProTable.getSelectionModel().getSelectedItem());

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* Handler for search part button in the Main Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void mainSearchBtn1Handler(ActionEvent event) {

// Looking through the list and saving appropriate parts (which start with specified prefix)

// to the foundParts list.

ObservableList<Part> foundParts = FXCollections.observableArrayList();

String prefix = mainSearchPartTxt.getText();

for (Part p : Inventory.getAllParts()) {

if (p.getPartName().startsWith(prefix))

foundParts.add(p);

}

// Set found list to the table

mainPartTable.setItems(foundParts);

}

/**

* Handler for search product button in the Main Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void mainSearchBtn2Handler(ActionEvent event) {

// Looking through the list and saving appropriate products (which start with specified prefix)

// to the foundParts list.

ObservableList<Product> foundProducts = FXCollections.observableArrayList();

String prefix = mainSearchProTxt.getText();

for (Product p : Inventory.getAllProducts()) {

if (p.getProductName().startsWith(prefix))

foundProducts.add(p);

}

// Set found list to the table

mainProTable.setItems(foundProducts);

}

} 

ModifyPartController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.io.IOException;

import java.net.URL;

import java.util.Optional;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.Initializable;

import javafx.fxml.FXML;

import javafx.fxml.FXMLLoader;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.scene.control.Alert;

import javafx.scene.control.Button;

import javafx.scene.control.ButtonType;

import javafx.scene.control.RadioButton;

import javafx.scene.control.TextField;

import javafx.scene.text.Text;

import javafx.stage.Stage;

import robdavidsonims.model.InHousePart;

import robdavidsonims.model.OutsourcedPart;

import robdavidsonims.model.Part;

/**

* FXML Contr * @author Davidson

*/

public class ModifyPartController implements Initializable {

// FXML Components

@FXML

private TextField modPartID;

@FXML

private TextField modPartPrice;

@FXML

private Button modPartSaveBtn;

@FXML

private RadioButton modInHouse;

@FXML

private TextField modPartMax;

@FXML

private RadioButton modOutsourced;

@FXML

private TextField modPartMin;

@FXML

private Button modPartCancelBtn;

@FXML

private TextField modPartInv;

@FXML

private TextField modPartMachine;

@FXML

private TextField modPartName;

@FXML

private Text machCompTxt;

// Part instance, represnting the part, which is being modified now

private Part part;

// Setter method for part field.

// Fills all fields of the form with appropriate values of the part

public void setPart(Part part) {

this.part = part;

modPartID.setText(part.getPartID() + “”);

modPartName.setText(part.getPartName());

modPartInv.setText(part.getPartInstock() + “”);

modPartPrice.setText(part.getPartCost() + “”);

modPartMax.setText(part.getPartMax() + “”);

modPartMin.setText(part.getPartMin() + “”);

if (part instanceof InHousePart) {

modInHouse.setSelected(true);

modPartMachine.setText(((InHousePart) part).getMachineID() + “”);

}

else {

modOutsourced.setSelected(true);

modPartMachine.setText(((OutsourcedPart) part).getCompanyName());

}

// During modification, part type can not be changed

modInHouse.setDisable(true);

modOutsourced.setDisable(true);

}

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL url, ResourceBundle rb) {

modPartID.setEditable(false);

modPartID.setDisable(true);

}

/**

* Handler for cancel in Modify Part Window

* @param event action event

*/

@FXML

void modPartCancelBtnHandler(ActionEvent event) throws IOException{

// Creating new dialog window cancelling question

Alert alert = new Alert(Alert.AlertType.CONFIRMATION);

alert.setTitle(“Modify part”);

alert.setHeaderText(“Are you sure, you want to cancel part modifying?”);

ButtonType yesButton = new ButtonType(“Yes”);

ButtonType noButton = new ButtonType(“No”);

alert.getButtonTypes().setAll(yesButton, noButton);

Optional<ButtonType> result = alert.showAndWait();

// If “Yes” is selected, return to main screen

if (result.get() == yesButton) {

Stage stage;

Parent root;

stage = (Stage) modPartCancelBtn.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“MainScreen.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

}

/**

* Handler for saving new part in Modify Part Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void modPartSaveBtnHandler(ActionEvent event) throws IOException{

// Initializing part fields with default values

String partName = “”;

int partInventory = 0;

double partPrice = 0;

int partMin = 0;

int partMax = 0;

int machineId = 0;

String companyName = “”;

//////////////////////////////////

/*

Here I have deleted ID text field processing

*/

/////////////////////////////////

// Reading part name

partName = modPartName.getText();

// Trying to read part inv. If it can not be parsed, the value is set to 0, and the textfield is set to “0”

try {

partInventory = Integer.parseInt(modPartInv.getText());

}

catch (NumberFormatException nfe) {

// Setting field and textfield to default value 0

partInventory = 0;

modPartInv.setText(“0”);

}

// Trying to read part price. If it can not be parsed, the exception is thrown and dialog is shown

try {

partPrice = Double.parseDouble(modPartPrice.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with part price error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Invalid part price”);

alert.showAndWait();

return;

}

// Trying to read part max. If it can not be parsed, the exception is thrown and dialog is shown

try {

partMax = Integer.parseInt(modPartMax.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with part max error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Invalid part max inventory”);

alert.showAndWait();

return;

}

// Trying to read part min. If it can not be parsed, the exception is thrown and dialog is shown

try {

partMin = Integer.parseInt(modPartMin.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with part min error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Invalid part min inventory”);

alert.showAndWait();

return;

}

if (modInHouse.isSelected()) {

// If part is inHouse part, then trying to parse machine id

// Trying to read machine id. If it can not be parsed, the exception is thrown and dialog is shown

try {

machineId = Integer.parseInt(modPartMachine.getText());

} catch (NumberFormatException nfe) {

// Creating new dialog window with machine id error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Invalid part machine ID”);

alert.showAndWait();

return;

}

}

else {

// If part is outsourced part, then reading company name

// Reading part name

companyName = modPartMachine.getText();

}

// If price is not positive, then the dialog is shown

if (partPrice <= 0) {

// Creating new dialog window with non-positive price message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Part price must be positive”);

alert.showAndWait();

return;

}

// If part name is empty, then the dialog is shown

if (“”.equals(partName.trim())) {

// Creating new dialog window with illegal max/min message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Part name must not be empty”);

alert.showAndWait();

return;

}

// If max is less than min, then the dialog is shown

if (partMax < partMin) {

// Creating new dialog window with illegal max/min message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Part max inventory must not be less than min inventory”);

alert.showAndWait();

return;

}

// If part inv is not in range, then the dialog is shown

if ((partInventory > partMax) || (partInventory < partMin)) {

// Creating new dialog window with illegal part inv message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Add part”);

alert.setHeaderText(“Add part error”);

alert.setContentText(“Part inventory must be between min and max”);

alert.showAndWait();

return;

}

// Setting new values to the part properties

//////////////////////////////////

/*

Here I have deleted ID text field setting

*/

/////////////////////////////////

part.setPartName(partName);

part.setPartInstock(partInventory);

part.setPartCost(partPrice);

part.setPartMax(partMax);

part.setPartMin(partMin);

if (modInHouse.isSelected()) {

((InHousePart)part).setMachineID(machineId);

}

else {

((OutsourcedPart)part).setCompanyName(companyName);

}

// Returning to the main screen

Stage stage;

Parent root;

stage = (Stage) modPartSaveBtn.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“MainScreen.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* InHouse toggle listener

* @param event action event

*/

@FXML

void inHouseHandler(ActionEvent event) {

// Changing machineID/company label, if toggle is changed

machCompTxt.setText(“Machine ID”);

}

/**

* OutSourced toggle listener

* @param event action event

*/

@FXML

void outSourceHandler(ActionEvent event) {

// Changing machineID/company label, if toggle is changed

machCompTxt.setText(“Company Name”);

}

} 

ModifyProductController.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.view_controller;

import java.io.IOException;

import java.net.URL;

import java.util.Optional;

import java.util.ResourceBundle;

import javafx.beans.value.ChangeListener;

import javafx.beans.value.ObservableValue;

import javafx.collections.FXCollections;

import javafx.collections.ObservableList;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.FXMLLoader;

import javafx.fxml.Initializable;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.scene.control.Alert;

import javafx.scene.control.Button;

import javafx.scene.control.ButtonType;

import javafx.scene.control.TableColumn;

import javafx.scene.control.TableView;

import javafx.scene.control.TextField;

import javafx.scene.control.cell.PropertyValueFactory;

import javafx.stage.Stage;

import robdavidsonims.model.Inventory;

import robdavidsonims.model.Part;

import robdavidsonims.model.Product;

/**

* FXML Controller class

*

* @author Davidson

*/

public class ModifyProductController implements Initializable {

// FXML Components

@FXML

private TextField addProductID;

@FXML

private Button addProductDeleteBtn;

@FXML

private TableColumn<Part, Double> addProductAddPartPriceColumn;

@FXML

private Button addProductAddBtn;

@FXML

private TableColumn<Part, String> addProductDeletePartNameColumn;

@FXML

private Button addProductSearchBtn;

@FXML

private TableView<Part> addProductAddPartTable;

@FXML

private TextField addProductMin;

@FXML

private Button addProductSaveBtn;

@FXML

private TextField addProductInv;

@FXML

private TableColumn<Part, Integer> addProductDeletePartIDColumn;

@FXML

private TableColumn<Part, String> addProductAddPartNameColumn;

@FXML

private TableColumn<Part, Integer> addProductAddPartInvColumn;

@FXML

private TextField addProductMax;

@FXML

private TableColumn<Part, Double> addProductDeletePartPriceColumn;

@FXML

private Button addProductCancelBtn;

@FXML

private TableView<Part> addProductDeletePartTable;

@FXML

private TableColumn<Part, Integer> addProductAddPartIDColumn;

@FXML

private TableColumn<Part, Integer> addProductDeletePartInvColumn;

@FXML

private TextField addProductName;

@FXML

private TextField addProductPrice;

@FXML

private TextField addProductSearchTxt;

// Product instance, represnting the product, which is being modified now

private Product product;

// Setter method for product field.

// Fills all fields of the form with appropriate values of the product

public void setProduct(Product product) {

this.product = product;

// Filling in textfields

addProductID.setText(product.getProductID()+ “”);

addProductName.setText(product.getProductName());

addProductInv.setText(product.getProductInstock() + “”);

addProductPrice.setText(product.getProductCost() + “”);

addProductMax.setText(product.getPartMax() + “”);

addProductMin.setText(product.getProductMin() + “”);

// Filling in tables

ObservableList<Part> addParts = FXCollections.observableArrayList();

ObservableList<Part> delParts = FXCollections.observableArrayList();

for (Part pt : Inventory.getAllParts()) {

if (!product.getAssociatedParts().contains(pt))

addParts.add(pt);

}

for (Part pt : Inventory.getAllParts()) {

if (product.getAssociatedParts().contains(pt))

delParts.add(pt);

}

addProductAddPartTable.setItems(addParts);

addProductDeletePartTable.setItems(delParts);

}

/**

* Initializes the controller class.

*/

@Override

public void initialize(URL location, ResourceBundle resources) {

addProductID.setEditable(false);

addProductID.setDisable(true);

// Setting value factories for each column of add part table

addProductAddPartIDColumn.setCellValueFactory(new PropertyValueFactory<>(“partID”));

addProductAddPartNameColumn.setCellValueFactory(new PropertyValueFactory<>(“partName”));

addProductAddPartInvColumn.setCellValueFactory(new PropertyValueFactory<>(“partInstock”));

addProductAddPartPriceColumn.setCellValueFactory(new PropertyValueFactory<>(“partCost”));

// Adding all parts from the inventory(empty) to the table

addProductAddPartTable.setItems(Inventory.getAllParts());

// Disabling add button, as now row is selected

addProductAddBtn.setDisable(true);

// Adding row selection listener to the add part table

addProductAddPartTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Part>() {

@Override

public void changed(ObservableValue<? extends Part> observable, Part oldValue, Part newValue) {

if (newValue == null) {

addProductAddBtn.setDisable(true);

}

else {

addProductAddBtn.setDisable(false);

}

}

});

// Setting value factories for each column of del part table

addProductDeletePartIDColumn.setCellValueFactory(new PropertyValueFactory<>(“partID”));

addProductDeletePartNameColumn.setCellValueFactory(new PropertyValueFactory<>(“partName”));

addProductDeletePartInvColumn.setCellValueFactory(new PropertyValueFactory<>(“partInstock”));

addProductDeletePartPriceColumn.setCellValueFactory(new PropertyValueFactory<>(“partCost”));

// Adding all parts from the inventory(empty) to the table

addProductDeleteBtn.setDisable(true);

// Adding row selection listener to the del part table

addProductDeletePartTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Part>() {

@Override

public void changed(ObservableValue<? extends Part> observable, Part oldValue, Part newValue) {

// If new selection contains no rows, then del button is disabled

if (newValue == null) {

addProductDeleteBtn.setDisable(true);

}

// Otherwise, del button is enabled

else {

addProductDeleteBtn.setDisable(false);

}

}

});

}

/**

* Handler for search part button in the Modify Product Window

* @param event action event

*/

@FXML

void addProductSearchBtnHandler(ActionEvent event) {

// Get input name prefix

String prefix = addProductSearchTxt.getText();

// Creating empty new list for updated tables

ObservableList<Part> addParts = FXCollections.observableArrayList();

ObservableList<Part> delParts = FXCollections.observableArrayList();

// If part p is not in ‘parts’ and matches prefix, then it is available for add table

for (Part p : Inventory.getAllParts()) {

if (product.getAssociatedParts().contains(p))

continue;

if (p.getPartName().startsWith(prefix))

addParts.add(p);

}

// If part p is in ‘parts’ and matches prefix, then it is available for del table

for (Part p : Inventory.getAllParts()) {

if ((product.getAssociatedParts().contains(p)) && (p.getPartName().startsWith(prefix)))

delParts.add(p);

}

// Set updated lists to the tables

addProductAddPartTable.setItems(addParts);

addProductDeletePartTable.setItems(delParts);

}

/**

* Handler for del part button in the Modify Product Window

* @param event action event

*/

@FXML

void addProductDeleteBtnHandler(ActionEvent event) {

// Removing selected part from ‘parts’

Part p = addProductDeletePartTable.getSelectionModel().getSelectedItem();

product.getAssociatedParts().remove(p);

// Creating empty new list for updated tables

ObservableList<Part> addParts = FXCollections.observableArrayList();

ObservableList<Part> delParts = FXCollections.observableArrayList();

// If part p is not in ‘parts’, then it is available for add table

for (Part pt : Inventory.getAllParts()) {

if (!product.getAssociatedParts().contains(pt))

addParts.add(pt);

}

// If part p is in ‘parts’, then it is available for del table

for (Part pt : Inventory.getAllParts()) {

if (product.getAssociatedParts().contains(pt))

delParts.add(pt);

}

// Set updated lists to the tables

addProductAddPartTable.setItems(addParts);

addProductDeletePartTable.setItems(delParts);

}

/**

* Handler for cancel in Modify Product Window

* @param event action event

*/

@FXML

void addProductCancelBtn(ActionEvent event) throws IOException{

// Creating new dialog window with cancelling question

Alert alert = new Alert(Alert.AlertType.CONFIRMATION);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Are you sure, you want to cancel product modifying?”);

ButtonType yesButton = new ButtonType(“Yes”);

ButtonType noButton = new ButtonType(“No”);

alert.getButtonTypes().setAll(yesButton, noButton);

Optional<ButtonType> result = alert.showAndWait();

// If “Yes” is selected, return to main screen

if (result.get() == yesButton) {

Stage stage;

Parent root;

stage = (Stage) addProductCancelBtn.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“MainScreen.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

}

/**

* Handler for saving new product in Modify Product Window

* @param event action event

* @throws IOException, if cannot open specified fxml file

*/

@FXML

void addProductSaveBtnHandler(ActionEvent event) throws IOException{

// Initializing part fields with default values

String prodName = “”;

int prodInventory = 0;

double prodPrice = 0;

int prodMin = 0;

int prodMax = 0;

//////////////////////////////////

/*

Here I have deleted ID text field processing

*/

/////////////////////////////////

// Reading product name

prodName = addProductName.getText();

// Trying to read product inv. If it can not be parsed, the value is set to 0, and the textfield is set to “0”

try {

prodInventory = Integer.parseInt(addProductInv.getText());

}

catch (NumberFormatException nfe) {

// Setting field and textfield to default value 0

prodInventory = 0;

addProductInv.setText(“0”);

}

// Trying to read product price. If it can not be parsed, the exception is thrown and dialog is shown

try {

prodPrice = Double.parseDouble(addProductPrice.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with product price error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Modify product error”);

alert.setContentText(“Invalid product price”);

alert.showAndWait();

return;

}

// Trying to read product max. If it can not be parsed, the exception is thrown and dialog is shown

try {

prodMax = Integer.parseInt(addProductMax.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with product max error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Modify product error”);

alert.setContentText(“Invalid product max inventory”);

alert.showAndWait();

return;

}

// Trying to read product min. If it can not be parsed, the exception is thrown and dialog is shown

try {

prodMin = Integer.parseInt(addProductMin.getText());

}

catch (NumberFormatException nfe) {

// Creating new dialog window with product min error message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Modify product error”);

alert.setContentText(“Invalid product min inventory”);

alert.showAndWait();

return;

}

// If product price is not positive, then the dialog is shown

if (prodPrice <= 0) {

// Creating new dialog window with non-positive product price message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Modify product error”);

alert.setContentText(“Product price must be positive”);

alert.showAndWait();

return;

}

// If product name is empty, then the dialog is shown

if (“”.equals(prodName.trim())) {

// Creating new dialog window with empty name message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Modify product error”);

alert.setContentText(“Product name must not be empty”);

alert.showAndWait();

return;

}

// If max is less than min, then the dialog is shown

if (prodMax < prodMin) {

// Creating new dialog window with illegal max/min message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Modify product error”);

alert.setContentText(“Product max inventory must not be less than min inventory”);

alert.showAndWait();

return;

}

// If product inv is not in range, then the dialog is shown

if ((prodInventory > prodMax) || (prodInventory < prodMin)) {

// Creating new dialog window with illegal product inv message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Modify product error”);

alert.setContentText(“Product inventory must be between min and max”);

alert.showAndWait();

return;

}

// If product has no parts, then the dialog is shown

if (product.getAssociatedParts().isEmpty()) {

// Creating new dialog window with empty part set message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Modify product error”);

alert.setContentText(“Product must have at least one part”);

alert.showAndWait();

return;

}

// Calculating product parts sum

double sum = 0;

for (Part p : product.getAssociatedParts()) {

sum += p.getPartCost();

}

// If product parts part sum is greater than product price, then the dialog is shown

if (sum > prodPrice) {

// Creating new dialog window with unappropriate product set set message

Alert alert = new Alert(Alert.AlertType.ERROR);

alert.setTitle(“Modify product”);

alert.setHeaderText(“Modify product error”);

alert.setContentText(“Price of product can not be less than the cost of the parts”);

alert.showAndWait();

return;

}

// Setting new values to the product properties

//////////////////////////////////

/*

Here I have deleted ID text field setting

*/

/////////////////////////////////

product.setProductName(prodName);

product.setProductInstock(prodInventory);

product.setProductCost(prodPrice);

product.setPartMax(prodMax);

product.setProductMin(prodMin);

// Add new product to the inventory

Stage stage;

Parent root;

stage = (Stage) addProductSaveBtn.getScene().getWindow();

root = FXMLLoader.load(getClass().getResource(“MainScreen.fxml”));

Scene scene = new Scene(root);

stage.setScene(scene);

stage.show();

}

/**

* Handler for add part button in the Modify Product Window

* @param event action event

*/

@FXML

void addPartAddHandler(ActionEvent event) {

// Adding selected part to ‘parts’

Part p = addProductAddPartTable.getSelectionModel().getSelectedItem();

product.getAssociatedParts().add(p);

// Creating empty new list for updated tables

ObservableList<Part> addParts = FXCollections.observableArrayList();

ObservableList<Part> delParts = FXCollections.observableArrayList();

// If part p is not in ‘parts’, then it is available for add table

for (Part pt : Inventory.getAllParts()) {

if (!product.getAssociatedParts().contains(pt))

addParts.add(pt);

}

// If part p is in ‘parts’, then it is available for del table

for (Part pt : Inventory.getAllParts()) {

if (product.getAssociatedParts().contains(pt))

delParts.add(pt);

}

// Set updated lists to the tables

addProductAddPartTable.setItems(addParts);

addProductDeletePartTable.setItems(delParts);

}

}

InHousePart.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.beans.property.IntegerProperty;

import javafx.beans.property.SimpleIntegerProperty;

/**

*

* @author Davidson

*/

public class InHousePart extends Part{

private final IntegerProperty machineID;

//////////////////////

/* Removed ID argument from constructor call*/

public InHousePart (String Name, int Instock, Double Cost, int Min, int Max, int MacID) {

//////////////////////

/* Removed ID argument from constructor call*/

super(Name, Instock, Cost, Min, Max);

/////////////////////

this.machineID=new SimpleIntegerProperty(MacID);

}

//Getter

public int getMachineID() {

return machineID.get();

}

//Setter

public void setMachineID(int ID) {

this.machineID.set(ID);

}

//Property

public IntegerProperty MachineIDProperty() {

return machineID;

}

}

  Inventory.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.collections.FXCollections;

import javafx.collections.ObservableList;

/**

*

* @author Davidson

*/

public class Inventory {

private static ObservableList<Part> allParts=FXCollections.observableArrayList();

private static ObservableList<Product> products=FXCollections.observableArrayList();

public static ObservableList<Part> getAllParts() {

return allParts;

}

public static ObservableList<Product> getAllProducts() {

return products;

}

public static void setAllParts(ObservableList<Part> parts) {

allParts=parts;

}

public static void addProduct(Product p) {

//functionality is handled in the add product controller

products.add (p);

}

public static boolean removeProduct (Product p) {

return products.remove(p);

}

public static Product lookupProduct (int i) {

return products.get(i);

}

//public static updateProduct (int i){ } This functionality is handled in the ModifyProductController.

public static void addPart (Part p) {

allParts.add (p);

}

public static boolean deletePart (Part p) {

return allParts.remove(p);

}

} 

OutsourcedPart.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.beans.property.StringProperty;

import javafx.beans.property.SimpleStringProperty;

/**

*

* @author Davidson

*/

public class OutsourcedPart extends Part {

private final StringProperty companyName;

//////////////////////

/* Removed ID argument from constructor call*/

public OutsourcedPart (String Name, int Instock, Double Cost, int Min, int Max, String CompName) {

//////////////////////

/* Removed ID argument from constructor call*/

super(Name, Instock, Cost, Min, Max);

/////////////////////

this.companyName=new SimpleStringProperty(CompName);

}

//Getter

public String getCompanyName() {

return companyName.get();

}

//Setter

public void setCompanyName(String Name) {

this.companyName.set(Name);

}

//Property

public StringProperty CompanyNameProperty() {

return companyName;

}

} 

Part.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.beans.property.DoubleProperty;

import javafx.beans.property.IntegerProperty;

import javafx.beans.property.SimpleDoubleProperty;

import javafx.beans.property.SimpleIntegerProperty;

import javafx.beans.property.SimpleStringProperty;

import javafx.beans.property.StringProperty;

/**

*

* @author Davidson

*/

public abstract class Part {

//////////////////////////

/* Static ID counter for all creaed parts*/

public static int IDCounter = 1;

//////////////////////////

private final IntegerProperty partID;

private final StringProperty partName;

private final IntegerProperty partInstock;

private final DoubleProperty partCost;

private final IntegerProperty partMin;

private final IntegerProperty partMax;

//Default constructor

public Part() {

//////////////////////

/* Removed ID argument from constructor call*/

this(null, 0, 0.0, 0, 0);

//////////////////////

}

//Constructor with initial data

public Part (String Name, int Instock, Double Cost, int Min, int Max) {

///////////////////////

/* Increasing parts counter and seting new ID to new part*/

this.partID=new SimpleIntegerProperty(IDCounter);

IDCounter++;

///////////////////////

this.partName=new SimpleStringProperty(Name);

this.partInstock=new SimpleIntegerProperty(Instock);

this.partCost=new SimpleDoubleProperty(Cost);

this.partMin=new SimpleIntegerProperty(Min);

this.partMax=new SimpleIntegerProperty(Max);

}

//Getters Setters and Returning Properties

//Getter

public int getPartID() {

return partID.get();

}

//Setter

public void setPartID(int ID) {

this.partID.set(ID);

}

//Property

public IntegerProperty PartIDProperty() {

return partID;

}

//Getter

public String getPartName() {

return partName.get();

}

//Setter

public void setPartName(String Name) {

this.partName.set(Name);

}

//Property

public StringProperty PartNameProperty() {

return partName;

}

//Getter

public int getPartInstock() {

return partInstock.get();

}

//Setter

public void setPartInstock(int Instock) {

this.partInstock.set(Instock);

}

//Property

public IntegerProperty PartInstockProperty() {

return partInstock;

}

//Getter

public double getPartCost() {

return partCost.get();

}

//Setter

public void setPartCost(double Cost) {

this.partCost.set(Cost);

}

//Property

public DoubleProperty PartCostProperty() {

return partCost;

}

//Getter

public int getPartMin() {

return partMin.get();

}

//Setter

public void setPartMin(int Min) {

this.partMin.set(Min);

}

//Property

public IntegerProperty PartMinProperty() {

return partMin;

}

//Getter

public int getPartMax() {

return partMax.get();

}

//Setter

public void setPartMax(int Max) {

this.partMax.set(Max);

}

//Property

public IntegerProperty PartMaxProperty() {

return partMax;

}

}

 Product.java 

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package robdavidsonims.model;

import javafx.beans.property.DoubleProperty;

import javafx.beans.property.IntegerProperty;

import javafx.beans.property.SimpleDoubleProperty;

import javafx.beans.property.SimpleIntegerProperty;

import javafx.beans.property.SimpleStringProperty;

import javafx.beans.property.StringProperty;

import javafx.collections.FXCollections;

import javafx.collections.ObservableList;

/**

*

* @author Davidson

*/

public class Product {

//////////////////////////

/* Static ID counter for all creaed products*/

public static int IDCounter = 1;

//////////////////////////

private final IntegerProperty productID;

private final StringProperty productName;

private final IntegerProperty productInstock;

private final DoubleProperty productCost;

private final IntegerProperty productMin;

private final IntegerProperty productMax;

private ObservableList<Part> associatedParts=FXCollections.observableArrayList();

//Default constructor

public Product() {

//////////////////////

/* Removed ID argument from constructor call*/

this(null, 0, 0.0, 0, 0,null);

//////////////////////

}

//Constructor with initial data

public Product (String Name, int Instock, Double Cost, int Min, int Max, ObservableList<Part> ap) {

///////////////////////

/* Increasing parts counter and seting new ID to new part*/

this.productID=new SimpleIntegerProperty(IDCounter);

IDCounter++;

///////////////////////

this.productName=new SimpleStringProperty(Name);

this.productInstock=new SimpleIntegerProperty(Instock);

this.productCost=new SimpleDoubleProperty(Cost);

this.productMin=new SimpleIntegerProperty(Min);

this.productMax=new SimpleIntegerProperty(Max);

if(ap!=null)this.associatedParts=ap;

}

//Getters Setters and Returning Properties

//Getter

public int getProductID() {

return productID.get();

}

//Setter

public void setProductID(int ID) {

this.productID.set(ID);

}

//Property

public IntegerProperty ProductIDProperty() {

return productID;

}

//Getter

public String getProductName() {

return productName.get();

}

//Setter

public void setProductName(String Name) {

this.productName.set(Name);

}

//Property

public StringProperty ProductNameProperty() {

return productName;

}

//Getter

public int getProductInstock() {

return productInstock.get();

}

//Setter

public void setProductInstock(int Instock) {

this.productInstock.set(Instock);

}

//Property

public IntegerProperty ProductInstockProperty() {

return productInstock;

}

//Getter

public double getProductCost() {

return productCost.get();

}

//Setter

public void setProductCost(double Cost) {

this.productCost.set(Cost);

}

//Property

public DoubleProperty ProductCostProperty() {

return productCost;

}

//Getter

public int getProductMin() {

return productMin.get();

}

//Setter

public void setProductMin(int Min) {

this.productMin.set(Min);

}

//Property

public IntegerProperty PartMinProperty() {

return productMin;

}

//Getter

public int getPartMax() {

return productMax.get();

}

//Setter

public void setPartMax(int Max) {

this.productMax.set(Max);

}

//Property

public IntegerProperty PartMaxProperty() {

return productMax;

}

//Getter

public ObservableList<Part> getAssociatedParts() {

return associatedParts;

}

//Setter

public void setAssociatedParts(ObservableList<Part> parts) {

associatedParts=parts;

}

}