Class CategoryController

java.lang.Object
com.esprit.controllers.films.CategoryController

public class CategoryController extends Object
Is responsible for handling user interactions with the category table. It provides a setupCellFactory method to set up cell factories for each column in the table, including id, nom, and description. The setupCellValueFactory method sets the cell value factory for each column, and the setupCellOnEditCommit method sets the on edit commit event handler for each column. These methods work together to handle user input and updates to the category table.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private javafx.scene.control.Button
     
    private javafx.scene.layout.AnchorPane
     
    private javafx.scene.control.TableColumn<Category,javafx.scene.control.Button>
     
    private javafx.scene.control.TextArea
     
    private javafx.scene.control.TableColumn<Category,String>
     
    private javafx.scene.control.TableView<Category>
     
    private javafx.scene.control.ComboBox<String>
     
    private javafx.scene.control.TableColumn<Category,Integer>
     
    private static final Logger
     
    private javafx.scene.control.TableColumn<Category,String>
     
    private javafx.scene.control.TextArea
     
    private javafx.scene.control.TextField
     
    private javafx.scene.layout.StackPane
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    Deletes a category with the given ID using `CategoryService`.
    (package private) void
    Adds a new column to a table, makes the table editable, sets up cell factories, value factories, and on-edit commit listeners.
    (package private) void
    insertCategory(javafx.event.ActionEvent event)
    Allows the user to create a new category by filling in a form with the category name and description, then calls the `create()` method of a `CategoryService` class to insert the category into the database, displays an alert message confirming the operation, and then refreshes the table displaying the categories.
    (package private) void
    Retrieves a list of categories from a service and populates a table with them.
    private void
    search(String keyword)
    Filters and displays a list of categories based on a search query provided as an argument.
    private void
    Sets cell factories for three table columns, `idCategory_tableColumn`, `nomCategory_tableColumn`, and `descrptionCategory_tableColumn`.
    private void
    Sets cell edit events for two columns of a table to update the corresponding fields of a `Category` object when committed.
    private void
    Sets cell values for four table columns in a category list by creating property value factories that return the id, description, nom, and delete buttons for each category respectively.
    void
    switchForm(javafx.event.ActionEvent event)
    Sets the visibility of an interface based on the source of the event.
    (package private) void
    Updates a specified category using the `CategoryService`, displays an alert to confirm the update, and then calls the `readCategoryTable()` function to refresh the category table.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • descriptionCategory_textArea

      private javafx.scene.control.TextArea descriptionCategory_textArea
    • nomCategory_textArea

      private javafx.scene.control.TextArea nomCategory_textArea
    • filmCategory_tableView

      private javafx.scene.control.TableView<Category> filmCategory_tableView
    • nomCategory_tableColumn

      private javafx.scene.control.TableColumn<Category,String> nomCategory_tableColumn
    • descrptionCategory_tableColumn

      private javafx.scene.control.TableColumn<Category,String> descrptionCategory_tableColumn
    • idCategory_tableColumn

      private javafx.scene.control.TableColumn<Category,Integer> idCategory_tableColumn
    • delete_tableColumn

      private javafx.scene.control.TableColumn<Category,javafx.scene.control.Button> delete_tableColumn
    • categoryCrudInterface

      private javafx.scene.layout.AnchorPane categoryCrudInterface
    • filterCriteriaComboBox

      private javafx.scene.control.ComboBox<String> filterCriteriaComboBox
    • stackPane

      private javafx.scene.layout.StackPane stackPane
    • AjouterCategory_Button

      private javafx.scene.control.Button AjouterCategory_Button
    • recherche_textField

      private javafx.scene.control.TextField recherche_textField
  • Constructor Details

    • CategoryController

      public CategoryController()
  • Method Details

    • initialize

      void initialize()
      Adds a new column to a table, makes the table editable, sets up cell factories, value factories, and on-edit commit listeners. It also reads data from a category table and provides initial values for a filter criteria combobox.
    • search

      private void search(String keyword)
      Filters and displays a list of categories based on a search query provided as an argument.
      Parameters:
      keyword - search query used to filter and display only relevant categories in the `filmCategory_tableView`.
    • insertCategory

      void insertCategory(javafx.event.ActionEvent event)
      Allows the user to create a new category by filling in a form with the category name and description, then calls the `create()` method of a `CategoryService` class to insert the category into the database, displays an alert message confirming the operation, and then refreshes the table displaying the categories.
      Parameters:
      event - user-generated action that triggered the function execution, allowing the code to respond accordingly.

      Event type: `ActionEvent` Target object: `nomCategory_textArea` and `descriptionCategory_textArea` Context: Callback function for button press

    • readCategoryTable

      void readCategoryTable()
      Retrieves a list of categories from a service and populates a table with them.
    • switchForm

      public void switchForm(javafx.event.ActionEvent event)
      Sets the visibility of an interface based on the source of the event.
      Parameters:
      event - ActionEvent object that triggered the method, providing information about the source of the event and its state.
    • deleteCategory

      void deleteCategory(Long id)
      Deletes a category with the given ID using `CategoryService`. If successful, it displays an alert message and updates the category table.
      Parameters:
      id - identity of the category to be deleted.
    • updateCategory

      void updateCategory(Category category)
      Updates a specified category using the `CategoryService`, displays an alert to confirm the update, and then calls the `readCategoryTable()` function to refresh the category table.
      Parameters:
      category - category object to be updated.

      - `Category category`: Represents a single category to be updated. Its main properties include its name and any relevant subcategories.

    • setupCellFactory

      private void setupCellFactory()
      Sets cell factories for three table columns, `idCategory_tableColumn`, `nomCategory_tableColumn`, and `descrptionCategory_tableColumn`. These factories create custom TableCells that display a text field with an error message when the user types invalid input.
    • setupCellValueFactory

      private void setupCellValueFactory()
      Sets cell values for four table columns in a category list by creating property value factories that return the id, description, nom, and delete buttons for each category respectively.
    • setupCellOnEditCommit

      private void setupCellOnEditCommit()
      Sets cell edit events for two columns of a table to update the corresponding fields of a `Category` object when committed.