JIDE 3.5.15

com.jidesoft.grid
Interface ISortableTableModel

All Superinterfaces:
TableModel
All Known Implementing Classes:
AdvancePageTableModel, CrudDatabaseTableModel, DatabaseTableModel, HibernatePageTableModel, SortableAggregateTableModel, SortableTableModel, SortableTreeTableModel

public interface ISortableTableModel
extends TableModel

An interface to allow you to implement sorting feature on any table model.


Nested Class Summary
static class ISortableTableModel.SortItem
           
 
Field Summary
static int SORT_PRIORITY_FIFO
           
static int SORT_PRIORITY_FILO
           
 
Method Summary
 void addSortListener(SortListener l)
          Adds the specified listener to receive SortEvents pane events from this SortableTableModel.
 int getActualRowAt(int row)
          Gets the actual row.
 int getColumnSortRank(int column)
          In the case of sort by multiple columns, this method will return the rank of this column within all sorted columns.
 int[] getMasterSortColumns()
          Gets the master sort columns.
 int getMaximumSortColumns()
          Gets the maximum columns can be sorted at once.
 int getSortedRowAt(int actualRow)
          Gets the visual row.
 List<ISortableTableModel.SortItem> getSortingColumns()
          Gets the sorting columns.
 SortListener[] getSortListeners()
          Returns an array of all the SortListeners added to this SortableTableModel with addSortListener.
 int getSortPriority()
          Gets the sort priority.
 boolean isColumnAscending(int column)
          Checks if the column is sorted ascendingly.
 boolean isColumnSortable(int column)
          Check if a certain column is sortable.
 boolean isColumnSorted(int column)
          Checks if the column is sorted.
 boolean isMultiColumnSortable()
          Does this table allow sort by multiple columns.
 boolean isSortable()
          Checks if the sortable table model is sortable.
 void removeSortListener(SortListener l)
          Removes the specified SortListener so that it no longer receives SortEvents from this SortableTableModel .
 void reset()
          Resets.
 void resort()
          Resort the table.
 void reverseColumnSortOrder(int column)
          Reverses the sort order of the column.
 void setColumnSortable(int column, boolean sortable)
          Sets a column sortable or not sortable.
 void setMasterSortColumns(int[] masterSortColumns)
          Sets the master sort column.
 void setMaximumSortColumns(int maximumSortColumns)
          Set the maximum number of columns that can be sorted at once.
 void setMultiColumnSortable(boolean multiColumnSortable)
          Set the value if this table allows sort by multiple columns.
 void setSortable(boolean sortable)
          Sets the table model sortable.
 void setSortingColumns(List<ISortableTableModel.SortItem> list)
          Sets the soring columns.
 void setSortPriority(int sortPriority)
          Sets the sort priority.
 void sortColumn(int column)
          Sort the column, equals to sortColumn(column, false).
 void sortColumn(int column, boolean reset)
          If reset is true, it will remove all existing sort-by columns and only sorts by column.
 void sortColumn(int column, boolean reset, boolean ascending)
          Sorts a column.
 void toggleSortOrder(int column, boolean extend)
          Toggles the sort order on the specified column.
 void unsortColumn(int column)
          Unsorts the column.
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnClass, getColumnCount, getColumnName, getRowCount, getValueAt, isCellEditable, removeTableModelListener, setValueAt
 

Field Detail

SORT_PRIORITY_FILO

static final int SORT_PRIORITY_FILO
See Also:
Constant Field Values

SORT_PRIORITY_FIFO

static final int SORT_PRIORITY_FIFO
See Also:
Constant Field Values
Method Detail

getSortedRowAt

int getSortedRowAt(int actualRow)
Gets the visual row.

Parameters:
actualRow - the actual row in actual model.
Returns:
the row on UI. -1 if cannot find the row.

getActualRowAt

int getActualRowAt(int row)
Gets the actual row.

Parameters:
row - the row on the UI.
Returns:
the actual row in the actual model. It will throw IllegalArgumentException if the row is out of range.

sortColumn

void sortColumn(int column)
Sort the column, equals to sortColumn(column, false).

Parameters:
column - column to be sorted

sortColumn

void sortColumn(int column,
                boolean reset)
If reset is true, it will remove all existing sort-by columns and only sorts by column. If reset is false, it will keep existing sort-by columns and add the column as a new sort-by column.

Parameters:
column - the column index.
reset - true to reset all existing sorting columns before sorting the new column.

unsortColumn

void unsortColumn(int column)
Unsorts the column.

Parameters:
column - column to be removed from sort-by columns

reverseColumnSortOrder

void reverseColumnSortOrder(int column)
Reverses the sort order of the column. The column must be one of sorted column, or else the method will do nothing

Parameters:
column - the column index.

sortColumn

void sortColumn(int column,
                boolean reset,
                boolean ascending)
Sorts a column.

Parameters:
column - the column index.
reset - true to reset all existing sorting columns before sorting the new column.
ascending - true to sort ascending. False to sort descending.

isColumnSorted

boolean isColumnSorted(int column)
Checks if the column is sorted.

Parameters:
column - the column index.
Returns:
true if the column is sorted.

isColumnAscending

boolean isColumnAscending(int column)
Checks if the column is sorted ascendingly.

