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 class
JmriJTablePersistenceManager.JTableListener
static class
JmriJTablePersistenceManager.TableColumnPreferences
Handler 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>>
columns
protected java.util.HashMap<java.lang.String,JmriJTablePersistenceManager.JTableListener>
listeners
java.lang.String
PAUSED
static java.lang.String
SORT_ORDER
protected java.util.HashMap<java.lang.String,java.util.List<javax.swing.RowSorter.SortKey>>
sortKeys
static java.lang.String
TABLES_ELEMENT
static java.lang.String
TABLES_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 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.java.util.Set<java.lang.Class<?>>
getProvides()
Get the set of Classes that this PreferencesManager can be registered as a provider of in theInstanceManager
.void
initialize(Profile profile)
Initialize the PreferencesManager with preferences associated with the provided Profile.protected boolean
isDirty()
Get dirty (needs to be saved) state.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.void
persist(javax.swing.JTable table, boolean resetState)
Persist the user interface state for a table.void
propertyChange(java.beans.PropertyChangeEvent evt)
void
resetState(javax.swing.JTable table)
Reset the table state to the cached state.void
savePreferences(Profile profile)
Save the preferences that this provider manages for the provided Profile.protected void
setDirty(boolean dirty)
Set dirty (needs to be saved) state.void
setPaused(boolean paused)
Pause saving persistence data to storage.protected void
setPersistedState(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.void
stopPersisting(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
resetState
is true.Using this method with
resetState
set 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:
persist
in 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:JTablePersistenceManager
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.- Specified by:
stopPersisting
in interfaceJTablePersistenceManager
- Parameters:
table
- the table to stop persisting
-
clearState
public void clearState(javax.swing.JTable table)
Description copied from interface:JTablePersistenceManager
Remove the persistent state for a table from the cache. This does not cause the JTablePersistanceManager to stop persisting the table.- Specified by:
clearState
in interfaceJTablePersistenceManager
- Parameters:
table
- the table to clear
-
cacheState
public void cacheState(javax.swing.JTable table)
Description copied from interface:JTablePersistenceManager
Add the current state for a table to the cache. This does not cause the JTablePersistanceManager to start persisting the table.- Specified by:
cacheState
in interfaceJTablePersistenceManager
- Parameters:
table
- the table to cache
-
resetState
public void resetState(javax.swing.JTable table)
Description copied from interface:JTablePersistenceManager
Reset the table state to the cached state. This does not cause the JTablePersistanceManager to start persisting the table.- Specified by:
resetState
in 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:JTablePersistenceManager
Pause saving persistence data to storage. If setting paused to false, pending persistence data is written immediately.- Specified by:
setPaused
in interfaceJTablePersistenceManager
- Parameters:
paused
- true if saving persistence data should be paused; false otherwise.
-
isPaused
public boolean isPaused()
Description copied from interface:JTablePersistenceManager
Determine if saving persistence data is paused.- Specified by:
isPaused
in interfaceJTablePersistenceManager
- Returns:
- true if saving persistence data is paused; false otherwise.
-
initialize
public void initialize(Profile profile) throws InitializationException
Description copied from interface:PreferencesManager
Initialize 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:
initialize
in 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:PreferencesManager
Save the preferences that this provider manages for the provided Profile.- Specified by:
savePreferences
in 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:AbstractPreferencesManager
Get 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:
getProvides
in interfacePreferencesManager
- Overrides:
getProvides
in 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:JTablePersistenceManager
Determine if persistence data is being held for a table.- Specified by:
isPersistenceDataRetained
in 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:JTablePersistenceManager
Determine if persistence data is being held for a table.- Specified by:
isPersistenceDataRetained
in 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:JTablePersistenceManager
Determine if a table is being persisted.- Specified by:
isPersisting
in 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:JTablePersistenceManager
Determine if a table is being persisted by name.- Specified by:
isPersisting
in 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:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
-