Package jmri.swing

Interface JTablePersistenceManager

All Known Implementing Classes:
JmriJTablePersistenceManager

public interface JTablePersistenceManager
Manager for ensuring that JTable user interface state is persisted.

JTable user interface state that can be persisted includes:

  • row sort order (if the table has a non-null RowSorter)
  • column order
  • column visibility
  • column width

Row sort order is only persisted for JTables that implement the RowSorter for sorting. If the RowSorter is null, the row sorting will not be persisted.

Column attributes (order, visibility, and width) are persisted by listening to changes in the TableColumnModel of the table. Column visibility is persisted only if the TableColumnModel is assignable from XTableColumnModel. Columns will be saved using the String representation of either TableColumn.getIdentifier() or TableColumn.getHeaderValue().

Tables against which persist(javax.swing.JTable) is called without first calling resetState(javax.swing.JTable) will not have state retained across application restarts.

Note: A JTable with UI state being persisted must have a unique non-null name; columns in the table must also have unique non-null identifiers or header text.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add the current state for a table to the cache.
    void
    Remove the persistent state for a table from the cache.
    boolean
    Determine if saving persistence data is paused.
    boolean
    Determine if persistence data is being held for a table.
    boolean
    Determine if persistence data is being held for a table.
    boolean
    Determine if a table is being persisted by name.
    boolean
    Determine if a table is being persisted.
    default void
    persist(JTable table)
    Persist the user interface state for a table.
    void
    persist(JTable table, boolean resetState)
    Persist the user interface state for a table.
    void
    Reset the table state to the cached state.
    void
    setPaused(boolean paused)
    Pause saving persistence data to storage.
    void
    Stop persisting the table.
  • Method Details

    • persist

      Persist the user interface state for a table. The name returned by Component.getName() is used to persist the table, so ensure the name is set such that it can be retrieved by the same name in a later JMRI execution.

      Note that the current state of the table, if not already persisted, at the time of this call is retained as the table state. Using this method is the same as calling persist(javax.swing.JTable, boolean) with false for the second argument.

      Parameters:
      table - the table to persist
      Throws:
      IllegalArgumentException - if another table instance is already persisted by the same name
      NullPointerException - if the table name is null
    • persist

      void persist(@Nonnull JTable table, boolean resetState) throws IllegalArgumentException, NullPointerException
      Persist the user interface state for a table. The name returned by Component.getName() is used to persist the table, so ensure the name is set such that it can be retrieved by the same name in a later JMRI execution.

      Note that the current state of the table, if not already persisted, at the time of this call is retained as the table state unless resetState is true.

      Using this method with resetState set to true is the same as resetState(javax.swing.JTable) immediately prior to calling persist(javax.swing.JTable).

      Parameters:
      table - the table to persist
      resetState - reset the table to the stored state if true; retain the current state if false
      Throws:
      IllegalArgumentException - if another table instance is already persisted by the same name
      NullPointerException - if the table name is null
    • stopPersisting

      Stop persisting the table. This does not clear the persistence state, but merely causes the JTablePersistenceManager to stop listening to the table. No error is thrown if the table state was not being persisted.
      Parameters:
      table - the table to stop persisting
      Throws:
      NullPointerException - if the table name is null
    • clearState

      Remove the persistent state for a table from the cache. This does not cause the JTablePersistanceManager to stop persisting the table.
      Parameters:
      table - the table to clear
      Throws:
      NullPointerException - if the table name is null
    • cacheState

      Add the current state for a table to the cache. This does not cause the JTablePersistanceManager to start persisting the table.
      Parameters:
      table - the table to cache
      Throws:
      NullPointerException - if the table name is null
    • resetState

      Reset the table state to the cached state. This does not cause the JTablePersistanceManager to start persisting the table.
      Parameters:
      table - the table to reset
      Throws:
      NullPointerException - if the table name is null
    • setPaused

      void setPaused(boolean paused)
      Pause saving persistence data to storage. If setting paused to false, pending persistence data is written immediately.
      Parameters:
      paused - true if saving persistence data should be paused; false otherwise.
    • isPaused

      boolean isPaused()
      Determine if saving persistence data is paused.
      Returns:
      true if saving persistence data is paused; false otherwise.
    • isPersisting

      boolean isPersisting(@Nonnull JTable table)
      Determine if a table is being persisted.
      Parameters:
      table - the table to check against
      Returns:
      true if the table is being persisted; false otherwise
    • isPersisting

      boolean isPersisting(@Nonnull String name)
      Determine if a table is being persisted by name.
      Parameters:
      name - the name of the table to check against
      Returns:
      true if the table is being persisted; false otherwise
    • isPersistenceDataRetained

      Determine if persistence data is being held for a table.
      Parameters:
      table - the table to check against
      Returns:
      true if the table has persistence data; false otherwise
    • isPersistenceDataRetained

      Determine if persistence data is being held for a table.
      Parameters:
      name - the name of the table to check against
      Returns:
      true if the table has persistence data; false otherwise