Class GeneralManager

java.lang.Object
org.troy.capstone.managers.GeneralManager

public class GeneralManager extends Object
The GeneralManager class is responsible for managing the UI elements, the search engine, and the recently viewed content. It provides methods to interact with the UI elements, retrieve search data, and perform search operations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final ItemRepo
    The ItemRepo containing all items, used by the SearchEngine for filtering and searching and by the RecentlyViewedManager for retrieving items.
    private boolean
    A flag to track whether the RecentlyViewedManager has been created.
    private final SearchEngine
    The SearchEngine instance for performing search operations.
    private boolean
    A flag to track whether the SimilarItemsManager has been created.
    private final Table
    The original Table containing the items, used for retrieving items by index.
    private final UIElementManager
    The UIElementManager instance for managing UI elements.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GeneralManager(Table table, ItemRepo itemRepo)
    Constructor for GeneralManager, filled from a Table.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a UI element to the UIElementManager, and creates the RecentlyViewedManager if the necessary UI elements are present and it has not already been created.
    Gets the button from the UIElementManager.
    Gets the search data from the UIElementManager.
    Gets a UI element from the UIElementManager based on the provided key.
    (package private) boolean
    Checks if the necessary UI elements for creating the RecentlyViewedManager (SearchedItemPagination and RecentlyViewedWindow) are present in the UIElementManager.
    (package private) boolean
    Checks if the necessary UI elements for creating the SimilarItemsManager (SearchedItemPagination and SimilarItemsContainer) are present in the UIElementManager.
    void
    Gets a UI element from the UIElementManager, filters data, sorts it, and updates the UI with the filtered results.
    void
    setButton(Button button)
    Sets the button in the UIElementManager and assigns an action to it that filters the search results and updates the UI when clicked.

    Methods inherited from class Object

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

    • uiManager

      private final UIElementManager uiManager
      The UIElementManager instance for managing UI elements.
    • searchEngine

      private final SearchEngine searchEngine
      The SearchEngine instance for performing search operations.
    • itemRepo

      private final ItemRepo itemRepo
      The ItemRepo containing all items, used by the SearchEngine for filtering and searching and by the RecentlyViewedManager for retrieving items.
    • table

      private final Table table
      The original Table containing the items, used for retrieving items by index.
    • recentlyViewedManagerCreated

      private boolean recentlyViewedManagerCreated
      A flag to track whether the RecentlyViewedManager has been created. Used to prevent duplicate creation.
    • similarItemsManagerCreated

      private boolean similarItemsManagerCreated
      A flag to track whether the SimilarItemsManager has been created. Used to prevent duplicate creation.
  • Constructor Details

    • GeneralManager

      public GeneralManager(Table table, ItemRepo itemRepo)
      Constructor for GeneralManager, filled from a Table.
      Parameters:
      table - The Table containing the item data to be used by the SearchEngine.
      itemRepo - The ItemRepo containing all items, used by the SearchEngine for filtering and searching and by the RecentlyViewedManager for retrieving items.
  • Method Details

    • getUIElement

      public Optional<Node> getUIElement(UIElementName key)
      Gets a UI element from the UIElementManager based on the provided key.
      Parameters:
      key - The key representing the UI element to retrieve.
      Returns:
      An Optional containing the UI element if found, or an empty Optional if not found.
      Preconditions:
      key is not null.
    • getSearchData

      public Map<UIDataName, Object> getSearchData()
      Gets the search data from the UIElementManager.
      Returns:
      The search data containing the filters to be applied.
      Preconditions:
      None, error handling is done within the UIElementManager.
    • addUIElement

      public void addUIElement(UIElementName key, Node element)
      Adds a UI element to the UIElementManager, and creates the RecentlyViewedManager if the necessary UI elements are present and it has not already been created.
      Parameters:
      key - The key representing the UI element.
      element - The UI element to be added.
      Preconditions:
      key and element are not null.
      Postconditions:
      The UI element is added to the UIElementManager and can be retrieved using the provided key. If the necessary UI elements are present and the RecentlyViewedManager has not already been created, it is created.
    • readyToMakeRecentlyViewedManager

      boolean readyToMakeRecentlyViewedManager()
      Checks if the necessary UI elements for creating the RecentlyViewedManager (SearchedItemPagination and RecentlyViewedWindow) are present in the UIElementManager.
      Returns:
      true if both the RecentlyViewedWindow and SearchedItemPagination components are present in the UIElementManager, false otherwise.
    • readyToMakeSimilarItemsManager

      boolean readyToMakeSimilarItemsManager()
      Checks if the necessary UI elements for creating the SimilarItemsManager (SearchedItemPagination and SimilarItemsContainer) are present in the UIElementManager.
      Returns:
      true if both the SimilarItemsContainer and SearchedItemPagination components are present in the UIElementManager, false otherwise.
    • setButton

      public void setButton(Button button)
      Sets the button in the UIElementManager and assigns an action to it that filters the search results and updates the UI when clicked.
      Parameters:
      button - The Button to be set in the UIElementManager
      Preconditions:
      button is not null.
      Postconditions:
      The button is set in the UIElementManager and its action is assigned to filter and update the UI when clicked.
    • getButton

      public Button getButton()
      Gets the button from the UIElementManager.
      Returns:
      The Button from the UIElementManager
    • refreshUI

      public void refreshUI()
      Gets a UI element from the UIElementManager, filters data, sorts it, and updates the UI with the filtered results.
      Postconditions:
      The UI is updated with the filtered and sorted results based on the current search data from the UIElementManager.