Class ThreadedTableModel<ROW_OBJECT,​DATA_SOURCE>

Constructor Detail

  • Method Detail

    • isLoadIncrementally

      public boolean isLoadIncrementally()
    • initializeSorting NEW

      protected void initializeSorting()
      Description copied from class: AbstractSortedTableModel
      This method is an attempt to help models that forget to call fireTableDataChanged(). It is expected that tables will fire the notification when they are ready to display data, even if they have that data at construction time. We put this call here so that the forgetful subclasses will have their data sorted for them the first time that this table tries to render itself.
      Overrides:
      initializeSorting in class AbstractSortedTableModel<ROW_OBJECT>
    • doLoad

      protected abstract void doLoad​(Accumulator<ROW_OBJECT> accumulator,
                                     TaskMonitor monitor)
                              throws CancelledException
      The basic method that all children must implement. This is where children load their data.
      Parameters:
      accumulator - the datastructure into which you should incrementally place you table row data
      monitor - the task monitor to check for cancellations and to update progress
      Throws:
      CancelledException - if the task monitor has been cancelled and a call is made to monitor.checkCancelled();.
    • getModelData

      public java.util.List<ROW_OBJECT> getModelData()
      Description copied from interface: RowObjectTableModel
      Implementors should return the current data of the model. For models that support filtering, this will be the filtered version of the data. Furthermore, the data should be the underlying data and not a copy, as this method will potentially sort the given data.

      For those subclasses using an array, you may use the Arrays class to create a list backed by the array ({@link Arrays#asList(Object...)).

      Specified by:
      getModelData in interface RowObjectTableModel<ROW_OBJECT>
      Returns:
      the model data.
    • getUnfilteredIndexForRowObject NEW

      protected int getUnfilteredIndexForRowObject​(ROW_OBJECT rowObject)
      Performs a quick search for the given item in the unfiltered data of this model. To search only for object that are visible in the GUI, use AbstractSortedTableModel.getIndexForRowObject(Object).
      Parameters:
      rowObject - The object for which to search
      Returns:
      The index for the given object; a negative value if the object is not in the list
    • getUnfilteredRowObjectForIndex NEW

      protected ROW_OBJECT getUnfilteredRowObjectForIndex​(int row)
      Returns the row object at the given index in the unfiltered data of this model; null if the index is negative or larger than the list. To search only for object that are visible in the GUI, use AbstractSortedTableModel.getRowObject(int).
      Parameters:
      row - The row index for which to get a row object
      Returns:
      Returns the row object at the given index in the unfiltered data of this model; null if the index is negative or larger than the list.
      See Also:
      AbstractSortedTableModel.getRowObject(int)
    • createSortComparator NEW

      protected java.util.Comparator<ROW_OBJECT> createSortComparator​(int columnIndex)
      Description copied from class: AbstractSortedTableModel
      An extension point for subclasses to insert their own comparator objects for their data. Subclasses can create comparators for a single or multiple columns, as desired. The AbstractSortedTableModel.DefaultColumnComparator is used as a, well, default comparator.
      Overrides:
      createSortComparator in class GDynamicColumnTableModel<ROW_OBJECT,​DATA_SOURCE>
      Parameters:
      columnIndex - the column index for which a comparator is desired.
      Returns:
      a comparator for the given index.
    • sort

      protected void sort​(java.util.List<ROW_OBJECT> data,
                          TableSortingContext<ROW_OBJECT> tableSortingContext)
      Description copied from class: AbstractSortedTableModel
      A default sort method that uses the Collections.sort(List, Comparator) method for sorting. Implementors with reasonably sized data sets can rely on this method. For data sets that can become large, the ThreadedTableModel is the recommended base class, as it handles loading/sorting/filtering in a threaded way.
      Overrides:
      sort in class AbstractSortedTableModel<ROW_OBJECT>
      Parameters:
      data - The data to be sorted
      tableSortingContext - The context required to sort (it contains the sorting columns, a comparator for sorting, etc...).
    • getTableFilter

      public TableFilter<ROW_OBJECT> getTableFilter()
      Returns the filter for this model. The value returned from this method will not be null, but will instead be an instanceof NullTableFilter when no filter is applied. The value returned from this method may not actually yet be applied, depending upon when the background thread finishes loading.
      Specified by:
      getTableFilter in interface RowObjectFilterModel<ROW_OBJECT>
      Returns:
      the filter
    • hasFitler

      public boolean hasFitler()
      Returns true if there is a table filter set that is not the NullTableFilter.
      Returns:
      true if there is a table filter set.
    • doFilter

      protected java.util.List<ROW_OBJECT> doFilter​(java.util.List<ROW_OBJECT> data,
                                                    TableSortingContext<ROW_OBJECT> lastSortingContext,
                                                    TaskMonitor monitor)
                                             throws CancelledException
      Override this to change how filtering is performed. This implementation will do nothing if a TableFilter has not been set via a call to setTableFilter(TableFilter). Also, no filtering will happen if there is no filter text set via a call to #setFilterText(String).
      Parameters:
      data - The list of data to be filtered.
      monitor - the progress monitor to check for cancellation.
      lastSortingContext - the comparator used to sort data. This can be used by overridden filter methods that need to query data about how the table is sorted.
      Returns:
      The new filtered list of data. If no filtering takes place, then the original list should be returned.
      Throws:
      CancelledException - If the filter operation is cancelled.
    • updateObject

      public void updateObject​(ROW_OBJECT obj)
      Schedules an update for the specified object.
      Parameters:
      obj - the object for which to schedule the update
    • addObject

      public void addObject​(ROW_OBJECT obj)
      Adds the specified object to this model and schedules an update.
      Parameters:
      obj - the object to add
    • removeObject

      public void removeObject​(ROW_OBJECT obj)
      Removes the specified object from this model and schedules an update.
      Parameters:
      obj - the object to remove
    • updateNow NEW

      protected void updateNow()
    • getAllData NEW

      protected java.util.List<ROW_OBJECT> getAllData()
    • isBusy

      public boolean isBusy()
      Returns true if the model is busy. "Busy" means the model is either loading or updating.
      Returns:
      true if the model is busy
    • reSort

      public void reSort()
      Resort the table using the current sort criteria. This is useful if the data in the table has changed and is no longer sorted properly. If the setSort method is used, nothing will happen because the table will think it is already sorted on that criteria.
      Overrides:
      reSort in class AbstractSortedTableModel<ROW_OBJECT>
    • reFilter

      public void reFilter()
      Triggers this class to filter the contents of the data.
    • reload

      public void reload()
      Schedules the model to completely reload its underlying data.
    • clearData NEW

      protected void clearData()
      This method will clear all data and trigger fire a table data changed. Use this method to immediately clear all data. This is useful when you want to reload your table data and not have any old data hanging around being painted, which can produce odd results.
    • cancelAllUpdates

      public void cancelAllUpdates()
      Cancels all current and pending updates to the model. Waits until all updates have been cancelled.
    • getRowCount

      public int getRowCount()
      Specified by:
      getRowCount in interface javax.swing.table.TableModel
      Overrides:
      getRowCount in class AbstractGTableModel<ROW_OBJECT>
      See Also:
      TableModel.getRowCount()
    • getUnfilteredCount

      public int getUnfilteredCount()
    • getViewRow

      public int getViewRow​(int modelRow)
      Given a row index for the raw (unfiltered) model, return the corresponding index in the view (filtered) model.
      Specified by:
      getViewRow in interface RowObjectFilterModel<ROW_OBJECT>
      Parameters:
      modelRow - The row index that corresponds to unfiltered data
      Returns:
      the index of that row in the filtered data
      See Also:
      getModelRow(int)
    • getModelRow

      public int getModelRow​(int viewRow)
      Given a row index for the view (filtered) model, return the corresponding index in the raw (unfiltered) model.
      Specified by:
      getModelRow in interface RowObjectFilterModel<ROW_OBJECT>
      Parameters:
      viewRow - The row index that corresponds to filtered data
      Returns:
      the index of that row in the unfiltered data
      See Also:
      getViewRow(int)
    • getRowObjects

      public java.util.List<ROW_OBJECT> getRowObjects​(int[] rows)
      Returns the corresponding row objects for the specified rows.
      Parameters:
      rows - the table rows
      Returns:
      the corresponding database keys
    • getSortedColumnClass NEW

      protected java.lang.Class<?> getSortedColumnClass​(int columnIndex)
    • setIncrementalTaskMonitor

      public void setIncrementalTaskMonitor​(TaskMonitor monitor)
    • addInitialLoadListener

      public void addInitialLoadListener​(ThreadedTableModelListener listener)
      Adds a listener that will be notified of the first table load of this model. After the initial load, the listener is removed.
      Parameters:
      listener -