Package com.portal.pfc.ui.table
Class SortTableController
java.lang.Object
javax.swing.table.AbstractTableModel
com.portal.pfc.ui.table.SortTableModel
com.portal.pfc.ui.table.SortTableController
- All Implemented Interfaces:
Serializable,EventListener,TableModelListener,TableModel
A controller class for sorting a SortTableModel. SortTableController keeps
an internal array of integers, which point to the actual data model in
SortTableModel. Sorting is accomplished by re-ordering this internal array
of integers.
- Author:
- Les Thomas
- See Also:
-
Field Summary
Fields inherited from class com.portal.pfc.ui.table.SortTableModel
mModelFields inherited from class javax.swing.table.AbstractTableModel
listenerList -
Constructor Summary
ConstructorsConstructorDescriptionDefault Constructor.SortTableController(TableModel model) Constructs a SortTableController object using the specified model. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSortTableHeaderListener(JTable table) Add a mouse listener to the Table, in order to trigger a table sort when a column header is clicked.voidForwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.intgetDataRow(int row) Return the sort row index for the given table row.intReturns the index of the last column sorted.booleanReturns the last sort order.Return mouse listener associated with SortTableController.getValueAt(int rowIndex, int columnIndex) Returns the value for the cell at columnIndex and rowIndex.voidreSort(TableColumnModel columnModel) Resort the table based upon the specified column model.voidreSort(TableColumnModel columnModel, int viewColumnIndex) Resorts the table based upon the specified column model and the view column index.voidrestoreDataPosition(JTable table) Restores the selected row in a table, after the data has been sorted.voidsaveDataPosition(JTable table) Concatenates and stores the data from a selected row in a table.voidsetColumnHeader(TableColumnModel model, int columnIndex) Sets the column header, based upon the specified index, to indicate whether the specified column is being sorted.voidsetCompare(Class c, Comparator compare) Allows the user to set a Comparator for an object.voidsetLastColumnSorted(int columnIndex) Sets the last column sorted, based upon the specified index.voidsetLastSortOrder(boolean sortOrder) Sets the last sort order, based upon the specified value.voidsetModel(TableModel model) Sets the model for the SortTableController.voidsetValueAt(Object aValue, int rowIndex, int columnIndex) Sets the value in the cell at columnIndex and rowIndex to aValue.voidsort_column(int columnIndex, boolean sort_ascending) Sort the specified column, in the specified order.voidtableChanged(TableModelEvent event) Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.Methods inherited from class com.portal.pfc.ui.table.SortTableModel
getColumnClass, getColumnCount, getColumnName, getModel, getRowCount, isCellEditableMethods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
Constructor Details
-
SortTableController
public SortTableController()Default Constructor. setModel must be called in order for SortTableController to be properly initialized. -
SortTableController
Constructs a SortTableController object using the specified model.- Parameters:
model- TableModel
-
-
Method Details
-
setModel
Sets the model for the SortTableController.- Overrides:
setModelin classSortTableModel- Parameters:
model- TableModel
-
fireTableChangedEvent
Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.- Parameters:
e- the event to be forwarded.
-
tableChanged
Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.- Specified by:
tableChangedin interfaceTableModelListener- Overrides:
tableChangedin classSortTableModel- Parameters:
e- the event to be forwarded.
-
getLastColumnSorted
public int getLastColumnSorted()Returns the index of the last column sorted.- Returns:
- the column index.
-
setLastColumnSorted
public void setLastColumnSorted(int columnIndex) Sets the last column sorted, based upon the specified index.- Parameters:
col- the column index
-
getLastSortOrder
public boolean getLastSortOrder()Returns the last sort order.- Returns:
- true (ascending), false (descending)
-
setLastSortOrder
public void setLastSortOrder(boolean sortOrder) Sets the last sort order, based upon the specified value.- Parameters:
sortOrder- true (ascending), false (descending).
-
getValueAt
Returns the value for the cell at columnIndex and rowIndex. A check will be made to determine whether the sort index length is equal to the table model's row count.- Specified by:
getValueAtin interfaceTableModel- Overrides:
getValueAtin classSortTableModel- Parameters:
rowIndex- the row whose value is to be queried.columnIndex- the column whose value is to be queried.row- the row whose value is to be queried.column- the column whose value is to be queried.- Returns:
- the value Object at the specified cell.
-
setValueAt
Sets the value in the cell at columnIndex and rowIndex to aValue. A check will be made to determine whether the sort index length is equal to the table model's row count.- Specified by:
setValueAtin interfaceTableModel- Overrides:
setValueAtin classSortTableModel- Parameters:
aValue- the new value.rowIndex- the row whose value is to be changed.columnIndex- the column whose value is to be changed.
-
getDataRow
public int getDataRow(int row) Return the sort row index for the given table row. A check will be made to determine whether the sort index length is equal to the table model's row count.- Parameters:
row- the table row.- Returns:
- the sorted index for the given table row.
-
reSort
Resort the table based upon the specified column model.- Parameters:
columnModel- Table column model.
-
reSort
Resorts the table based upon the specified column model and the view column index.- Parameters:
columnModel- Table column model.viewColumn- view column index.
-
sort_column
public void sort_column(int columnIndex, boolean sort_ascending) Sort the specified column, in the specified order.- Parameters:
column- index of column to be sorted.mSortAscending- sort order, ascending (true), descending (false).
-
addSortTableHeaderListener
Add a mouse listener to the Table, in order to trigger a table sort when a column header is clicked.- Parameters:
table- Table to be sorted.
-
setColumnHeader
Sets the column header, based upon the specified index, to indicate whether the specified column is being sorted.- Parameters:
model- TableColumn modelcolumnIndex- the column index
-
saveDataPosition
Concatenates and stores the data from a selected row in a table.This will be used to restore the selected row after the data is sorted.
- Parameters:
table- Table which contains the selected row.
-
restoreDataPosition
Restores the selected row in a table, after the data has been sorted.Each row in the table is concatenated and compared with sSortPositionMap. When a match is found, the row is selected.
- Parameters:
table- Table which contains the selected row.
-
getMouseListener
Return mouse listener associated with SortTableController.- Returns:
- listener.
-
setCompare
Allows the user to set a Comparator for an object.- Parameters:
c- the object that the Comparator applies tocompare- the comparator for the given class
-