public class SortableAndSearchableWrapperTableModel extends AbstractTableModel implements TableModelListener, SortableTableModel, SearchableTableModel
Modifier and Type | Class and Description |
---|---|
static class |
SortableAndSearchableWrapperTableModel.SortContainer
Helper class for sorting the columns.
|
Modifier and Type | Field and Description |
---|---|
protected boolean[] |
m_ColumnIsNumeric
whether a column is numeric.
|
protected gnu.trove.list.array.TIntArrayList |
m_DisplayIndices
the indices of the rows to display that match a search string.
|
protected TableModel |
m_Model
the actual table model.
|
protected MouseListener |
m_MouseListener
the mouse listener in use.
|
protected boolean |
m_RegExpSearch
whether the search was a regular expression based one.
|
protected String |
m_SearchString
the string that was searched for.
|
protected boolean |
m_SortAscending
whether sorting is ascending or descending.
|
protected int |
m_SortColumn
the sort column.
|
protected int[] |
m_SortedIndices
the mapping between displayed and actual index.
|
listenerList
Constructor and Description |
---|
SortableAndSearchableWrapperTableModel()
initializes with no model.
|
SortableAndSearchableWrapperTableModel(TableModel model)
initializes with the given model.
|
Modifier and Type | Method and Description |
---|---|
void |
addMouseListenerToHeader(JTable table)
Adds a mouselistener to the header: left-click on the header sorts in
ascending manner, using shift-left-click in descending manner.
|
int |
getActualRow(int visibleRow)
Returns the actual underlying row the given visible one represents.
|
int |
getActualRowCount()
Returns the actual row count in the model.
|
Class |
getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the
column.
|
protected Class |
getColumnClassForComparison(int columnIndex)
Returns the class of the column.
|
int |
getColumnCount()
Returns the number of columns in the model.
|
String |
getColumnName(int columnIndex)
Returns the name of the column at columnIndex.
|
int |
getDisplayRow(int internalRow)
Returns the "visible" row derived from row in the actual table model.
|
MouseListener |
getHeaderMouseListener()
Returns the mouse listener that got assigned to the header, if any.
|
int |
getRowCount()
Returns the number of rows in the model.
|
String |
getSeachString()
Returns the current search string.
|
int |
getSortColumn()
Returns the sort column.
|
TableModel |
getUnsortedModel()
returns the underlying model, can be null.
|
Object |
getValueAt(int rowIndex,
int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.
|
protected Object |
getValueForComparison(int row,
int column)
Returns the value used in the comparison.
|
protected void |
initialize()
Initializes indices etc.
|
protected void |
initializeColumnTypes()
Determines which column is a numeric one (skipped in search).
|
protected void |
initializeSortIndices()
(re-)initializes the indices.
|
boolean |
isAscending()
Returns whether sorting is ascending or not.
|
boolean |
isCellEditable(int rowIndex,
int columnIndex)
Returns true if the cell at rowIndex and columnIndex is editable.
|
protected boolean |
isColumnNumeric(int colIndex)
Returns whether the specified column is numeric.
|
protected boolean |
isInitialized()
whether the model is initialized.
|
boolean |
isRegExpSearch()
Returns whether the last search was a regular expression based one.
|
boolean |
isSearchMatch(SearchParameters params,
int row)
Tests whether the search matches the specified row.
|
boolean |
isSorted()
returns whether the table was sorted.
|
void |
search(String searchString,
boolean regexp)
Performs a search for the given string.
|
void |
setUnsortedModel(TableModel value)
Sets the model to use.
|
void |
setUnsortedModel(TableModel value,
boolean restoreSorting)
Sets the model to use.
|
void |
setValueAt(Object aValue,
int rowIndex,
int columnIndex)
Sets the value in the cell at columnIndex and rowIndex to aValue.
|
void |
sort(int columnIndex)
sorts the table over the given column (ascending).
|
void |
sort(int columnIndex,
boolean ascending)
sorts the table over the given column, either ascending or descending.
|
void |
tableChanged(TableModelEvent e)
This fine grain notification tells listeners the exact range of cells,
rows, or columns that changed.
|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addTableModelListener, removeTableModelListener
protected TableModel m_Model
protected int[] m_SortedIndices
protected int m_SortColumn
protected boolean m_SortAscending
protected MouseListener m_MouseListener
protected String m_SearchString
protected boolean m_RegExpSearch
protected gnu.trove.list.array.TIntArrayList m_DisplayIndices
protected boolean[] m_ColumnIsNumeric
public SortableAndSearchableWrapperTableModel()
public SortableAndSearchableWrapperTableModel(TableModel model)
model
- the model to initialize the sorted model withpublic void setUnsortedModel(TableModel value)
setUnsortedModel
in interface SortableTableModel
value
- the model to usepublic void setUnsortedModel(TableModel value, boolean restoreSorting)
value
- the model to userestoreSorting
- whether to restore the sorting (if any)public TableModel getUnsortedModel()
getUnsortedModel
in interface SortableTableModel
protected void initialize()
protected void initializeColumnTypes()
protected boolean isColumnNumeric(int colIndex)
colIndex
- the index of the columnm_ColumnIsNumeric
,
initializeColumnTypes()
protected void initializeSortIndices()
public boolean isSorted()
isSorted
in interface SortableTableModel
public int getSortColumn()
getSortColumn
in interface SortableTableModel
public boolean isAscending()
isAscending
in interface SortableTableModel
isSorted()
,
getSortColumn()
protected boolean isInitialized()
public int getActualRow(int visibleRow)
getActualRow
in interface SearchableTableModel
getActualRow
in interface SortableTableModel
visibleRow
- the displayed row to retrieve the original row forpublic int getDisplayRow(int internalRow)
getDisplayRow
in interface SortableTableModel
internalRow
- the row in the actual modelpublic Class getColumnClass(int columnIndex)
getColumnClass
in interface TableModel
getColumnClass
in class AbstractTableModel
columnIndex
- the index of the columnpublic int getColumnCount()
getColumnCount
in interface TableModel
public String getColumnName(int columnIndex)
getColumnName
in interface TableModel
getColumnName
in class AbstractTableModel
columnIndex
- the column to retrieve the name forpublic int getRowCount()
getRowCount
in interface TableModel
public Object getValueAt(int rowIndex, int columnIndex)
getValueAt
in interface TableModel
rowIndex
- the rowcolumnIndex
- the columnpublic boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface TableModel
isCellEditable
in class AbstractTableModel
rowIndex
- the rowcolumnIndex
- the columnpublic void setValueAt(Object aValue, int rowIndex, int columnIndex)
setValueAt
in interface TableModel
setValueAt
in class AbstractTableModel
aValue
- the new value of the cellrowIndex
- the rowcolumnIndex
- the columnprotected Class getColumnClassForComparison(int columnIndex)
columnIndex
- the index of the columnpublic void sort(int columnIndex)
sort
in interface SortableTableModel
columnIndex
- the column to sort overpublic void sort(int columnIndex, boolean ascending)
sort
in interface SortableTableModel
columnIndex
- the column to sort overascending
- ascending if true, otherwise descendingprotected Object getValueForComparison(int row, int column)
row
- the row of the cellcolumn
- the column of the cellpublic void tableChanged(TableModelEvent e)
tableChanged
in interface TableModelListener
e
- the eventpublic void addMouseListenerToHeader(JTable table)
table
- the table to add the listener topublic MouseListener getHeaderMouseListener()
public int getActualRowCount()
getActualRowCount
in interface SearchableTableModel
public boolean isSearchMatch(SearchParameters params, int row)
params
- the search parametersrow
- the row of the underlying, unsorted modelpublic void search(String searchString, boolean regexp)
search
in interface SearchableTableModel
searchString
- the string to search forregexp
- whether to perform regular expression matching
or just plain string comparisonpublic String getSeachString()
getSeachString
in interface SearchableTableModel
public boolean isRegExpSearch()
isRegExpSearch
in interface SearchableTableModel
Copyright © 2017. All Rights Reserved.