public abstract class AbstractPageProvider<T> extends Object implements PageProvider<T>
PageProvider
.
Provides next/prev standard logics, and helper methods for retrieval of items and first/next/prev/last buttons display as well as other display information (number of pages for instance).
Also handles selection by providing a default implementation of getCurrentSelectPage()
working in
conjunction with setSelectedEntries(List)
.
Modifier and Type | Field and Description |
---|---|
protected int |
currentEntryIndex |
protected int |
currentHigherNonEmptyPageIndex
Integer keeping track of the higher page index giving results.
|
protected PageSelections<T> |
currentSelectPage |
protected PageProviderDefinition |
definition |
protected Throwable |
error |
protected String |
errorMessage |
static org.apache.commons.logging.Log |
log |
protected long |
maxPageSize |
protected String |
name |
protected long |
offset |
static String |
PAGEPROVIDER_TRACK_PROPERTY_NAME
property used to enable globally tracking : property should contains the list of pageproviders to be tracked
|
protected PageProviderChangedListener |
pageProviderChangedListener |
protected long |
pageSize |
protected List<Long> |
pageSizeOptions |
protected Object[] |
parameters |
protected Map<String,Serializable> |
properties |
protected long |
resultsCount |
protected DocumentModel |
searchDocumentModel |
protected List<T> |
selectedEntries |
protected static List<String> |
SKIPPED_SCHEMAS_FOR_SEARCHFIELD
lists schemas prefixes that should be skipped when extracting "search fields" (tracking) from searchDocumentModel
|
protected boolean |
sortable |
protected List<SortInfo> |
sortInfos |
protected Boolean |
tracking |
DEFAULT_MAX_PAGE_SIZE, DEFAULT_MAX_PAGE_SIZE_RUNTIME_PROP, PAGE_LIMIT_UNKNOWN, UNKNOWN_SIZE, UNKNOWN_SIZE_AFTER_QUERY
Constructor and Description |
---|
AbstractPageProvider() |
Modifier and Type | Method and Description |
---|---|
void |
addSortInfo(String sortColumn,
boolean sortAscending)
Add the given sort info to the list of sorting infos.
|
protected void |
fireSearchEvent(Principal principal,
String query,
List<T> entries,
Long executionTimeMs)
Send a search event so that PageProvider calls can be tracked by Audit or other statistic gathering process
|
void |
firstPage()
Go to the first page
|
List<AggregateDefinition> |
getAggregateDefinitions() |
Map<String,Aggregate<? extends Bucket>> |
getAggregates() |
protected boolean |
getBooleanProperty(String propName,
boolean defaultValue) |
T |
getCurrentEntry()
Returns the current entry.
|
int |
getCurrentHigherNonEmptyPageIndex()
Returns an integer keeping track of the higher page index giving results.
|
abstract List<T> |
getCurrentPage()
Returns the list of current page items.
|
long |
getCurrentPageIndex()
Returns the current page index as a zero-based integer.
|
long |
getCurrentPageOffset()
Returns the offset (starting from 0) of the first element in the current page or
UNKNOWN_SIZE . |
long |
getCurrentPageSize()
Returns the number of elements in current page.
|
String |
getCurrentPageStatus()
Returns a simple formatted string for current pagination status.
|
PageSelections<T> |
getCurrentSelectPage()
Returns the current page of results wrapped in a
PageSelection item. |
protected long |
getDefaultMaxPageSize() |
PageProviderDefinition |
getDefinition() |
Throwable |
getError() |
String |
getErrorMessage() |
int |
getMaxNumberOfEmptyPages()
Returns the maximum number of empty pages that can be fetched empty (defaults to 1).
|
long |
getMaxPageSize()
Returns the max number of results per page.
|
long |
getMinMaxPageSize()
Returns the minimal value for the max page size, taking the lower value between the requested page size and the
maximum accepted page size.
|
String |
getName()
Returns the provider identifier
|
long |
getNumberOfPages()
Returns the total number of pages or 0 if number of pages is unknown.
|
long |
getPageLimit()
Returns the page limit.
|
long |
getPageSize()
Returns the number of results per page.
|
List<Long> |
getPageSizeOptions()
Returns a list of available page size options to display in the page size selector.
|
Object[] |
getParameters() |
protected boolean |
getParametersChanged(Object[] oldParams,
Object[] newParams) |
Map<String,Serializable> |
getProperties()
Gets properties set on the provider.
|
long |
getResultsCount()
Returns the number of result elements if available or a negative value if it is unknown:
UNKNOWN_SIZE if it is unknown as query was not done, and since 5.5,
UNKNOWN_SIZE_AFTER_QUERY if it is still unknown after query was done. |
DocumentModel |
getSearchDocumentModel() |
SortInfo |
getSortInfo()
Returns the first sorting info for this provider
|
int |
getSortInfoIndex(String sortColumn,
boolean sortAscending)
Returns a positive 0-based integer if given sort information is found on the set sort infos, indicating the sort
index, or -1 if this sort information is not found.
|
List<SortInfo> |
getSortInfos()
Returns the complete list of sorting info for this provider
|
boolean |
hasAggregateSupport() |
boolean |
hasChangedParameters(Object[] parameters)
Test if provider parameters have changed
|
boolean |
hasError() |
protected void |
incorporateAggregates(Map<String,Serializable> eventProps)
Default (dummy) implementation that should be overridden by PageProvider actually dealing with Aggregates
|
boolean |
isLastPageAvailable()
Returns a boolean expressing if the last page can be displayed.
|
boolean |
isNextEntryAvailable()
Returns true if there is a next entry.
|
boolean |
isNextPageAvailable()
Returns a boolean expressing if there are further pages.
|
boolean |
isPreviousEntryAvailable()
Returns true if there is a previous entry.
|
boolean |
isPreviousPageAvailable()
Returns a boolean expressing if there is a previous page.
|
boolean |
isSortable()
Returns if this provider is sortable
|
protected boolean |
isTrackingEnabled() |
void |
last()
Deprecated.
|
void |
lastPage()
Go to the last page.
|
void |
next()
Deprecated.
|
void |
nextEntry()
Move the current entry to the next one, if applicable.
|
void |
nextPage()
Go to the next page
|
protected void |
notifyPageChanged()
Call the registered
PageProviderChangedListener , if any, to notify that the page provider current page
has changed. |
protected void |
notifyRefresh()
Call the registered
PageProviderChangedListener , if any, to notify that the page provider has refreshed. |
protected void |
pageChanged()
Page change hook, to override for custom behavior
|
void |
previous()
Deprecated.
|
void |
previousEntry()
Move the current entry to the previous one, if applicable.
|
void |
previousPage()
Go to the previous page
|
void |
refresh()
Refresh hook, to override for custom behavior
|
void |
rewind()
Deprecated.
|
protected boolean |
searchDocumentModelChanged(DocumentModel oldDoc,
DocumentModel newDoc) |
void |
setCurrentEntry(T entry)
Sets the current entry.
|
void |
setCurrentEntryIndex(long index)
Sets the current entry index.
|
void |
setCurrentHigherNonEmptyPageIndex(int higherFilledPageIndex) |
List<T> |
setCurrentPage(long page)
Sets the current page of results to the required one and return it.
|
void |
setCurrentPageIndex(long currentPageIndex)
Sets the current page of results to the required one.
|
void |
setCurrentPageOffset(long offset)
Sets the current page offset.
|
void |
setDefinition(PageProviderDefinition providerDefinition) |
void |
setMaxPageSize(long maxPageSize)
Sets the max number of results per page.
|
void |
setName(String name)
Sets the provider identifier
|
void |
setPageProviderChangedListener(PageProviderChangedListener listener)
Sets the
PageProviderChangedListener for this PageProvider . |
void |
setPageSize(long pageSize)
Sets the number of results per page.
|
void |
setPageSizeOptions(List<Long> options)
Sets the page size options.
|
void |
setParameters(Object[] parameters) |
void |
setProperties(Map<String,Serializable> properties)
Sets properties set on the provider.
|
void |
setResultsCount(long resultsCount)
Sets the results count.
|
void |
setSearchDocumentModel(DocumentModel searchDocumentModel) |
void |
setSelectedEntries(List<T> entries)
Sets the list of selected entries to take into account in
PageProvider.getCurrentSelectPage() . |
void |
setSortable(boolean sortable) |
void |
setSortInfo(SortInfo sortInfo)
Sets the first and only sorting info for this provider.
|
void |
setSortInfo(String sortColumn,
boolean sortAscending,
boolean removeOtherSortInfos)
Sets the first and only sorting info for this provider if parameter removeOtherSortInfos is true.
|
void |
setSortInfos(List<SortInfo> sortInfo)
Sets the complete list of sorting info for this provider
|
protected boolean |
sortInfoChanged(List<SortInfo> oldSortInfos,
List<SortInfo> newSortInfos) |
public static final org.apache.commons.logging.Log log
public static final String PAGEPROVIDER_TRACK_PROPERTY_NAME
protected static final List<String> SKIPPED_SCHEMAS_FOR_SEARCHFIELD
protected long offset
protected long pageSize
protected List<Long> pageSizeOptions
protected long maxPageSize
protected long resultsCount
protected int currentEntryIndex
protected int currentHigherNonEmptyPageIndex
protected boolean sortable
protected List<T> selectedEntries
protected PageSelections<T> currentSelectPage
protected Map<String,Serializable> properties
protected Object[] parameters
protected DocumentModel searchDocumentModel
protected String errorMessage
protected PageProviderDefinition definition
protected PageProviderChangedListener pageProviderChangedListener
public AbstractPageProvider()
public abstract List<T> getCurrentPage()
Custom implementation can be added here, based on the page provider properties, parameters and
WhereClauseDefinition
on the PageProviderDefinition
, as well as search document, sort
information, etc...
Implementation of this method usually consists in setting a non-null value to a field caching current items, and
nullifying this field by overriding pageChanged()
and refresh()
.
Fields errorMessage
and error
can also be filled to provide accurate feedback in case an error
occurs during the search.
When items are retrieved, a call to setResultsCount(long)
should be made to ensure proper pagination as
implemented in this abstract class. The implementation in CoreQueryAndFetchPageProvider
is a good example
when the total results count is known.
If for performance reasons, for instance, the number of results cannot be known, a fall-back strategy can be
applied to provide the "next" button but not the "last" one, by calling
getCurrentHigherNonEmptyPageIndex()
and setCurrentHigherNonEmptyPageIndex(int)
. In this case,
CoreQueryDocumentPageProvider
is a good example.
getCurrentPage
in interface PageProvider<T>
protected void pageChanged()
When overriding it, call super.pageChanged()
as last statement to make sure that the
PageProviderChangedListener
is called with the up-to-date @{code PageProvider} state.
public void firstPage()
PageProvider
firstPage
in interface PageProvider<T>
@Deprecated public void rewind()
public long getCurrentPageIndex()
PageProvider
getCurrentPageIndex
in interface PageProvider<T>
public long getCurrentPageOffset()
PageProvider
UNKNOWN_SIZE
.getCurrentPageOffset
in interface PageProvider<T>
public void setCurrentPageOffset(long offset)
PageProvider
If the provider keeps information linked to the current page, they should be reset after calling this method.
setCurrentPageOffset
in interface PageProvider<T>
public long getCurrentPageSize()
PageProvider
getCurrentPageSize
in interface PageProvider<T>
public String getName()
PageProvider
getName
in interface PageProvider<T>
public long getNumberOfPages()
PageProvider
getNumberOfPages
in interface PageProvider<T>
public void setCurrentPageIndex(long currentPageIndex)
PageProvider
setCurrentPageIndex
in interface PageProvider<T>
currentPageIndex
- the page index, starting from 0public List<T> setCurrentPage(long page)
PageProvider
setCurrentPage
in interface PageProvider<T>
page
- the page index, starting from 0public long getPageSize()
PageProvider
PageProvider.getMaxPageSize()
is greater than
this value, it will be taken into account instead.getPageSize
in interface PageProvider<T>
public void setPageSize(long pageSize)
PageProvider
PageProvider.getMaxPageSize()
is greater than this
value, it will be taken into account instead.setPageSize
in interface PageProvider<T>
public List<Long> getPageSizeOptions()
PageProvider
Uses an hardcoded list of values, and adds up the page provider initial and current page sizes.
getPageSizeOptions
in interface PageProvider<T>
public void setPageSizeOptions(List<Long> options)
PageProvider
setPageSizeOptions
in interface PageProvider<T>
public List<SortInfo> getSortInfos()
PageProvider
getSortInfos
in interface PageProvider<T>
public SortInfo getSortInfo()
PageProvider
Also kept for compatibility with existing code.
getSortInfo
in interface PageProvider<T>
protected boolean sortInfoChanged(List<SortInfo> oldSortInfos, List<SortInfo> newSortInfos)
public void setSortInfos(List<SortInfo> sortInfo)
PageProvider
setSortInfos
in interface PageProvider<T>
public void setSortInfo(SortInfo sortInfo)
PageProvider
Also kept for compatibility with existing code.
setSortInfo
in interface PageProvider<T>
public void setSortInfo(String sortColumn, boolean sortAscending, boolean removeOtherSortInfos)
PageProvider
setSortInfo
in interface PageProvider<T>
public void addSortInfo(String sortColumn, boolean sortAscending)
PageProvider
addSortInfo
in interface PageProvider<T>
public int getSortInfoIndex(String sortColumn, boolean sortAscending)
PageProvider
getSortInfoIndex
in interface PageProvider<T>
public boolean isNextPageAvailable()
PageProvider
isNextPageAvailable
in interface PageProvider<T>
public boolean isLastPageAvailable()
PageProvider
isLastPageAvailable
in interface PageProvider<T>
public boolean isPreviousPageAvailable()
PageProvider
isPreviousPageAvailable
in interface PageProvider<T>
public void lastPage()
PageProvider
lastPage
in interface PageProvider<T>
@Deprecated public void last()
public void nextPage()
PageProvider
nextPage
in interface PageProvider<T>
@Deprecated public void next()
public void previousPage()
PageProvider
previousPage
in interface PageProvider<T>
@Deprecated public void previous()
public void refresh()
When overriding it, call super.refresh()
as last statement to make sure that the
PageProviderChangedListener
is called with the up-to-date @{code PageProvider} state.
refresh
in interface PageProvider<T>
public void setName(String name)
PageProvider
setName
in interface PageProvider<T>
public String getCurrentPageStatus()
PageProvider
getCurrentPageStatus
in interface PageProvider<T>
public boolean isNextEntryAvailable()
PageProvider
The next entry might be in next page, except if results count is unknown.
isNextEntryAvailable
in interface PageProvider<T>
public boolean isPreviousEntryAvailable()
PageProvider
The previous entry might be in previous page.
isPreviousEntryAvailable
in interface PageProvider<T>
public void nextEntry()
PageProvider
If needed and possible, the provider will forward to next page. No special exceptions: this method is intended to be plugged directly at the UI layer. In case there's no next entry, nothing happens.
nextEntry
in interface PageProvider<T>
public void previousEntry()
PageProvider
No exception: this method is intended to be plugged directly at the UI layer. In case there's no previous entry, nothing will happen.
previousEntry
in interface PageProvider<T>
public T getCurrentEntry()
PageProvider
getCurrentEntry
in interface PageProvider<T>
public void setCurrentEntry(T entry)
PageProvider
setCurrentEntry
in interface PageProvider<T>
public void setCurrentEntryIndex(long index)
PageProvider
setCurrentEntryIndex
in interface PageProvider<T>
public long getResultsCount()
PageProvider
UNKNOWN_SIZE
if it is unknown as query was not done, and since 5.5,
UNKNOWN_SIZE_AFTER_QUERY
if it is still unknown after query was done.getResultsCount
in interface PageProvider<T>
public Map<String,Serializable> getProperties()
PageProvider
Useful to retrieve a provider specific field attributes after instantiation. Other contextual parameters can be passed through API constructing the result provider.
getProperties
in interface PageProvider<T>
public void setProperties(Map<String,Serializable> properties)
PageProvider
Useful to initialize a provider specific field attributes after instantiation. Other contextual parameters can be passed through API constructing the result provider.
setProperties
in interface PageProvider<T>
protected boolean getBooleanProperty(String propName, boolean defaultValue)
public void setResultsCount(long resultsCount)
PageProvider
setResultsCount
in interface PageProvider<T>
public void setSortable(boolean sortable)
setSortable
in interface PageProvider<T>
public boolean isSortable()
PageProvider
isSortable
in interface PageProvider<T>
public PageSelections<T> getCurrentSelectPage()
PageProvider
PageSelection
item.
By default, no entry is selected, unless PageProvider.setSelectedEntries(List)
has been called before.
getCurrentSelectPage
in interface PageProvider<T>
public void setSelectedEntries(List<T> entries)
PageProvider
PageProvider.getCurrentSelectPage()
.setSelectedEntries
in interface PageProvider<T>
public Object[] getParameters()
getParameters
in interface PageProvider<T>
public void setParameters(Object[] parameters)
setParameters
in interface PageProvider<T>
public DocumentModel getSearchDocumentModel()
getSearchDocumentModel
in interface PageProvider<T>
protected boolean searchDocumentModelChanged(DocumentModel oldDoc, DocumentModel newDoc)
public void setSearchDocumentModel(DocumentModel searchDocumentModel)
setSearchDocumentModel
in interface PageProvider<T>
public String getErrorMessage()
getErrorMessage
in interface PageProvider<T>
public Throwable getError()
getError
in interface PageProvider<T>
public boolean hasError()
hasError
in interface PageProvider<T>
public PageProviderDefinition getDefinition()
getDefinition
in interface PageProvider<T>
public void setDefinition(PageProviderDefinition providerDefinition)
setDefinition
in interface PageProvider<T>
public long getMaxPageSize()
PageProvider
If page size is greater than this maximum value, it will be taken into account instead.
getMaxPageSize
in interface PageProvider<T>
public void setMaxPageSize(long maxPageSize)
PageProvider
If page size is greater than this maximum value, it will be taken into account instead.
setMaxPageSize
in interface PageProvider<T>
public long getMinMaxPageSize()
public int getCurrentHigherNonEmptyPageIndex()
public long getPageLimit()
getPageLimit
in interface PageProvider<T>
public void setCurrentHigherNonEmptyPageIndex(int higherFilledPageIndex)
public int getMaxNumberOfEmptyPages()
protected long getDefaultMaxPageSize()
public void setPageProviderChangedListener(PageProviderChangedListener listener)
PageProvider
PageProviderChangedListener
for this PageProvider
.setPageProviderChangedListener
in interface PageProvider<T>
protected void notifyPageChanged()
PageProviderChangedListener
, if any, to notify that the page provider current page
has changed.protected void notifyRefresh()
PageProviderChangedListener
, if any, to notify that the page provider has refreshed.public boolean hasChangedParameters(Object[] parameters)
PageProvider
hasChangedParameters
in interface PageProvider<T>
protected boolean getParametersChanged(Object[] oldParams, Object[] newParams)
public List<AggregateDefinition> getAggregateDefinitions()
getAggregateDefinitions
in interface PageProvider<T>
public Map<String,Aggregate<? extends Bucket>> getAggregates()
getAggregates
in interface PageProvider<T>
public boolean hasAggregateSupport()
hasAggregateSupport
in interface PageProvider<T>
protected boolean isTrackingEnabled()
protected void fireSearchEvent(Principal principal, String query, List<T> entries, Long executionTimeMs)
principal
- query
- entries
- protected void incorporateAggregates(Map<String,Serializable> eventProps)
eventProps
- Copyright © 2015 Nuxeo SA. All rights reserved.