Class GeneralManager
java.lang.Object
org.troy.capstone.managers.GeneralManager
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
FieldsModifier and TypeFieldDescriptionprivate final ItemRepoTheItemRepocontaining all items, used by theSearchEnginefor filtering and searching and by theRecentlyViewedManagerfor retrieving items.private booleanA flag to track whether theRecentlyViewedManagerhas been created.private final SearchEngineTheSearchEngineinstance for performing search operations.private booleanA flag to track whether theSimilarItemsManagerhas been created.private final TableThe originalTablecontaining the items, used for retrieving items by index.private final UIElementManagerTheUIElementManagerinstance for managing UI elements. -
Constructor Summary
ConstructorsConstructorDescriptionGeneralManager(Table table, ItemRepo itemRepo) Constructor forGeneralManager, filled from aTable. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddUIElement(UIElementName key, Node element) Adds a UI element to theUIElementManager, and creates theRecentlyViewedManagerif the necessary UI elements are present and it has not already been created.Gets the button from theUIElementManager.Gets the search data from theUIElementManager.Gets a UI element from theUIElementManagerbased on the provided key.(package private) booleanChecks if the necessary UI elements for creating theRecentlyViewedManager(SearchedItemPagination and RecentlyViewedWindow) are present in theUIElementManager.(package private) booleanChecks if the necessary UI elements for creating theSimilarItemsManager(SearchedItemPagination and SimilarItemsContainer) are present in theUIElementManager.voidGets a UI element from theUIElementManager, filters data, sorts it, and updates the UI with the filtered results.voidSets the button in theUIElementManagerand assigns an action to it that filters the search results and updates the UI when clicked.
-
Field Details
-
uiManager
TheUIElementManagerinstance for managing UI elements. -
searchEngine
TheSearchEngineinstance for performing search operations. -
itemRepo
TheItemRepocontaining all items, used by theSearchEnginefor filtering and searching and by theRecentlyViewedManagerfor retrieving items. -
table
The originalTablecontaining the items, used for retrieving items by index. -
recentlyViewedManagerCreated
private boolean recentlyViewedManagerCreatedA flag to track whether theRecentlyViewedManagerhas been created. Used to prevent duplicate creation. -
similarItemsManagerCreated
private boolean similarItemsManagerCreatedA flag to track whether theSimilarItemsManagerhas been created. Used to prevent duplicate creation.
-
-
Constructor Details
-
GeneralManager
Constructor forGeneralManager, filled from aTable.- Parameters:
table- TheTablecontaining the item data to be used by theSearchEngine.itemRepo- TheItemRepocontaining all items, used by theSearchEnginefor filtering and searching and by theRecentlyViewedManagerfor retrieving items.
-
-
Method Details
-
getUIElement
Gets a UI element from theUIElementManagerbased on the provided key.- Parameters:
key- The key representing the UI element to retrieve.- Returns:
- An
Optionalcontaining the UI element if found, or an emptyOptionalif not found. - Preconditions:
- key is not null.
-
getSearchData
Gets the search data from theUIElementManager.- Returns:
- The search data containing the filters to be applied.
- Preconditions:
- None, error handling is done within the
UIElementManager.
-
addUIElement
Adds a UI element to theUIElementManager, and creates theRecentlyViewedManagerif 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
UIElementManagerand can be retrieved using the provided key. If the necessary UI elements are present and theRecentlyViewedManagerhas not already been created, it is created.
-
readyToMakeRecentlyViewedManager
boolean readyToMakeRecentlyViewedManager()Checks if the necessary UI elements for creating theRecentlyViewedManager(SearchedItemPagination and RecentlyViewedWindow) are present in theUIElementManager.- Returns:
- true if both the
RecentlyViewedWindowandSearchedItemPaginationcomponents are present in theUIElementManager, false otherwise.
-
readyToMakeSimilarItemsManager
boolean readyToMakeSimilarItemsManager()Checks if the necessary UI elements for creating theSimilarItemsManager(SearchedItemPagination and SimilarItemsContainer) are present in theUIElementManager.- Returns:
- true if both the
SimilarItemsContainerandSearchedItemPaginationcomponents are present in theUIElementManager, false otherwise.
-
setButton
Sets the button in theUIElementManagerand assigns an action to it that filters the search results and updates the UI when clicked.- Parameters:
button- The Button to be set in theUIElementManager- Preconditions:
- button is not null.
- Postconditions:
- The button is set in the
UIElementManagerand its action is assigned to filter and update the UI when clicked.
-
getButton
Gets the button from theUIElementManager.- Returns:
- The Button from the
UIElementManager
-
refreshUI
public void refreshUI()Gets a UI element from theUIElementManager, 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.
-