Class SimilarItemsManager

java.lang.Object
org.troy.capstone.managers.SimilarItemsManager
All Implemented Interfaces:
SearchedItemPanelInteractor

public class SimilarItemsManager extends Object implements SearchedItemPanelInteractor
The SimilarItemsManager class manages the display of similar items to a selected item. It listens for item selection events and updates a SimilarItemsContainer accordingly.
  • Field Details

    • similarItemsContainer

      private final SimilarItemsContainer similarItemsContainer
      The SimilarItemsContainer that displays the similar items.
    • similarItemsGraph

      private final SimilarItemsGraph similarItemsGraph
      The SimilarItemsGraph that represents the similarity relationships between items.
  • Constructor Details

    • SimilarItemsManager

      private SimilarItemsManager(SimilarItemsContainer similarItemsContainer, ItemRepo itemRepo, Table table)
      Private constructor to enforce the use of the static factory method.
      Parameters:
      similarItemsContainer - The SimilarItemsContainer that will display the similar items, used to update the displayed similar items when new items are added.
      itemRepo - The ItemRepo containing all items, used for retrieving items to display as similar items.
      table - The Table containing all items, used for retrieving items via their index when finding similar items to display.
      Preconditions:
      similarItemsContainer is not null.
  • Method Details

    • create

      public static SimilarItemsManager create(ItemRepo itemRepo, Table table, SearchedItemPanelDestinationUI destinationUI, SearchedItemPanelSourceUI panelSourceUI)
      Static factory method for creating a SimilarItemsManager instance. Also handles registering the manager as a listener to the searched item panels in the searched item pagination, allowing it to update the similar items content based on user interactions with the search results.
      Parameters:
      itemRepo - The ItemRepo containing all items, used for retrieving items to display as similar items.
      table - The Table containing all items, used for retrieving items via their index when finding similar items to display.
      destinationUI - The SearchedItemPanelDestinationUI that will display the similar items, used to update the displayed similar items when new items are added.
      panelSourceUI - The SearchedItemPanelSourceUI that will hold the search results, used to attach listeners to the item panels within.
      Returns:
      A new instance of SimilarItemsManager with the given parameters, and registered as a listener to the panelSourceUI.
    • onItemSelected

      public void onItemSelected(String itemId)
      Called when an item is selected in the SearchedItemPanel. Updates the similar items container content to display items similar to the selected item.
      Specified by:
      onItemSelected in interface SearchedItemPanelInteractor
      Parameters:
      itemId - The ID of the selected item.
      Preconditions:
      itemId is not null and corresponds to a valid key in the ItemHashMap.