Package com.nuix.nx.models
Class DynamicTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- com.nuix.nx.models.DynamicTableModel
-
- All Implemented Interfaces:
java.io.Serializable
,javax.swing.table.TableModel
public class DynamicTableModel extends javax.swing.table.AbstractTableModel
Table model used to store data for aDynamicTableControl
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DynamicTableModel(java.util.List<java.lang.String> headers, java.util.List<java.lang.Object> records, DynamicTableValueCallback valueCallback, boolean defaultCheckState)
Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRecord(java.lang.Object record)
Adds a single recordvoid
checkDisplayedRecords()
Sets the checked state of the currently displayed records to checked.ChoiceTableModelChangeListener
getChangeListener()
Get the listener which will be notified whn changes are made.java.util.Set<java.lang.String>
getCheckedRecordHashes()
Gets the MD5 hashes for all the currently checked records usinggetRecordHashes(java.util.List<java.lang.Object>)
java.util.List<java.lang.Object>
getCheckedRecords()
Gets a list of records which are checked, regardless of whether they are currently displayedint
getCheckedValueCount()
Gets a count of how many records are currently checkedjava.lang.Class<?>
getColumnClass(int columnIndex)
int
getColumnCount()
java.lang.String
getColumnName(int columnIndex)
java.util.List<DynamicTableFilterProvider>
getCustomFilterProviders()
Gets the list of filter providers beyond those that are built in, allowing you to add or remove custom filter providers.protected java.util.Set<java.lang.String>
getRecordHashes(java.util.List<java.lang.Object> records)
Generates a series of hashes representing each record by callinghashRecord(Object)
on each record.java.util.List<java.lang.Object>
getRecords()
Gets the records associatedint
getRowCount()
int
getTotalValueCount()
Gets the total count of records, regardless of check state or display statejava.lang.Object
getValueAt(int rowIndex, int columnIndex)
DynamicTableValueCallback
getValueCallback()
A reference to the callback used for retrieving values for display.int
getVisibleValueCount()
Gets the count of records which are currently displayed.protected java.lang.String
hashRecord(java.lang.Object record)
Hashes a record by the values in its columns.boolean
isCellEditable(int rowIndex, int columnIndex)
boolean
isSelected(java.lang.Object record)
Used to determine whether a given record is checked in the tablevoid
remove(int rowIndex)
Remove a record at a specified indexvoid
removeChangeListener(ChoiceTableModelChangeListener listener)
void
setChangeListener(ChoiceTableModelChangeListener listener)
Set a listener which will be notified when changes are madevoid
setCheckedAtIndex(int index, boolean value)
Set the checked state of a record at a given indexvoid
setCheckedRecordsFromHashes(java.util.List<java.lang.String> hashStrings)
Sets the checked state of loaded records to checked for records with MD5 hash values matching those in the provided list.void
setColumnEditable(int column)
Allows caller to define whether a given column is allowed to be editable.void
setColumnName(int columnIndex, java.lang.String updatedValue)
void
setCustomFilterProviders(java.util.List<DynamicTableFilterProvider> customFilterProviders)
Sets the list of filter providers beyond those that are built in.void
setDefaultCheckState(boolean defaultCheckState)
Sets the default checked state of recordsvoid
setFilter(java.lang.String filter)
Set the current filter stringvoid
setRecords(java.util.List<java.lang.Object> records)
Sets the records associatedvoid
setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
int[]
shiftRows(int[] positions, int offset)
Shifts a given set of rows (based on row index) a given offset.int[]
shiftRowsDown(int[] positions)
Shift a series of rows down 1int[]
shiftRowsUp(int[] positions)
Shift a series of rows up 1void
uncheckDisplayedRecords()
Sets the checked state of the currently displayed records to unchecked.-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Constructor Detail
-
DynamicTableModel
public DynamicTableModel(java.util.List<java.lang.String> headers, java.util.List<java.lang.Object> records, DynamicTableValueCallback valueCallback, boolean defaultCheckState)
Create a new instance- Parameters:
headers
- The headers for each columnrecords
- A collection of records to be displayedvalueCallback
- Callback that yields a value for a cell given a particular record and column numberdefaultCheckState
- Determines whether by default are records checked
-
-
Method Detail
-
setChangeListener
public void setChangeListener(ChoiceTableModelChangeListener listener)
Set a listener which will be notified when changes are made- Parameters:
listener
- The listener to be notified of changes
-
getChangeListener
public ChoiceTableModelChangeListener getChangeListener()
Get the listener which will be notified whn changes are made.- Returns:
- the listener that is notified of changes
-
removeChangeListener
public void removeChangeListener(ChoiceTableModelChangeListener listener)
-
getValueCallback
public DynamicTableValueCallback getValueCallback()
A reference to the callback used for retrieving values for display.- Returns:
DynamicTableValueCallback
used to get the values displayed in the table
-
getColumnCount
public int getColumnCount()
-
getRowCount
public int getRowCount()
-
getValueAt
public java.lang.Object getValueAt(int rowIndex, int columnIndex)
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)
- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classjavax.swing.table.AbstractTableModel
-
setValueAt
public void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
- Specified by:
setValueAt
in interfacejavax.swing.table.TableModel
- Overrides:
setValueAt
in classjavax.swing.table.AbstractTableModel
-
getColumnName
public java.lang.String getColumnName(int columnIndex)
- Specified by:
getColumnName
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnName
in classjavax.swing.table.AbstractTableModel
-
setColumnName
public void setColumnName(int columnIndex, java.lang.String updatedValue)
-
getColumnClass
public java.lang.Class<?> getColumnClass(int columnIndex)
- Specified by:
getColumnClass
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnClass
in classjavax.swing.table.AbstractTableModel
-
setFilter
public void setFilter(java.lang.String filter)
Set the current filter string- Parameters:
filter
- The filter string to use
-
isSelected
public boolean isSelected(java.lang.Object record)
Used to determine whether a given record is checked in the table- Parameters:
record
- The record to check for- Returns:
- True if the record is present and found to be checked
-
getRecords
public java.util.List<java.lang.Object> getRecords()
Gets the records associated- Returns:
- The current full set of records
-
setRecords
public void setRecords(java.util.List<java.lang.Object> records)
Sets the records associated- Parameters:
records
- The records to associate
-
addRecord
public void addRecord(java.lang.Object record)
Adds a single record- Parameters:
record
- The record to add
-
remove
public void remove(int rowIndex)
Remove a record at a specified index- Parameters:
rowIndex
- The index of the row containing the record to remove
-
setCheckedAtIndex
public void setCheckedAtIndex(int index, boolean value)
Set the checked state of a record at a given index- Parameters:
index
- The index to set the checked state ofvalue
- The checked state to set
-
checkDisplayedRecords
public void checkDisplayedRecords()
Sets the checked state of the currently displayed records to checked. If no filtering is currently applied this is all records, otherwise it will be just the filtered subset.
-
uncheckDisplayedRecords
public void uncheckDisplayedRecords()
Sets the checked state of the currently displayed records to unchecked. If no filtering is currently applied this is all records, otherwise it will be just the filtered subset.
-
getCheckedRecords
public java.util.List<java.lang.Object> getCheckedRecords()
Gets a list of records which are checked, regardless of whether they are currently displayed- Returns:
- A list of checked records
-
hashRecord
protected java.lang.String hashRecord(java.lang.Object record)
Hashes a record by the values in its columns. Used to store settings to JSON- Parameters:
record
- The record to hash- Returns:
- An MD5 string based on a concatenation of the column values
-
getRecordHashes
protected java.util.Set<java.lang.String> getRecordHashes(java.util.List<java.lang.Object> records)
Generates a series of hashes representing each record by callinghashRecord(Object)
on each record.- Parameters:
records
- The record to generate hashes for.- Returns:
- A Set of distinct MD5 hash strings
-
getCheckedRecordHashes
public java.util.Set<java.lang.String> getCheckedRecordHashes()
Gets the MD5 hashes for all the currently checked records usinggetRecordHashes(java.util.List<java.lang.Object>)
- Returns:
- MD5 hashes for all the currently checked records
-
setCheckedRecordsFromHashes
public void setCheckedRecordsFromHashes(java.util.List<java.lang.String> hashStrings)
Sets the checked state of loaded records to checked for records with MD5 hash values matching those in the provided list. Used to restore a selection of items which has previously been saved.- Parameters:
hashStrings
- The MD5 hashes to match to records to be checked
-
getCheckedValueCount
public int getCheckedValueCount()
Gets a count of how many records are currently checked- Returns:
- The checked record count
-
getVisibleValueCount
public int getVisibleValueCount()
Gets the count of records which are currently displayed. If no filtering is currently applied this will be to total record count. If filtering is currently applied this will be the number of displayed records.- Returns:
- A count of currently visible records
-
getTotalValueCount
public int getTotalValueCount()
Gets the total count of records, regardless of check state or display state- Returns:
- The total count of records
-
shiftRowsUp
public int[] shiftRowsUp(int[] positions)
Shift a series of rows up 1- Parameters:
positions
- Position indices of the rows to be shifted- Returns:
- The resulting new positions
-
shiftRowsDown
public int[] shiftRowsDown(int[] positions)
Shift a series of rows down 1- Parameters:
positions
- Position indices of the rows to be shifted- Returns:
- The resulting new positions
-
shiftRows
public int[] shiftRows(int[] positions, int offset)
Shifts a given set of rows (based on row index) a given offset. A value of -1 for the offset is up (earlier in the list) while a value of 1 is down (later in the list).- Parameters:
positions
- Position indices of the rows to be shiftedoffset
- The offset to shift the rows.- Returns:
- The resulting new positions
-
setColumnEditable
public void setColumnEditable(int column)
Allows caller to define whether a given column is allowed to be editable. The column index provided is relative to user data and therefore index 0 is the first record column.- Parameters:
column
- The column index to set as editable
-
setDefaultCheckState
public void setDefaultCheckState(boolean defaultCheckState)
Sets the default checked state of records- Parameters:
defaultCheckState
- The default check state to use
-
getCustomFilterProviders
public java.util.List<DynamicTableFilterProvider> getCustomFilterProviders()
Gets the list of filter providers beyond those that are built in, allowing you to add or remove custom filter providers.- Returns:
- The current list of custom filter providers
-
setCustomFilterProviders
public void setCustomFilterProviders(java.util.List<DynamicTableFilterProvider> customFilterProviders)
Sets the list of filter providers beyond those that are built in.- Parameters:
customFilterProviders
- The new list of custom filter providers
-
-