Class JmriJTablePersistenceManager
- java.lang.Object
-
- jmri.beans.UnboundBean
-
- jmri.beans.Bean
-
- jmri.util.prefs.AbstractPreferencesManager
-
- jmri.swing.JmriJTablePersistenceManager
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.util.EventListener,BeanInterface,PropertyChangeFirer,PropertyChangeProvider,JmriServiceProviderInterface,PreferencesManager,JTablePersistenceManager
public class JmriJTablePersistenceManager extends AbstractPreferencesManager implements JTablePersistenceManager, java.beans.PropertyChangeListener
Default implementation ofJTablePersistenceManager. The column preferredWidth retained for a column is theTableColumn.getPreferredWidth(), since this preferredWidth is available before the table column is rendered by Swing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classJmriJTablePersistenceManager.JTableListenerstatic classJmriJTablePersistenceManager.TableColumnPreferencesHandler for individual column preferences.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,JmriJTablePersistenceManager.TableColumnPreferences>>columnsprotected java.util.HashMap<java.lang.String,JmriJTablePersistenceManager.JTableListener>listenersjava.lang.StringPAUSEDstatic java.lang.StringSORT_ORDERprotected java.util.HashMap<java.lang.String,java.util.List<javax.swing.RowSorter.SortKey>>sortKeysstatic java.lang.StringTABLES_ELEMENTstatic java.lang.StringTABLES_NAMESPACE-
Fields inherited from class jmri.beans.Bean
propertyChangeSupport
-
-
Constructor Summary
Constructors Constructor Description JmriJTablePersistenceManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcacheState(javax.swing.JTable table)Add the current state for a table to the cache.voidclearState(javax.swing.JTable table)Remove the persistent state for a table from the cache.java.util.Set<java.lang.Class<?>>getProvides()Get the set of Classes that this PreferencesManager can be registered as a provider of in theInstanceManager.voidinitialize(Profile profile)Initialize the PreferencesManager with preferences associated with the provided Profile.protected booleanisDirty()Get dirty (needs to be saved) state.booleanisPaused()Determine if saving persistence data is paused.booleanisPersistenceDataRetained(java.lang.String name)Determine if persistence data is being held for a table.booleanisPersistenceDataRetained(javax.swing.JTable table)Determine if persistence data is being held for a table.booleanisPersisting(java.lang.String name)Determine if a table is being persisted by name.booleanisPersisting(javax.swing.JTable table)Determine if a table is being persisted.voidpersist(javax.swing.JTable table, boolean resetState)Persist the user interface state for a table.voidpropertyChange(java.beans.PropertyChangeEvent evt)voidresetState(javax.swing.JTable table)Reset the table state to the cached state.voidsavePreferences(Profile profile)Save the preferences that this provider manages for the provided Profile.protected voidsetDirty(boolean dirty)Set dirty (needs to be saved) state.voidsetPaused(boolean paused)Pause saving persistence data to storage.protected voidsetPersistedState(java.lang.String table, java.lang.String column, int order, int width, javax.swing.SortOrder sort, boolean hidden)Set the persisted state for the given column in the given table.voidstopPersisting(javax.swing.JTable table)Stop persisting the table.-
Methods inherited from class jmri.util.prefs.AbstractPreferencesManager
addInitializationException, getInitializationExceptions, getRequires, isInitialized, isInitializedWithExceptions, isInitializing, requireAllOther, requiresNoInitializedWithExceptions, requiresNoInitializedWithExceptions, setInitialized, setInitializing
-
Methods inherited from class jmri.beans.Bean
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, isNotifyOnEDT, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from class jmri.beans.UnboundBean
getIndexedProperty, getProperty, getPropertyNames, hasIndexedProperty, hasProperty, setIndexedProperty, setProperty
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.swing.JTablePersistenceManager
persist
-
-
-
-
Field Detail
-
listeners
protected final java.util.HashMap<java.lang.String,JmriJTablePersistenceManager.JTableListener> listeners
-
columns
protected final java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,JmriJTablePersistenceManager.TableColumnPreferences>> columns
-
sortKeys
protected final java.util.HashMap<java.lang.String,java.util.List<javax.swing.RowSorter.SortKey>> sortKeys
-
PAUSED
public final java.lang.String PAUSED
- See Also:
- Constant Field Values
-
TABLES_NAMESPACE
public static final java.lang.String TABLES_NAMESPACE
- See Also:
- Constant Field Values
-
TABLES_ELEMENT
public static final java.lang.String TABLES_ELEMENT
- See Also:
- Constant Field Values
-
SORT_ORDER
public static final java.lang.String SORT_ORDER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JmriJTablePersistenceManager
public JmriJTablePersistenceManager()
-
-
Method Detail
-
persist
public 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 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 asJTablePersistenceManager.resetState(javax.swing.JTable)immediately prior to callingJTablePersistenceManager.persist(javax.swing.JTable).Persisting a table that is already persisted may cause the persistence state to be updated, but will not cause additional listeners to be added to the table.
- Specified by:
persistin interfaceJTablePersistenceManager- Parameters:
table- the table to persistresetState- 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 namejava.lang.NullPointerException- if the table name is null
-
stopPersisting
public void stopPersisting(javax.swing.JTable table)
Description copied from interface:JTablePersistenceManagerStop 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.- Specified by:
stopPersistingin interfaceJTablePersistenceManager- Parameters:
table- the table to stop persisting
-
clearState
public void clearState(javax.swing.JTable table)
Description copied from interface:JTablePersistenceManagerRemove the persistent state for a table from the cache. This does not cause the JTablePersistanceManager to stop persisting the table.- Specified by:
clearStatein interfaceJTablePersistenceManager- Parameters:
table- the table to clear
-
cacheState
public void cacheState(javax.swing.JTable table)
Description copied from interface:JTablePersistenceManagerAdd the current state for a table to the cache. This does not cause the JTablePersistanceManager to start persisting the table.- Specified by:
cacheStatein interfaceJTablePersistenceManager- Parameters:
table- the table to cache
-
resetState
public void resetState(javax.swing.JTable table)
Description copied from interface:JTablePersistenceManagerReset the table state to the cached state. This does not cause the JTablePersistanceManager to start persisting the table.- Specified by:
resetStatein interfaceJTablePersistenceManager- Parameters:
table- the table to reset
-
setDirty
protected void setDirty(boolean dirty)
Set dirty (needs to be saved) state. Protected so that subclasses can manipulate this state.- Parameters:
dirty- true if needs to be saved
-
isDirty
protected boolean isDirty()
Get dirty (needs to be saved) state. Protected so that subclasses can manipulate this state.- Returns:
- true if needs to be saved
-
setPaused
public void setPaused(boolean paused)
Description copied from interface:JTablePersistenceManagerPause saving persistence data to storage. If setting paused to false, pending persistence data is written immediately.- Specified by:
setPausedin interfaceJTablePersistenceManager- Parameters:
paused- true if saving persistence data should be paused; false otherwise.
-
isPaused
public boolean isPaused()
Description copied from interface:JTablePersistenceManagerDetermine if saving persistence data is paused.- Specified by:
isPausedin interfaceJTablePersistenceManager- Returns:
- true if saving persistence data is paused; false otherwise.
-
initialize
public void initialize(Profile profile) throws InitializationException
Description copied from interface:PreferencesManagerInitialize the PreferencesManager with preferences associated with the provided Profile.Implementing classes should throw an InitializationException with a user readable localized message, since it most likely be displayed to the user. Implementing classes will still want to ensure that
PreferencesManager.isInitialized(jmri.profile.Profile)orPreferencesManager.isInitializedWithExceptions(jmri.profile.Profile)return true if throwing an InitializationException to ensure that the provider is not repeatedly initialized.- Specified by:
initializein interfacePreferencesManager- Parameters:
profile- the configuration profile used for this initialization; may be null to initialize for this user regardless of profile- Throws:
InitializationException- if the user needs to be notified of an issue that prevents regular use of the application
-
savePreferences
public void savePreferences(Profile profile)
Description copied from interface:PreferencesManagerSave the preferences that this provider manages for the provided Profile.- Specified by:
savePreferencesin interfacePreferencesManager- Parameters:
profile- the profile associated with the preferences to save; may be null to save preferences that apply to the current user regardless of profile
-
getProvides
@Nonnull public java.util.Set<java.lang.Class<?>> getProvides()
Description copied from class:AbstractPreferencesManagerGet the set of Classes that this PreferencesManager can be registered as a provider of in theInstanceManager.This implementation returns the class of the object against which this method is called.
- Specified by:
getProvidesin interfacePreferencesManager- Overrides:
getProvidesin classAbstractPreferencesManager- Returns:
- A set or list of classes. If this PreferencesManager provides an instance of no other Interfaces or abstract Classes than PreferencesManager, return an empty set instead of null.
-
setPersistedState
protected void setPersistedState(@Nonnull java.lang.String table, @Nonnull java.lang.String column, int order, int width, javax.swing.SortOrder sort, boolean hidden)
Set the persisted state for the given column in the given table. The persisted state is not saved untilsavePreferences(jmri.profile.Profile)is called.- Parameters:
table- the table namecolumn- the column nameorder- order of the columnwidth- column preferredWidthsort- how the column is sortedhidden- true if column is hidden- Throws:
java.lang.NullPointerException- if either name is null
-
isPersistenceDataRetained
public boolean isPersistenceDataRetained(javax.swing.JTable table)
Description copied from interface:JTablePersistenceManagerDetermine if persistence data is being held for a table.- Specified by:
isPersistenceDataRetainedin interfaceJTablePersistenceManager- Parameters:
table- the table to check against- Returns:
- true if the table has persistence data; false otherwise
-
isPersistenceDataRetained
public boolean isPersistenceDataRetained(java.lang.String name)
Description copied from interface:JTablePersistenceManagerDetermine if persistence data is being held for a table.- Specified by:
isPersistenceDataRetainedin interfaceJTablePersistenceManager- Parameters:
name- the name of the table to check against- Returns:
- true if the table has persistence data; false otherwise
-
isPersisting
public boolean isPersisting(javax.swing.JTable table)
Description copied from interface:JTablePersistenceManagerDetermine if a table is being persisted.- Specified by:
isPersistingin interfaceJTablePersistenceManager- Parameters:
table- the table to check against- Returns:
- true if the table is being persisted; false otherwise
-
isPersisting
public boolean isPersisting(java.lang.String name)
Description copied from interface:JTablePersistenceManagerDetermine if a table is being persisted by name.- Specified by:
isPersistingin interfaceJTablePersistenceManager- Parameters:
name- the name of the table to check against- Returns:
- true if the table is being persisted; false otherwise
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
-