Class 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 a DynamicTableControl
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class javax.swing.table.AbstractTableModel

        listenerList
    • 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 record
      void 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 using getRecordHashes(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 displayed
      int getCheckedValueCount()
      Gets a count of how many records are currently checked
      java.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 calling hashRecord(Object) on each record.
      java.util.List<java.lang.Object> getRecords()
      Gets the records associated
      int getRowCount()  
      int getTotalValueCount()
      Gets the total count of records, regardless of check state or display state
      java.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 table
      void remove​(int rowIndex)
      Remove a record at a specified index
      void removeChangeListener​(ChoiceTableModelChangeListener listener)  
      void setChangeListener​(ChoiceTableModelChangeListener listener)
      Set a listener which will be notified when changes are made
      void setCheckedAtIndex​(int index, boolean value)
      Set the checked state of a record at a given index
      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.
      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 records
      void setFilter​(java.lang.String filter)
      Set the current filter string
      void setRecords​(java.util.List<java.lang.Object> records)
      Sets the records associated
      void 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 1
      int[] shiftRowsUp​(int[] positions)
      Shift a series of rows up 1
      void 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 column
        records - A collection of records to be displayed
        valueCallback - Callback that yields a value for a cell given a particular record and column number
        defaultCheckState - 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
      • 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 interface javax.swing.table.TableModel
        Overrides:
        isCellEditable in class javax.swing.table.AbstractTableModel
      • setValueAt

        public void setValueAt​(java.lang.Object aValue,
                               int rowIndex,
                               int columnIndex)
        Specified by:
        setValueAt in interface javax.swing.table.TableModel
        Overrides:
        setValueAt in class javax.swing.table.AbstractTableModel
      • getColumnName

        public java.lang.String getColumnName​(int columnIndex)
        Specified by:
        getColumnName in interface javax.swing.table.TableModel
        Overrides:
        getColumnName in class javax.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 interface javax.swing.table.TableModel
        Overrides:
        getColumnClass in class javax.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 of
        value - 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 calling hashRecord(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 using getRecordHashes(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 shifted
        offset - 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