Class TableDataProvider<T>

java.lang.Object
io.goobi.viewer.managedbeans.tabledata.TableDataProvider<T>
Type Parameters:
T -
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
PersistentTableDataProvider

public class TableDataProvider<T> extends Object implements Serializable
Generic data provider for paginated, filterable, and sortable admin data tables.
See Also:
  • Constructor Details

    • TableDataProvider

      public TableDataProvider(TableDataSource<T> source)
      Creates a new TableDataProvider instance.
      Parameters:
      source - data source that supplies and counts table entries
    • TableDataProvider

      public TableDataProvider(int entriesPerPage, TableDataProvider.SortOrder sortOrder, TableDataSource<T> source)
      Creates a new TableDataProvider instance.
      Parameters:
      entriesPerPage - the number of entries per page
      sortOrder - initial sort direction for the table
      source - data source that supplies and counts table entries
  • Method Details

    • initDataProvider

      public static <T> TableDataProvider<T> initDataProvider(int itemsPerPage, String defaultSortField, TableDataProvider.SortOrder defaultSortOrder, DAOSearchFunction<T> search)

      initDataProvider.

      Type Parameters:
      T - a T class
      Parameters:
      itemsPerPage - number of items displayed per page
      defaultSortField - field name used when no explicit sort is set
      defaultSortOrder - sort direction applied with the default sort field
      search - DAO function used to fetch and count records
      Returns:
      a new TableDataProvider backed by the given DAO search function
    • getPaginatorList

      public List<T> getPaginatorList() throws TableDataSourceException
      getPaginatorList.
      Returns:
      a list of entries for the current page according to the current sort order and active filters
      Throws:
      TableDataSourceException - if any.
    • loadList

      protected Optional<List<T>> loadList()
      loadList.
      Returns:
      an Optional containing the current page's data list, or empty if the source returns null
    • getFiltersAsMap

      public Map<String,String> getFiltersAsMap()
      getFiltersAsMap.
      Returns:
      a map of column names to filter values derived from the active filters
    • resetCurrentList

      protected void resetCurrentList()
      Called ony any changes to the currently listed objects noop - may be implemented by inheriting classes.
    • sortBy

      public void sortBy(String sortField, String sortOrder)
      sortBy.
      Parameters:
      sortField - field name to sort the table by
      sortOrder - sort direction name, parsed via SortOrder.valueOf
    • sortBy

      public void sortBy(String sortField, TableDataProvider.SortOrder sortOrder)
      sortBy.
      Parameters:
      sortField - field name to sort the table by
      sortOrder - ascending or descending sort direction to apply
    • cmdMoveFirst

      public String cmdMoveFirst() throws TableDataSourceException
      cmdMoveFirst.
      Returns:
      an empty string after navigating to the first page of the data table
      Throws:
      TableDataSourceException - if any.
    • cmdMovePrevious

      public String cmdMovePrevious() throws TableDataSourceException
      cmdMovePrevious.
      Returns:
      an empty string after navigating to the previous page of the data table
      Throws:
      TableDataSourceException - if any.
    • cmdMoveNext

      public String cmdMoveNext() throws TableDataSourceException
      cmdMoveNext.
      Returns:
      an empty string after navigating to the next page of the data table
      Throws:
      TableDataSourceException - if any.
    • cmdMoveLast

      public String cmdMoveLast() throws TableDataSourceException
      cmdMoveLast.
      Returns:
      an empty string after navigating to the last page of the data table
      Throws:
      TableDataSourceException - if any.
    • setTxtMoveTo

      public void setTxtMoveTo(int neueSeite) throws TableDataSourceException
      setTxtMoveTo.
      Parameters:
      neueSeite - 1-based target page number to navigate to
      Throws:
      TableDataSourceException - if any.
    • getTxtMoveTo

      public int getTxtMoveTo()
      getTxtMoveTo.
      Returns:
      a int.
    • getLastPageNumber

      public int getLastPageNumber()
      getLastPageNumber.
      Returns:
      a int.
    • isFirstPage

      public boolean isFirstPage()
      isFirstPage.
      Returns:
      true if the current page is the first page of the data table, false otherwise
    • isLastPage

      public boolean isLastPage()
      isLastPage.
      Returns:
      true if the current page is the last page of the data table, false otherwise
    • hasNextPage

      public boolean hasNextPage()
      hasNextPage.
      Returns:
      true if there is a next page available in the data table, false otherwise
    • hasPreviousPage

      public boolean hasPreviousPage()
      hasPreviousPage.
      Returns:
      true if there is a previous page available in the data table, false otherwise
    • getPageNumberCurrent

      public Long getPageNumberCurrent()
      getPageNumberCurrent.
      Returns:
      the 1-based current page number
    • getPageNumberLast

      public Long getPageNumberLast()
      getPageNumberLast.
      Returns:
      the 1-based last page number
    • getSizeOfDataList

      public long getSizeOfDataList()
      getSizeOfDataList.
      Returns:
      a long.
    • getSortField

      public String getSortField()
      Getter for the field sortField.
      Returns:
      the name of the field currently used for sorting the data table
    • setSortField

      public void setSortField(String sortField)
      Setter for the field sortField.
      Parameters:
      sortField - field name to sort the table by
    • getSortOrder

      public TableDataProvider.SortOrder getSortOrder()
      Getter for the field sortOrder.
      Returns:
      the current sort direction
    • setSortOrder

      public void setSortOrder(TableDataProvider.SortOrder sortOrder)
      Setter for the field sortOrder.
      Parameters:
      sortOrder - ascending or descending sort direction to apply
    • setEntriesPerPage

      public void setEntriesPerPage(int entriesPerPage)
      Setter for the field entriesPerPage.
      Parameters:
      entriesPerPage - number of rows to display per page
    • getEntriesPerPage

      public int getEntriesPerPage()
      Getter for the field entriesPerPage.
      Returns:
      a int.
    • getFilters

      public List<TableDataFilter> getFilters()
      Getter for the field filters.
      Returns:
      a list of active filter criteria applied to the data source
    • removeFilter

      public void removeFilter(TableDataFilter filter)
      removeFilter.
      Parameters:
      filter - filter instance to remove from the active filters
    • resetFilters

      public void resetFilters()
      resetFilters.
    • resetAll

      public void resetAll()
      resetAll.
    • update

      public void update()
      update.
    • getFilter

      public TableDataFilter getFilter(String... columns)

      getFilter.

      Parameters:
      columns - one or more column names the filter applies to
      Returns:
      the existing filter for the given columns, or a newly created one if none exists
    • addFilter

      public void addFilter(TableDataFilter filter)

      addFilter.

      Parameters:
      filter - pre-built filter instance to append to the active filters
    • getFilterIfPresent

      public Optional<TableDataFilter> getFilterIfPresent(String... columns)

      getFilterIfPresent.

      Parameters:
      columns - one or more column names to match against existing filters
      Returns:
      an Optional containing the matching filter, or empty if none is found