Class SelfUpdatingTableModel
java.lang.Object
javax.swing.table.AbstractTableModel
javax.swing.table.DefaultTableModel
com.compomics.util.gui.tablemodels.SelfUpdatingTableModel
- All Implemented Interfaces:
Serializable
,TableModel
public abstract class SelfUpdatingTableModel extends DefaultTableModel
These table models include a self updating function. Due to instability of
the JTable with this model, it comprises a simple row sorter. Use it at your
own risks and feel free to debug.
- Author:
- Marc Vaudel, Harald Barsnes
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description boolean
isScrolling
When true this indicates that the user is currently scrolling in the table and that the table should not update. -
Constructor Summary
Constructors Constructor Description SelfUpdatingTableModel()
-
Method Summary
Modifier and Type Method Description static void
addScrollListeners(JTable table, JScrollPane scrollPane, JScrollBar scrollBar)
Add scroll bar and mouse wheel listeners.static void
addSortListener(JTable jTable, ProgressDialogX progressDialog)
Convenience method adding a row sorter listener to the given JTable.protected abstract void
catchException(Exception e)
This method is called whenever an exception is encountered in a separate thread.protected void
dataMissingAtRow(int row)
Calling this method indicates that data is missing at the given row.int
getRowNumber(int viewIndex)
Returns the row number of the given view index.int
getViewIndex(int row)
Returns the view index of the given row.void
initiateSorter()
Initiates the sorter to the current order of the table.boolean
isScrolling()
Indicates whether the table is currently being scrolled.boolean
isSelfUpdating()
Indicates whether the table is in self update mode.protected abstract int
loadDataForRows(ArrayList<Integer> indexes, WaitingHandler waitingHandler)
Loads the data needed for objects at rows of the given view indexes.boolean
needsUpdate(int column, String waitingContent)
Indicates whether the given column needs an update, i.e.void
resetSorting(ProgressDialogX aProgressDialog)
Sorts the table according to a given column using the built in sorter.void
setIsScrolling(boolean isScrolling)
Set if the user is currently scrolling or not.void
setSelfUpdating(boolean selfUpdating)
Sets whether the table is in self update mode.void
sort(int column, ProgressDialogX aProgressDialog)
Sorts the table according to a given column using the built in sorter.Methods inherited from class javax.swing.table.DefaultTableModel
addColumn, addColumn, addColumn, addRow, addRow, convertToVector, convertToVector, getColumnCount, getColumnName, getDataVector, getRowCount, getValueAt, insertRow, insertRow, isCellEditable, moveRow, newDataAvailable, newRowsAdded, removeRow, rowsRemoved, setColumnCount, setColumnIdentifiers, setColumnIdentifiers, setDataVector, setDataVector, setNumRows, setRowCount, setValueAt
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, removeTableModelListener
-
Field Details
-
isScrolling
public boolean isScrollingWhen true this indicates that the user is currently scrolling in the table and that the table should not update.
-
-
Constructor Details
-
SelfUpdatingTableModel
public SelfUpdatingTableModel()
-
-
Method Details
-
loadDataForRows
Loads the data needed for objects at rows of the given view indexes. Use this method to cache data before working on the given lines.- Parameters:
indexes
- the view indexes to load as a list. Shall not be empty or null.waitingHandler
- the waiting handler- Returns:
- the last updated row
-
catchException
This method is called whenever an exception is encountered in a separate thread.- Parameters:
e
- the exception encountered
-
dataMissingAtRow
protected void dataMissingAtRow(int row)Calling this method indicates that data is missing at the given row. The data will be loaded in a separate thread and the table updated later on.- Parameters:
row
- the row number (not the view index)
-
isSelfUpdating
public boolean isSelfUpdating()Indicates whether the table is in self update mode.- Returns:
- true if the table is in self update mode
-
setSelfUpdating
public void setSelfUpdating(boolean selfUpdating)Sets whether the table is in self update mode.- Parameters:
selfUpdating
- if false the table will not automatically update
-
needsUpdate
Indicates whether the given column needs an update, i.e. whether a cell contains waitingContent.- Parameters:
column
- index of the column of interestwaitingContent
- the waiting content of this table- Returns:
- indicates whether the given column needs an update
-
initiateSorter
public void initiateSorter()Initiates the sorter to the current order of the table. -
getViewIndex
public int getViewIndex(int row)Returns the view index of the given row.- Parameters:
row
- the row of interest- Returns:
- the corresponding view index
-
getRowNumber
public int getRowNumber(int viewIndex)Returns the row number of the given view index.- Parameters:
viewIndex
- view index row of interest- Returns:
- the corresponding row
-
resetSorting
Sorts the table according to a given column using the built in sorter.- Parameters:
aProgressDialog
- a progress dialog used to display the progress and interrupt the process
-
sort
Sorts the table according to a given column using the built in sorter.- Parameters:
column
- the column of interestaProgressDialog
- a progress dialog used to display the progress and interrupt the process
-
addSortListener
Convenience method adding a row sorter listener to the given JTable.- Parameters:
jTable
- the table to add the resetSorting listener toprogressDialog
- progress dialog used to display progress or cancel while sorting. Can be null.
-
isScrolling
public boolean isScrolling()Indicates whether the table is currently being scrolled.- Returns:
- true if the table is currently being scrolled
-
setIsScrolling
public void setIsScrolling(boolean isScrolling)Set if the user is currently scrolling or not.- Parameters:
isScrolling
- the isScrolling to set
-
addScrollListeners
Add scroll bar and mouse wheel listeners.- Parameters:
table
- the tablescrollBar
- the scroll barscrollPane
- the scroll pane
-