Interface Paginator<T>
- Type Parameters:
T- the source element type
- All Known Implementing Classes:
NormalPagination,PatternPagination,ScrollPagination
PaginationHost. This is the relocated 2.x Pagination interface,
renamed because the public pagination.Pagination name now belongs to the reactive
token.-
Method Summary
Modifier and TypeMethodDescriptionvoidbind(@NotNull PaginationHost host) Binds the engine against a freshly opened host: sets the host, derives the navigation state for the current (possibly pre-recorded) page and dispatches the initial load without requesting a render — the open's initial paint covers it.voidchangePage(int page) Navigates directly to the given 1-indexed page.intReturns the current page.intReturns the page capacity.intgetPageOfIndex(int index) Maps a global source index onto the page it appears on.intReturns the element count of the current source.intReturns the page count of the current source.booleanReturns whether forward navigation is possible.booleanReturns whether backward navigation is possible.voidPaints the items of the current page throughPaginationHost.fillPage(java.util.List<tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.RenderedItem>, tech.guilhermekaua.spigotboot.inventoryapi.layout.Layout).booleanReports whether the most recently settled page rendered no elements.booleanReturns the in-flight state of the source.@Nullable ThrowableReturns the most recent load failure.voidnextPage()Advances to the next page if one exists.voidReturns to the previous page if one exists.voidrefresh()Re-requests the current page, invalidating any cached copy first.voidreplaceSource(@NotNull PageSource<T> source) Swaps the backing source and clears the locally held items.
-
Method Details
-
bind
Binds the engine against a freshly opened host: sets the host, derives the navigation state for the current (possibly pre-recorded) page and dispatches the initial load without requesting a render — the open's initial paint covers it.Must be called once before any painting method is invoked. Eager sources settle inline during bind, so their items are ready before the first paint; async sources leave
isLoading()trueso the first paint shows the loading frame.- Parameters:
host- the world-facing seam the engine paints and renders through
-
insertPageItems
void insertPageItems()Paints the items of the current page throughPaginationHost.fillPage(java.util.List<tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.RenderedItem>, tech.guilhermekaua.spigotboot.inventoryapi.layout.Layout). -
isCurrentPageEmpty
boolean isCurrentPageEmpty()Reports whether the most recently settled page rendered no elements. Used by the host to decide whether to paint the empty-state frame.- Returns:
truewhen the current page has no elements
-
changePage
void changePage(int page) Navigates directly to the given 1-indexed page.The target is clamped to at least 1, and to
getTotalPages()once the backing source's totals are known. For async sources, navigation issued before the first load completes is honored optimistically and re-clamped downward when totals arrive. A call that targets the current page while a request for it is already in flight is ignored; userefresh()to force a reload. Beforebind(PaginationHost)the call only records the target page;binddispatches the load for it.- Parameters:
page- the 1-indexed page to navigate to
-
nextPage
void nextPage()Advances to the next page if one exists. -
hasNextPage
boolean hasNextPage()Returns whether forward navigation is possible.- Returns:
trueif there is at least one page after the current one
-
previousPage
void previousPage()Returns to the previous page if one exists. -
hasPreviousPage
boolean hasPreviousPage()Returns whether backward navigation is possible.- Returns:
trueif there is at least one page before the current one
-
getTotalPages
int getTotalPages()Returns the page count of the current source.Results are undefined before
bind(tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.PaginationHost): the page limit is derived from the layout at bind time (pre-init reads are answered by the binding, never by the engine).- Returns:
- the total number of pages backing the current source, at least 1
-
getCurrentPage
int getCurrentPage()Returns the current page.- Returns:
- the 1-indexed current page number
-
getTotalElements
int getTotalElements()Returns the element count of the current source.- Returns:
- the total number of elements in the backing source, independent of how many are loaded locally
-
getItemPageLimit
int getItemPageLimit()Returns the page capacity.Results are undefined before
bind(tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.PaginationHost): the page limit is derived from the layout at bind time (pre-init reads are answered by the binding, never by the engine).- Returns:
- the maximum number of items rendered per page
-
getPageOfIndex
int getPageOfIndex(int index) Maps a global source index onto the page it appears on.Results are undefined before
bind(tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.PaginationHost): the page limit is derived from the layout at bind time (pre-init reads are answered by the binding, never by the engine).- Parameters:
index- the global element index- Returns:
- the 1-indexed page containing the given index (for scroll paginators: the first
page on which the index becomes visible), or
-1if the index is outside[0, getTotalElements())
-
isLoading
boolean isLoading()Returns the in-flight state of the source.- Returns:
truewhile an async page load for this paginator is in flight; alwaysfalsefor eager sources
-
lastError
Returns the most recent load failure.- Returns:
- the failure of the most recent async page load, or
null; cleared when a new load is dispatched. Alwaysnullfor eager sources.
-
refresh
void refresh()Re-requests the current page, invalidating any cached copy first. For async sources this is the supported idiom to re-query after the backing store changed; for eager sources it re-renders the current page. -
replaceSource
Swaps the backing source and clears the locally held items. Dispatches nothing and renders nothing — callers drive the re-request; a swap beforebind(PaginationHost)is picked up by the bind-time dispatch.- Parameters:
source- the new page source, not null- Throws:
NullPointerException- ifsourceis null
-