Class SortedColumnList

java.lang.Object
org.apache.myfaces.tobago.model.SortedColumnList
All Implemented Interfaces:
Serializable

public class SortedColumnList extends Object implements Serializable
Holds the sorting state for a sheet (data table).

This class maintains an ordered list of SortedColumn entries representing the current multi-column sort, where the first entry has the highest precedence. The size of the list is limited by max.

The property getToBeSortedLevel() indicates how many leading sort levels must be (re)applied during the current request. It is increased when the sort order changes and reset by sorted() after the data has been processed.

New sort requests move the affected column to the front of the list; repeating the request on the same column toggles its direction.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new sort state with a maximum number of tracked sort levels.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String columnId, boolean ascending)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Only for backward compatibility of deprecated functions.
    void
    Removes all SortedColumn entries from this list.
    get(int index)
    Returns the SortedColumn at the given position.
    Returns the primary sort column, if any.
    int
    Number of levels (columns) which are still to be sorted.
    int
    Returns the index of a column with the given identifier.
    boolean
    Returns whether no sort order is currently defined.
    boolean
    If max > 1 the UI may show sort order numbers, which can be queried.
    void
    setToBeSortedLevel(int toBeSortedLevel)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use sorted()
    int
    Returns the number of active sort levels currently stored.
    void
    Indicates that every column is sorted and a SortActionEvent is not executed in this request.
    void
    Updates the current sort state for the given column identifier.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SortedColumnList

      public SortedColumnList(int max)
      Creates a new sort state with a maximum number of tracked sort levels.

      The list will keep at most max entries. If max is less than 1, it will be normalized to 1. When max > 1, isShowNumbers() will be true so that the UI can optionally display sort order numbers.

      Parameters:
      max - the maximum number of columns to consider for multi-column sorting
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns whether no sort order is currently defined.
    • getFirst

      public SortedColumn getFirst()
      Returns the primary sort column, if any.
    • updateSortState

      public void updateSortState(String columnId)
      Updates the current sort state for the given column identifier.

      If the column is already the primary sort key, its direction is toggled and at least the first level is marked to be re-sorted. Otherwise, the column is moved/inserted to the front as ascending, previous occurrence (if any) is removed, and the number of levels to be sorted is adjusted. The list size is then normalized to the configured maximum.

      Parameters:
      columnId - the technical identifier of the column to sort by
    • add

      @Deprecated(since="5.3.0", forRemoval=true) public void add(String columnId, boolean ascending)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Only for backward compatibility of deprecated functions. Use updateSortState(String) instead.
      Adds a sorted column entry to the end of the list.
      Parameters:
      columnId - the technical identifier of the column
      ascending - true for ascending order, false for descending
    • get

      public SortedColumn get(int index)
      Returns the SortedColumn at the given position.
      Parameters:
      index - zero-based index into the current sort list
      Returns:
      the SortedColumn at the given index
    • size

      public int size()
      Returns the number of active sort levels currently stored.
      Returns:
      the size of the internal list of SortedColumn entries
    • clear

      public void clear()
      Removes all SortedColumn entries from this list.
    • sorted

      public void sorted()
      Indicates that every column is sorted and a SortActionEvent is not executed in this request.
    • indexOf

      public int indexOf(String id)
      Returns the index of a column with the given identifier.
      Parameters:
      id - the technical identifier of the column to look up
    • isShowNumbers

      public boolean isShowNumbers()

      If max > 1 the UI may show sort order numbers, which can be queried.

      Method is used internally by the Tobago sorting component.

    • getToBeSortedLevel

      public int getToBeSortedLevel()

      Number of levels (columns) which are still to be sorted. Is smaller or equals the size of list (columns to sort by).

      Method is used internally by the Tobago sorting component.

      Returns:
      the number of levels (columns) which must be sorted this request
    • setToBeSortedLevel

      @Deprecated(since="5.9.1", forRemoval=true) public void setToBeSortedLevel(int toBeSortedLevel)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use sorted()