JIDE 3.5.15

com.jidesoft.grid
Class SortItemSupport

java.lang.Object
  extended by com.jidesoft.grid.SortItemSupport

public class SortItemSupport
extends Object

TableModel used by SortableTable.


Nested Class Summary
static interface SortItemSupport.SortOrderHandler
          A handler to handle the toggling of sort order.
 
Field Summary
protected  List<ISortableTableModel.SortItem> _sortingColumns
          The List that keeps the list of SortItem(s).
 
Constructor Summary
SortItemSupport()
          Creates a SortableTableModel from any table model.
 
Method Summary
protected  void addSortItem(ISortableTableModel.SortItem sortItem)
           
 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 getMasterSortColumnIndex(int column)
           
 int[] getMasterSortColumns()
          Gets the master sort columns.
 int getMaximumSortColumns()
          Gets the maximum columns can be sorted at once.
 List<ISortableTableModel.SortItem> getSortingColumns()
          Gets the sorting columns.
 SortItemSupport.SortOrderHandler getSortOrderHandler()
          Gets the SortOrderHandler.
 int getSortPriority()
          Gets the sort priority.
 boolean isColumnAscending(int column)
          Checks if the column is sorted ascendingly.
 boolean isColumnSorted(int column)
          Checks if the column is sorted.
protected  boolean isEmpty()
           
 boolean isMultiColumnSortable()
          Does this table allow sort by multiple columns.
 boolean isSortable()
          Checks if the sortable table model is sortable.
 boolean reset()
          Resets.
 boolean reverseColumnSortOrder(int column)
          Reverses the sort order of the column.
 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 setSortOrderHandler(SortItemSupport.SortOrderHandler sortOrderHandler)
          Sets the SortOrderHandler.
 void setSortPriority(int sortPriority)
          Sets the sort priority.
 boolean sortColumn(int column)
          Sort the column, equals to sortColumn(column, false).
 boolean sortColumn(int column, boolean reset)
          If reset is true, it will remove all existing sort-by columns and only sorts by column.
 boolean sortColumn(int column, boolean reset, boolean ascending)
          Sorts a column.
 void toggleSortOrder(int column, boolean extend)
          Toggles the sort order on the specified column.
 boolean unsortColumn(int column)
          Unsort column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sortingColumns

protected List<ISortableTableModel.SortItem> _sortingColumns
The List that keeps the list of SortItem(s).

Constructor Detail

SortItemSupport

public SortItemSupport()
Creates a SortableTableModel from any table model.

Method Detail

getMasterSortColumns

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

Returns:
the master sort columns.

setMasterSortColumns

public 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.

getMasterSortColumnIndex

public int getMasterSortColumnIndex(int column)

addSortItem

protected void addSortItem(ISortableTableModel.SortItem sortItem)

sortColumn

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

Parameters:
column - column to be sorted
Returns:
true if the column is sorted. False is the column is already sorted.

sortColumn

public boolean 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.
Returns:
true if the column is sorted. False is the column is already sorted.

unsortColumn

public boolean unsortColumn(int column)
Unsort column.

Parameters:
column - column to be removed from sort-by columns
Returns:
true if the column is unsorted. Otherwise false.

reverseColumnSortOrder

public boolean 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.
Returns:
true if the sort order is reversed. Otherwise false.

sortColumn

public boolean 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.
Returns:
true if the column is sorted. False is the column is already sorted.

isColumnSorted

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

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

isColumnAscending

public 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

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

Returns:
true if it is reset. False if there is nothing to reset.

isEmpty

protected boolean isEmpty()

getSortingColumns

public 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

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

Parameters:
list - a list of SortItems.

getColumnSortRank

public 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.

isMultiColumnSortable

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

Returns:
true if this table allows sort by multiple columns

setMultiColumnSortable

public 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

isSortable

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

Returns:
true or false.

setSortable

public 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.

getSortPriority

public int getSortPriority()
Gets the sort priority.

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

setSortPriority

public 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 sortpriorityy 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

public 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

public 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.

getSortOrderHandler

public SortItemSupport.SortOrderHandler getSortOrderHandler()
Gets the SortOrderHandler.

Returns:
the SortOrderHandler.

setSortOrderHandler

public void setSortOrderHandler(SortItemSupport.SortOrderHandler sortOrderHandler)
Sets the SortOrderHandler.

Parameters:
sortOrderHandler - a new SortOrderHandler.
See Also:
toggleSortOrder(int,boolean)

toggleSortOrder

public 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.

See default implementation below.


  if (isMultiColumnSortable() && extend) {
      if (!isColumnSorted(column))
          sortColumn(column, false, true);
      else if (isColumnAscending(column))
          reverseColumnSortOrder(column);
      else
          unsortColumn(column);
  }
  else {
      if (!isColumnSorted(column))
          sortColumn(column, true, true);
      else if (isColumnAscending(column))
          reverseColumnSortOrder(column);
      else
          reset();
  }
  

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

JIDE 3.5.15