Parameters:
column - the column index.
Returns:
true if column is ascendingly sorted. If it's not sorted or sorted but descending, it will return false.

reset

void reset()
Resets. No columns will be sorted. Nothing will be done if the model was not sorted.


toggleSortOrder

void toggleSortOrder(int column,
                     boolean extend)
Toggles the sort order on the specified column. By default, it will sort the column if not sorted. If sorted ascending, it will change to descending. If descending, it will unsort.

Parameters:
column - the column index.
extend - if true, extend the current sort to add more sorted columns.

getSortingColumns

List<ISortableTableModel.SortItem> getSortingColumns()
Gets the sorting columns. It's a ArrayList. The element in the list is SortItem which has the column index and sorting direction.

Returns:
an ArrayList of sorting columns.

setSortingColumns

void setSortingColumns(List<ISortableTableModel.SortItem> list)
Sets the soring columns. It will do a sort action automatically.

Parameters:
list - a list of SortItems.

getColumnSortRank

int getColumnSortRank(int column)
In the case of sort by multiple columns, this method will return the rank of this column within all sorted columns.

Parameters:
column - the column index.
Returns:
the rank of this column within all sorted columns. -1 is the column is not sorted. 0 means the first rank and so on.

setMasterSortColumns

void setMasterSortColumns(int[] masterSortColumns)
Sets the master sort column. If the master sort columns are set, the row order will only be changed when the master sort columns have the same value. This is used when there are cell spans in certain column and you don't want the sorting to mess up the cell span as those rows will have to stay together.

Parameters:
masterSortColumns - the new master sort columns.

getMasterSortColumns

int[] getMasterSortColumns()
Gets the master sort columns.

Returns:
the master sort columns.

isMultiColumnSortable

boolean isMultiColumnSortable()
Does this table allow sort by multiple columns.

Returns:
true if this table allows sort by multiple columns

setMultiColumnSortable

void setMultiColumnSortable(boolean multiColumnSortable)
Set the value if this table allows sort by multiple columns.

Parameters:
multiColumnSortable - pass in true if this you want this table allows sort by multiple columns

isColumnSortable

boolean isColumnSortable(int column)
Check if a certain column is sortable.

Parameters:
column - the column index.
Returns:
true if this table column is sortable.
See Also:
setColumnSortable(int,boolean)

setColumnSortable

void setColumnSortable(int column,
                       boolean sortable)
Sets a column sortable or not sortable. Please note, you will have to set it again if the table model structure is changed. By default, all columns are sortable.

Parameters:
column - the column index.
sortable - true to make the column sortable.

isSortable

boolean isSortable()
Checks if the sortable table model is sortable.

Returns:
true or false.

setSortable

void setSortable(boolean sortable)
Sets the table model sortable. If the model is not sortable, toggleSortOrder(int,boolean) will have no effect.

Parameters:
sortable - true or false.

resort

void resort()
Resort the table. When autoResort is false, the table will be out of order after data changes. The method will resort the table while keeping the sorting columns.


addSortListener

void addSortListener(SortListener l)
Adds the specified listener to receive SortEvents pane events from this SortableTableModel.

Parameters:
l - the SortListener

removeSortListener

void removeSortListener(SortListener l)
Removes the specified SortListener so that it no longer receives SortEvents from this SortableTableModel .

Parameters:
l - the SortableTableModel listener

getSortListeners

SortListener[] getSortListeners()
Returns an array of all the SortListeners added to this SortableTableModel with addSortListener.

Returns:
all of the SortListeners added or an empty array if no listeners have been added
See Also:
addSortListener(com.jidesoft.grid.SortListener)

getSortPriority

int getSortPriority()
Gets the sort priority.

Returns:
the sort priority. It could be either SORT_PRIORITY_FILO (the default) or SORT_PRIORITY_FIFO.

setSortPriority

void setSortPriority(int sortPriority)
Sets the sort priority. This property only has effect when multiple columns are sorted. When sort priority is FILO (first-in-last-out), the first sorted column has the smallest sort rank (with a number "1" on its column header). If there are more columns being sorted, their sort tank are getting higher based on the the order when they are sorted. Oppositely, when sort priority is FIFO (first-in-first-out), the first sorted column has the sort rank 1. But the moment a new column is sorted, it will get sort rank 1 and push the previous sorted column's sort rank to 2. And so on. If you view it as a queue, you will see it's either a FILO queue or FIFO queue. That's why we call it FIFO or FILO.

Parameters:
sortPriority - must be one the following value: SORT_PRIORITY_FILO (the default), or SORT_PRIORITY_FIFO

getMaximumSortColumns

int getMaximumSortColumns()
Gets the maximum columns can be sorted at once. If user tries to sort another columns when maximum count is met, depending on the value of getSortPriority(), the behavior is different. If sort priority is FILO, nothing will happen when user tries to sort one column. If FIFO, it will push the column with the largest sort rank out.

Returns:
the maximum sorted column number.

setMaximumSortColumns

void setMaximumSortColumns(int maximumSortColumns)
Set the maximum number of columns that can be sorted at once.

Parameters:
maximumSortColumns - the maximum number of columns that can be sorted at once.

JIDE 3.5.15