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

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void cacheState​(javax.swing.JTable table)
      Add the current state for a table to the cache.
      void clearState​(javax.swing.JTable table)
      Remove the persistent state for a table from the cache.
      boolean isPaused()
      Determine if saving persistence data is paused.
      boolean isPersistenceDataRetained​(java.lang.String name)
      Determine if persistence data is being held for a table.
      boolean isPersistenceDataRetained​(javax.swing.JTable table)
      Determine if persistence data is being held for a table.
      boolean isPersisting​(java.lang.String name)
      Determine if a table is being persisted by name.
      boolean isPersisting​(javax.swing.JTable table)
      Determine if a table is being persisted.
      default void persist​(javax.swing.JTable table)
      Persist the user interface state for a table.
      void persist​(javax.swing.JTable table, boolean resetState)
      Persist the user interface state for a table.
      void resetState​(javax.swing.JTable table)
      Reset the table state to the cached state.
      void setPaused​(boolean paused)
      Pause saving persistence data to storage.
      void stopPersisting​(javax.swing.JTable table)
      Stop persisting the table.
    • Method Detail

      • persist

        default void persist​(@Nonnull
                             javax.swing.JTable table)
                      throws java.lang.IllegalArgumentException,
                             java.lang.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. 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:
        java.lang.IllegalArgumentException - if another table instance is already persisted by the same name
        java.lang.NullPointerException - if the table name is null
      • persist

        void persist​(@Nonnull
                     javax.swing.JTable table,
                     boolean resetState)
              throws java.lang.IllegalArgumentException,
                     java.lang.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:
        java.lang.IllegalArgumentException - if another table instance is already persisted by the same name
        java.lang.NullPointerException - if the table name is null
      • stopPersisting

        void stopPersisting​(@Nonnull
                            javax.swing.JTable table)
                     throws java.lang.NullPointerException
        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:
        java.lang.NullPointerException - if the table name is null
      • clearState

        void clearState​(@Nonnull
                        javax.swing.JTable table)
                 throws java.lang.NullPointerException
        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:
        java.lang.NullPointerException - if the table name is null
      • cacheState

        void cacheState​(@Nonnull
                        javax.swing.JTable table)
                 throws java.lang.NullPointerException
        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:
        java.lang.NullPointerException - if the table name is null
      • resetState

        void resetState​(@Nonnull
                        javax.swing.JTable table)
                 throws java.lang.NullPointerException
        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:
        java.lang.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
                             javax.swing.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
                             java.lang.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

        boolean isPersistenceDataRetained​(@Nonnull
                                          javax.swing.JTable table)
        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

        boolean isPersistenceDataRetained​(@Nonnull
                                          java.lang.String name)
        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