Package com.esprit.controllers.products
Class ShoppingCartProductControllers
java.lang.Object
com.esprit.controllers.products.ShoppingCartProductControllers
- All Implemented Interfaces:
javafx.fxml.Initializable
JavaFX controller class for the RAKCHA application. Handles UI interactions
and manages view logic using FXML.
- Since:
- 1.0.0
- Version:
- 1.0.0
- Author:
- RAKCHA Team
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate javafx.scene.layout.FlowPane
private static final Logger
(package private) Order
private double
private javafx.scene.layout.FlowPane
private org.kordamp.ikonli.javafx.FontIcon
(package private) ShoppingCart
(package private) ShoppingCartService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
afficherProduct
(javafx.scene.input.MouseEvent mouseEvent) Loads an FXML file and displays it in a new stage, blocking the current stage and setting the new stage as the owner.(package private) void
cinemaclient
(javafx.event.ActionEvent event) Loads a new user interface, creates a new stage and attaches it to the existing stage, replacing the original interface, and finally closes the original stage.private javafx.scene.control.Label
createPrixTotalLabel
(double prixTotal) /** Creates a new Label element with the total price displayed as a double value, using the specified font size, position, and styling options.private javafx.scene.layout.VBox
createProductVBox
(ShoppingCart ShoppingCart) Generates a `VBox` container for each product in the shopping cart, with buttons to decrease or increase the quantity and a label to display the total price.private void
decreaseQuantity
(javafx.scene.control.TextField quantityTextField, ShoppingCart shoppingcart) Decreases the quantity of items in a shopping cart by one unit when the user types a negative value into a text field.(package private) void
eventClient
(javafx.event.ActionEvent event) Loads a new UI fragment (`AffichageEvenementClient.fxml`) and replaces the current scene with it, creating a new stage and closing the original one.private void
increaseQuantity
(javafx.scene.control.TextField quantityTextField, ShoppingCart shoppingcart) Increases the quantity of an item in a shopping cart by 1, checking if the stock is available and displaying an alert if it's not.void
initialize
(URL url, ResourceBundle resourceBundle) /** Triggers a task to be executed on the EDT (Event Dispatch Thread) by calling `Platform.runLater`.private boolean
isStockAvailable
(Product produit, int quantity) Compares the requested quantity with the available quantity of stock for a given product and returns true if there is enough stock, otherwise false.private void
Retrieves a list of products from a service, verifies if each product has already been added to the cart, and adds it to the cart if not.(package private) void
MovieClient
(javafx.event.ActionEvent event) Loads a new FXML interface using `FXMLLoader`, creates a new scene and stage, and replaces the current stage with the new one, closing the previous stage.(package private) void
order
(javafx.event.ActionEvent event) Loads a FXML file named `/OrderClient.fxml` into a Stage, initializes a `OrderClientController`, and displays the scene on the Stage.void
Paiment
(javafx.scene.input.MouseEvent event) Is a handling function for mouse events.private double
prixProduct
(Long idProduct, int quantity) Calculates the total price of a product based on its ID and quantity by multiplying the unitaire price fetched from the `ProductService`.(package private) void
produitClient
(javafx.event.ActionEvent event) Loads a new FXML interface, creates a new scene and stage, and replaces the current stage with the new one, closing the old stage upon execution.(package private) void
profilclient
(javafx.event.ActionEvent event) Is expected to perform some actions or calculations upon receiving an event call.private void
Clears the current elements from the shopping cart, reloads the accepted items, and updates the total price.(package private) void
SerieClient
(javafx.event.ActionEvent event) Charges a new FXML file, creates a new scene, and attaches it to a new stage.private void
Updates the total price label based on the items in a given order by multiplying the product prices by their quantities and storing the result in a shared data instance, then adding it to the flow pane with a created label.
-
Field Details
-
LOGGER
-
produitVBoxMap
-
order
Order order -
shoppingcartService
ShoppingCartService shoppingcartService -
shoppingcart
ShoppingCart shoppingcart -
cartFlowPane
private javafx.scene.layout.FlowPane cartFlowPane -
prixtotaleFlowPane
private javafx.scene.layout.FlowPane prixtotaleFlowPane -
prixTotal
private double prixTotal -
retour
private org.kordamp.ikonli.javafx.FontIcon retour
-
-
Constructor Details
-
ShoppingCartProductControllers
public ShoppingCartProductControllers()
-
-
Method Details
-
initialize
/** Triggers a task to be executed on the EDT (Event Dispatch Thread) by calling `Platform.runLater`. The task is an anonymous inner class that calls the method `loadAcceptedShoppingCart`.- Specified by:
initialize
in interfacejavafx.fxml.Initializable
- Parameters:
url
- URL of the application that requires initialization, and is passed to the `runLater()` method for further processing.resourceBundle
- resource bundle that provides localized data for the platform, and is used to load the accepted shoppingcart in the run method.
-
loadAcceptedShoppingCart
private void loadAcceptedShoppingCart()Retrieves a list of products from a service, verifies if each product has already been added to the cart, and adds it to the cart if not. It also marks the product as added in a map for future reference. -
createPrixTotalLabel
private javafx.scene.control.Label createPrixTotalLabel(double prixTotal) /** Creates a new Label element with the total price displayed as a double value, using the specified font size, position, and styling options.- Parameters:
prixTotal
- total price of the product, which is used to create and set the label's text value.
-
createProductVBox
Generates a `VBox` container for each product in the shopping cart, with buttons to decrease or increase the quantity and a label to display the total price. It also provides delete confirmation pop-up for removing items from the cart.- Parameters:
ShoppingCart
- shoppingcart object that contains the details of the products, quantities, and total price, which are used to populate the UI elements in the `generateProductCard()` function.
-
refreshUI
private void refreshUI()Clears the current elements from the shopping cart, reloads the accepted items, and updates the total price. -
decreaseQuantity
private void decreaseQuantity(javafx.scene.control.TextField quantityTextField, ShoppingCart shoppingcart) Decreases the quantity of items in a shopping cart by one unit when the user types a negative value into a text field. The updated quantity is then saved in the shoppingcart object and reflected in the cart's total quantity.- Parameters:
quantityTextField
- quantity to be decreased, which is obtained from the text field of the same name.shoppingcart
- ShoppingCart object whose quantity is being updated by the function.
-
isStockAvailable
Compares the requested quantity with the available quantity of stock for a given product and returns true if there is enough stock, otherwise false.- Parameters:
produit
- product for which the availability of stock is being checked.quantity
- amount of units of the product that are required or desired by the user, which is compared with the available stock quantity to determine if the product is available for purchase.
-
increaseQuantity
private void increaseQuantity(javafx.scene.control.TextField quantityTextField, ShoppingCart shoppingcart) Increases the quantity of an item in a shopping cart by 1, checking if the stock is available and displaying an alert if it's not.- Parameters:
quantityTextField
- quantity of the product to be updated in the shoppingcart, as indicated by its name.shoppingcart
- containing the products that the user wishes to increase the quantity of.
-
updatePrixTotal
private void updatePrixTotal()Updates the total price label based on the items in a given order by multiplying the product prices by their quantities and storing the result in a shared data instance, then adding it to the flow pane with a created label. -
prixProduct
Calculates the total price of a product based on its ID and quantity by multiplying the unitaire price fetched from the `ProductService`.- Parameters:
idProduct
- ID of the product for which the price is being calculated.quantity
- number of units of the product to be priced, which is multiplied by the unit price returned by the `ProductService` to compute the total price.
-
order
void order(javafx.event.ActionEvent event) Loads a FXML file named `/OrderClient.fxml` into a Stage, initializes a `OrderClientController`, and displays the scene on the Stage.- Parameters:
event
- order action event that triggered the function, providing the necessary context for the code to operate properly.
-
Paiment
public void Paiment(javafx.scene.input.MouseEvent event) Is a handling function for mouse events. It does not perform any specific action or have any distinctive features beyond processing mouse input.- Parameters:
event
- mouse event that triggered the execution of the `Paiment()` function.
-
cinemaclient
void cinemaclient(javafx.event.ActionEvent event) Loads a new user interface, creates a new stage and attaches it to the existing stage, replacing the original interface, and finally closes the original stage.- Parameters:
event
- ActionEvent object that triggered the `cinemaclient` method, providing the necessary information to update the FXML layout of the stage.
-
eventClient
void eventClient(javafx.event.ActionEvent event) Loads a new UI fragment (`AffichageEvenementClient.fxml`) and replaces the current scene with it, creating a new stage and closing the original one.- Parameters:
event
- event object that triggered the function, providing information about the event, such as its source and details, which can be used to handle the event appropriately.
-
produitClient
void produitClient(javafx.event.ActionEvent event) Loads a new FXML interface, creates a new scene and stage, and replaces the current stage with the new one, closing the old stage upon execution.- Parameters:
event
- ActionEvent that triggers the function and provides access to information about the action that was performed, such as the source of the event and the stage where the action occurred.
-
profilclient
void profilclient(javafx.event.ActionEvent event) Is expected to perform some actions or calculations upon receiving an event call.- Parameters:
event
- triggered event that initiated the call to the `profilclient` function.
-
MovieClient
void MovieClient(javafx.event.ActionEvent event) Loads a new FXML interface using `FXMLLoader`, creates a new scene and stage, and replaces the current stage with the new one, closing the previous stage.- Parameters:
event
- ActionEvent object that triggered the function execution, providing access to information about the event such as its source and target.
-
SerieClient
void SerieClient(javafx.event.ActionEvent event) Charges a new FXML file, creates a new scene, and attaches it to a new stage. It also closes the current stage and shows the new stage.- Parameters:
event
- ActionEvent that triggers the `SerieClient()` method and provides information about the source of the event.
-
afficherProduct
public void afficherProduct(javafx.scene.input.MouseEvent mouseEvent) Loads an FXML file and displays it in a new stage, blocking the current stage and setting the new stage as the owner.- Parameters:
mouseEvent
- mouse event that triggered the execution of the `afficherProduct()` method.
-