Class SimilarItemsManager
java.lang.Object
org.troy.capstone.managers.SimilarItemsManager
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final SimilarItemsContainerTheSimilarItemsContainerthat displays the similar items.private final SimilarItemsGraphTheSimilarItemsGraphthat represents the similarity relationships between items. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSimilarItemsManager(SimilarItemsContainer similarItemsContainer, ItemRepo itemRepo, Table table) Private constructor to enforce the use of the static factory method. -
Method Summary
Modifier and TypeMethodDescriptionstatic SimilarItemsManagercreate(ItemRepo itemRepo, Table table, SearchedItemPanelDestinationUI destinationUI, SearchedItemPanelSourceUI panelSourceUI) Static factory method for creating a SimilarItemsManager instance.voidonItemSelected(String itemId) Called when an item is selected in theSearchedItemPanel.
-
Field Details
-
similarItemsContainer
TheSimilarItemsContainerthat displays the similar items. -
similarItemsGraph
TheSimilarItemsGraphthat 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- TheSimilarItemsContainerthat will display the similar items, used to update the displayed similar items when new items are added.itemRepo- TheItemRepocontaining all items, used for retrieving items to display as similar items.table- TheTablecontaining all items, used for retrieving items via their index when finding similar items to display.- Preconditions:
similarItemsContaineris 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- TheItemRepocontaining all items, used for retrieving items to display as similar items.table- TheTablecontaining all items, used for retrieving items via their index when finding similar items to display.destinationUI- TheSearchedItemPanelDestinationUIthat will display the similar items, used to update the displayed similar items when new items are added.panelSourceUI- TheSearchedItemPanelSourceUIthat will hold the search results, used to attach listeners to the item panels within.- Returns:
- A new instance of
SimilarItemsManagerwith the given parameters, and registered as a listener to thepanelSourceUI.
-
onItemSelected
Called when an item is selected in theSearchedItemPanel. Updates the similar items container content to display items similar to the selected item.- Specified by:
onItemSelectedin interfaceSearchedItemPanelInteractor- Parameters:
itemId- The ID of the selected item.- Preconditions:
itemIdis not null and corresponds to a valid key in theItemHashMap.
-