Interface JTablePersistenceManager
- All Known Implementing Classes:
JmriJTablePersistenceManager
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 TypeMethodDescriptionvoidcacheState(JTable table) Add the current state for a table to the cache.voidclearState(JTable table) Remove the persistent state for a table from the cache.booleanisPaused()Determine if saving persistence data is paused.booleanDetermine if persistence data is being held for a table.booleanisPersistenceDataRetained(JTable table) Determine if persistence data is being held for a table.booleanisPersisting(String name) Determine if a table is being persisted by name.booleanisPersisting(JTable table) Determine if a table is being persisted.default voidPersist the user interface state for a table.voidPersist the user interface state for a table.voidresetState(JTable table) Reset the table state to the cached state.voidsetPaused(boolean paused) Pause saving persistence data to storage.voidstopPersisting(JTable table) Stop persisting the table.
-
Method Details
-
persist
Persist the user interface state for a table. The name returned byComponent.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 nameNullPointerException- 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 byComponent.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
resetStateis true.Using this method with
resetStateset to true is the same asresetState(javax.swing.JTable)immediately prior to callingpersist(javax.swing.JTable).- Parameters:
table- the table to persistresetState- 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 nameNullPointerException- 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
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
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
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
-