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, removeTableModelListenerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddTableModelListener, removeTableModelListenerprotected 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 SortableTableModelvalue - 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 SortableTableModelprotected 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 SortableTableModelpublic int getSortColumn()
getSortColumn in interface SortableTableModelpublic boolean isAscending()
isAscending in interface SortableTableModelisSorted(),
getSortColumn()protected boolean isInitialized()
public int getActualRow(int visibleRow)
getActualRow in interface SearchableTableModelgetActualRow in interface SortableTableModelvisibleRow - the displayed row to retrieve the original row forpublic int getDisplayRow(int internalRow)
getDisplayRow in interface SortableTableModelinternalRow - the row in the actual modelpublic Class getColumnClass(int columnIndex)
getColumnClass in interface TableModelgetColumnClass in class AbstractTableModelcolumnIndex - the index of the columnpublic int getColumnCount()
getColumnCount in interface TableModelpublic String getColumnName(int columnIndex)
getColumnName in interface TableModelgetColumnName in class AbstractTableModelcolumnIndex - the column to retrieve the name forpublic int getRowCount()
getRowCount in interface TableModelpublic Object getValueAt(int rowIndex, int columnIndex)
getValueAt in interface TableModelrowIndex - the rowcolumnIndex - the columnpublic boolean isCellEditable(int rowIndex,
int columnIndex)
isCellEditable in interface TableModelisCellEditable in class AbstractTableModelrowIndex - the rowcolumnIndex - the columnpublic void setValueAt(Object aValue, int rowIndex, int columnIndex)
setValueAt in interface TableModelsetValueAt in class AbstractTableModelaValue - 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 SortableTableModelcolumnIndex - the column to sort overpublic void sort(int columnIndex,
boolean ascending)
sort in interface SortableTableModelcolumnIndex - 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 TableModelListenere - the eventpublic void addMouseListenerToHeader(JTable table)
table - the table to add the listener topublic MouseListener getHeaderMouseListener()
public int getActualRowCount()
getActualRowCount in interface SearchableTableModelpublic 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 SearchableTableModelsearchString - the string to search forregexp - whether to perform regular expression matching
or just plain string comparisonpublic String getSeachString()
getSeachString in interface SearchableTableModelpublic boolean isRegExpSearch()
isRegExpSearch in interface SearchableTableModelCopyright © 2017. All Rights Reserved.