Class SortTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- com.inductiveautomation.ignition.client.util.gui.table.SortTableModel
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.EventListener
,javax.swing.event.TableModelListener
,javax.swing.table.TableModel
public class SortTableModel extends javax.swing.table.AbstractTableModel implements javax.swing.event.TableModelListener
A sorter for TableModels. The sorter has a model (conforming to TableModel) and itself implements TableModel. TableSorter does not store or copy the data in the TableModel, instead it maintains an array of integers which it keeps the same size as the number of rows in its model. When the model changes it notifies the sorter that something has changed eg. "rowsAdded" so that its internal array of integers can be reallocated. As requests are made of the sorter (like getValueAt(row, col) it redirects them to its model via the mapping array. That way the TableSorter appears to hold another copy of the table with the rows in a different order. The sorting algorthm used is stable which means that it does not move around rows when its comparison function returns 0 to denote that they are equivalent.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SortTableModel(javax.swing.table.AbstractTableModel delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
_sortOrig()
Re-allocates the indexes array to be a straight sort: matching the original sort order of the tablevoid
addMouseListenerToHeaderInTable(javax.swing.JTable table)
void
checkModel()
int
compare(int row1, int row2)
int
compareRowsByColumn(int row1, int row2, int column)
int
findColumn(java.lang.String columnName)
java.lang.Class<?>
getColumnClass(int columnIndex)
int
getColumnCount()
java.lang.String
getColumnName(int column)
int[]
getIndexes()
Returns an array of integers, which are the indexes of the actual data rows in the current sort orderint
getRowCount()
java.lang.Object
getValueAt(int aRow, int aColumn)
boolean
isCellEditable(int rowIndex, int columnIndex)
boolean
isRetainSortOnChange()
void
reallocateIndexes()
void
setRetainSortOnChange(boolean b)
void
setValueAt(java.lang.Object aValue, int aRow, int aColumn)
void
sortByColumn(int column, boolean ascending)
void
sortOriginal()
void
tableChanged(javax.swing.event.TableModelEvent e)
int
translateIndexToRow(int row)
Translates a row index as the underlying model knows it to a row as the JTable view sees it.int
translateRowToIndex(int index)
Translates a row as the JTable view reports it to a model index of the underlying model-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Method Detail
-
compareRowsByColumn
public int compareRowsByColumn(int row1, int row2, int column)
-
compare
public int compare(int row1, int row2)
-
reallocateIndexes
public void reallocateIndexes()
-
tableChanged
public void tableChanged(javax.swing.event.TableModelEvent e)
- Specified by:
tableChanged
in interfacejavax.swing.event.TableModelListener
-
checkModel
public void checkModel()
-
getValueAt
public java.lang.Object getValueAt(int aRow, int aColumn)
- Specified by:
getValueAt
in interfacejavax.swing.table.TableModel
-
setValueAt
public void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
- Specified by:
setValueAt
in interfacejavax.swing.table.TableModel
- Overrides:
setValueAt
in classjavax.swing.table.AbstractTableModel
-
translateIndexToRow
public int translateIndexToRow(int row)
Translates a row index as the underlying model knows it to a row as the JTable view sees it.
-
translateRowToIndex
public int translateRowToIndex(int index)
Translates a row as the JTable view reports it to a model index of the underlying model
-
_sortOrig
public void _sortOrig()
Re-allocates the indexes array to be a straight sort: matching the original sort order of the table
-
getIndexes
public int[] getIndexes()
Returns an array of integers, which are the indexes of the actual data rows in the current sort order
-
sortOriginal
public void sortOriginal()
-
sortByColumn
public void sortByColumn(int column, boolean ascending)
-
addMouseListenerToHeaderInTable
public void addMouseListenerToHeaderInTable(javax.swing.JTable table)
-
getColumnCount
public int getColumnCount()
- Specified by:
getColumnCount
in interfacejavax.swing.table.TableModel
-
getRowCount
public int getRowCount()
- Specified by:
getRowCount
in interfacejavax.swing.table.TableModel
-
findColumn
public int findColumn(java.lang.String columnName)
- Overrides:
findColumn
in classjavax.swing.table.AbstractTableModel
-
getColumnClass
public java.lang.Class<?> getColumnClass(int columnIndex)
- Specified by:
getColumnClass
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnClass
in classjavax.swing.table.AbstractTableModel
-
getColumnName
public java.lang.String getColumnName(int column)
- Specified by:
getColumnName
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnName
in classjavax.swing.table.AbstractTableModel
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)
- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classjavax.swing.table.AbstractTableModel
-
isRetainSortOnChange
public boolean isRetainSortOnChange()
-
setRetainSortOnChange
public void setRetainSortOnChange(boolean b)
-
-