Class AbstractSortedTableModel<T>

    • Field Detail

      • hasEverSorted

        protected boolean hasEverSorted
    • Constructor Detail

      • AbstractSortedTableModel

        public AbstractSortedTableModel()
      • AbstractSortedTableModel

        public AbstractSortedTableModel​(int defaultSortColumn)
    • Method Detail

      • setDefaultTableSortState

        protected void setDefaultTableSortState​(TableSortState defaultSortState)
      • addSortListener

        public void addSortListener​(SortListener l)
        Description copied from interface: SortedTableModel
        Adds a listener to be notified when the sort state of this model changes.
        Note: the listener may be stored in a weak collection, which means you have to maintain a handle to the listener so that it does not get garbage collected.
        Specified by:
        addSortListener in interface SortedTableModel
        Parameters:
        l - the listener
      • getRowIndex

        public int getRowIndex​(T rowObject)
        Returns the index of the given row object in this model; a negative value if the model does not contain the given object.

        Warning: if the this model has no sort applied, then performance will be O(n). If sorted, then performance is O(log n). You can call isSorted() to know when this will happen.

        Specified by:
        getRowIndex in interface RowObjectTableModel<T>
        Overrides:
        getRowIndex in class AbstractGTableModel<T>
        Parameters:
        rowObject - the object
        Returns:
        the row number
      • fireTableChanged

        public void fireTableChanged​(javax.swing.event.TableModelEvent e)
        Overrides:
        fireTableChanged in class javax.swing.table.AbstractTableModel
      • reSort

        protected void reSort()
      • getPrimarySortColumnIndex

        public int getPrimarySortColumnIndex()
        Description copied from interface: SortedTableModel
        Returns the column index that is the primary sorted column; -1 if no column is sorted
        Specified by:
        getPrimarySortColumnIndex in interface SortedTableModel
        Returns:
        the index
      • cleanupTableSortState

        protected TableSortState cleanupTableSortState​(TableSortState state)
        A convenience method that will take a given sort state and remove from it any columns that cannot be sorted. This is useful if the client is restoring a sort state that contains columns that have been removed or are no longer sortable (such as during major table model rewrites).
        Parameters:
        state - the state
        Returns:
        the updated state
      • isSortPending

        public boolean isSortPending()
        Returns true if there is a pending change to the current sort state (this includes a sort state that signals no sort will be applied)
        Returns:
        true if there is a pending change to the current sort state
      • isSorted

        public boolean isSorted()
        Returns true if this model has been sorted and does not have a new pending sort that will be applied
        Returns:
        true if sorted
        See Also:
        isSortPending()
      • initializeSorting

        protected void initializeSorting()
        This method is an attempt to help models that forget to call fireTableDataChanged(). It is expected that tables will fire the notification when they are ready to display data, even if they have that data at construction time. We put this call here so that the forgetful subclasses will have their data sorted for them the first time that this table tries to render itself.
      • getIndexForRowObject

        protected int getIndexForRowObject​(T rowObject)
        A convenience method for subclasses to quickly/efficiently search for the index of a given row object that is visible in the GUI. The visible limitation is due to the fact that the data searched is retrieved from RowObjectTableModel.getModelData(), which may be filtered.
        Overrides:
        getIndexForRowObject in class AbstractGTableModel<T>
        Parameters:
        rowObject - The object for which to search.
        Returns:
        the index of the item in the data returned by
      • getIndexForRowObject

        protected int getIndexForRowObject​(T rowObject,
                                           java.util.List<T> data)
        Returns the index for the given object in the given list
        Overrides:
        getIndexForRowObject in class AbstractGTableModel<T>
        Parameters:
        rowObject - the item
        data - the data
        Returns:
        the index
      • sort

        protected void sort​(java.util.List<T> data,
                            TableSortingContext<T> sortingContext)
        A default sort method that uses the Collections.sort(List, Comparator) method for sorting. Implementors with reasonably sized data sets can rely on this method. For data sets that can become large, the ThreadedTableModel is the recommended base class, as it handles loading/sorting/filtering in a threaded way.
        Parameters:
        data - The data to be sorted
        sortingContext - The context required to sort (it contains the sorting columns, a comparator for sorting, etc...).
      • notifyModelSorted

        protected void notifyModelSorted​(boolean dataChanged)
        Fires an event to let the listeners (like JTable) know that things have been changed. This method exists so that subclasses have a way to call the various tableChanged() methods without triggering this class's overridden version.
        Parameters:
        dataChanged - True signals that the actual data has changed; false signals that the data is the same, with exception that attributes of that data may be different.
      • createSortComparator

        protected java.util.Comparator<T> createSortComparator​(int columnIndex)
        An extension point for subclasses to insert their own comparator objects for their data. Subclasses can create comparators for a single or multiple columns, as desired.
        Parameters:
        columnIndex - the column index
        Returns:
        the comparator