Package org.apache.jorphan.gui

# Class ObjectTableSorter

java.lang.Object
javax.swing.RowSorter<ObjectTableModel>
org.apache.jorphan.gui.ObjectTableSorter

public class ObjectTableSorter extends RowSorter<ObjectTableModel>
Implementation of a `RowSorter` for `ObjectTableModel`

Since:
  3.2

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected class`
`ObjectTableSorter.PreserveLastRowComparator`
`class`
`ObjectTableSorter.Row`
View row with model mapping.

## Nested classes/interfaces inherited from class javax.swing.RowSorter

`RowSorter.SortKey`

## Constructor Summary

Constructors
Constructor
Description
`ObjectTableSorter(ObjectTableModel model)`

## Method Summary

Modifier and Type
Method
Description
`void`
`allRowsChanged()`
`int`
`convertRowIndexToModel(int index)`
`int`
`convertRowIndexToView(int index)`
`ObjectTableSorter`
`fixLastRow()`
Sets `primary comparator` to one that don't sort last row.
`protected Comparator<ObjectTableSorter.Row>`
`getComparatorFromSortKey(RowSorter.SortKey sortkey)`
`protected Comparator<?>`
`getDefaultComparator(int column)`
Builds a default comparator based on model column class.
`Comparator<ObjectTableSorter.Row>`
`getFallbackComparator()`
Returns Comparator if all sorted columns matches.
`ObjectTableModel`
`getModel()`
`int`
`getModelRowCount()`
`Comparator<ObjectTableSorter.Row>`
`getPrimaryComparator()`
Returns Comparator used prior to sorted columns.
`List<? extends RowSorter.SortKey>`
`getSortKeys()`
`Comparator<?>`
`getValueComparator(int column)`
Returns Comparator used on column.
`int`
`getViewRowCount()`
`protected void`
`invalidate()`
`protected boolean`
`isSortable(int column)`
`protected boolean`
`isSorted()`
`protected boolean`
`isSorted(int column)`
`void`
`modelStructureChanged()`
`protected void`
`rowsChanged(int firstRow, int endRow, boolean deleted, boolean inserted)`
`void`
`rowsDeleted(int firstRow, int endRow)`
`void`
`rowsInserted(int firstRow, int endRow)`
`void`
`rowsUpdated(int firstRow, int endRow)`
`void`
`rowsUpdated(int firstRow, int endRow, int column)`
`ObjectTableSorter`
`setFallbackComparator(Comparator<ObjectTableSorter.Row> comparator)`
Sets a fallback comparator (defaults to model index comparison) if none `primary`, neither `column value comparators` can make differences between two rows.
`ObjectTableSorter`
`setPrimaryComparator(Comparator<ObjectTableSorter.Row> primaryComparator)`
Comparator used prior to sorted columns.
`void`
`setSortKey(RowSorter.SortKey sortkey)`
`void`
`setSortKeys(List<? extends RowSorter.SortKey> keys)`
`ObjectTableSorter`
`setValueComparator(int column, Comparator<?> comparator)`
Assign comparator to given column, if `null` a getDefaultComparator(int) default one is used instead.
`protected void`
`sort()`
Sort table
`void`
`toggleSortOrder(int column)`
`protected void`
`updateModelToView()`
fill in modelToView list with index of view
`protected void`
`validate()`

### Methods inherited from class javax.swing.RowSorter

`addRowSorterListener, fireRowSorterChanged, fireSortOrderChanged, removeRowSorterListener`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ObjectTableSorter

public ObjectTableSorter(ObjectTableModel model)

## Method Details

### getPrimaryComparator

public Comparator<ObjectTableSorter.Row> getPrimaryComparator()
Returns Comparator used prior to sorted columns.

Returns:
  Comparator used prior to sorted columns.

### getValueComparator

public Comparator<?> getValueComparator(int column)
Returns Comparator used on column.

Parameters:
  `column` - to be compared
Returns:
  Comparator used on column.

### getFallbackComparator

public Comparator<ObjectTableSorter.Row> getFallbackComparator()
Returns Comparator if all sorted columns matches. Defaults to model index comparison.

Returns:
  Comparator if all sorted columns matches. Defaults to model index comparison.

### setPrimaryComparator

public ObjectTableSorter setPrimaryComparator(Comparator<ObjectTableSorter.Row> primaryComparator)
Comparator used prior to sorted columns.

Parameters:
  `primaryComparator` - `Comparator` to be used first
Returns:
  `this`

### fixLastRow

public ObjectTableSorter fixLastRow()
Sets `primary comparator` to one that don't sort last row.

Returns:
  `this`

### setValueComparator

public ObjectTableSorter setValueComparator(int column, Comparator<?> comparator)
Assign comparator to given column, if `null` a getDefaultComparator(int) default one is used instead.

Parameters:
  `column` - Model column index.
  `comparator` - Column value comparator.
Returns:
  `this`

### getDefaultComparator

protected Comparator<?> getDefaultComparator(int column)
Builds a default comparator based on model column class. `Collator.getInstance()` for `String`, `natural order` for `Comparable`, no sort support for others.

Parameters:
  `column` - Model column index.
Returns:
  default `Comparator`

### setFallbackComparator

public ObjectTableSorter setFallbackComparator(Comparator<ObjectTableSorter.Row> comparator)
Sets a fallback comparator (defaults to model index comparison) if none `primary`, neither `column value comparators` can make differences between two rows.

Parameters:
  `comparator` - to be used, when all other `Comparator`s can't see a difference
Returns:
  `this`

### getModel

public ObjectTableModel getModel()

Specified by:
  `getModel` in class `RowSorter<ObjectTableModel>`

### toggleSortOrder

public void toggleSortOrder(int column)

Specified by:
  `toggleSortOrder` in class `RowSorter<ObjectTableModel>`

### convertRowIndexToModel

public int convertRowIndexToModel(int index)

Specified by:
  `convertRowIndexToModel` in class `RowSorter<ObjectTableModel>`

### convertRowIndexToView

public int convertRowIndexToView(int index)

Specified by:
  `convertRowIndexToView` in class `RowSorter<ObjectTableModel>`

### setSortKeys

public void setSortKeys(List<? extends RowSorter.SortKey> keys)

Specified by:
  `setSortKeys` in class `RowSorter<ObjectTableModel>`

### setSortKey

public void setSortKey(RowSorter.SortKey sortkey)

### getSortKeys

public List<? extends RowSorter.SortKey> getSortKeys()

Specified by:
  `getSortKeys` in class `RowSorter<ObjectTableModel>`

### getViewRowCount

public int getViewRowCount()

Specified by:
  `getViewRowCount` in class `RowSorter<ObjectTableModel>`

### getModelRowCount

public int getModelRowCount()

Specified by:
  `getModelRowCount` in class `RowSorter<ObjectTableModel>`

### modelStructureChanged

public void modelStructureChanged()

Specified by:
  `modelStructureChanged` in class `RowSorter<ObjectTableModel>`

### allRowsChanged

public void allRowsChanged()

Specified by:
  `allRowsChanged` in class `RowSorter<ObjectTableModel>`

### rowsInserted

public void rowsInserted(int firstRow, int endRow)

Specified by:
  `rowsInserted` in class `RowSorter<ObjectTableModel>`

### rowsDeleted

public void rowsDeleted(int firstRow, int endRow)

Specified by:
  `rowsDeleted` in class `RowSorter<ObjectTableModel>`

### rowsUpdated

public void rowsUpdated(int firstRow, int endRow)

Specified by:
  `rowsUpdated` in class `RowSorter<ObjectTableModel>`

### rowsChanged

protected void rowsChanged(int firstRow, int endRow, boolean deleted, boolean inserted)

### rowsUpdated

public void rowsUpdated(int firstRow, int endRow, int column)

Specified by:
  `rowsUpdated` in class `RowSorter<ObjectTableModel>`

### isSortable

protected boolean isSortable(int column)

### isSorted

protected boolean isSorted(int column)

### isSorted

protected boolean isSorted()

### invalidate

protected void invalidate()

### validate

protected void validate()

### getComparatorFromSortKey

protected Comparator<ObjectTableSorter.Row> getComparatorFromSortKey(RowSorter.SortKey sortkey)

### sort

protected void sort()
Sort table

### updateModelToView

protected void updateModelToView()
fill in modelToView list with index of view