Class ManagerDefaultSelector
- java.lang.Object
-
- jmri.beans.UnboundBean
-
- jmri.beans.Bean
-
- jmri.util.prefs.AbstractPreferencesManager
-
- jmri.managers.ManagerDefaultSelector
-
- All Implemented Interfaces:
BeanInterface
,PropertyChangeFirer
,PropertyChangeProvider
,JmriServiceProviderInterface
,PreferencesManager
public class ManagerDefaultSelector extends AbstractPreferencesManager
Records and executes a desired set of defaults for the JMRI InstanceManager and ProxyManagers.Provided that a connection provides a default, this verifies, unless the per-profile property
jmri-managers.allInternalDefaults
istrue
, that a non-Internal connection (other than type None in the preferences window) is the default for at least one type of manager.allInternalDefaults is preserved as a preference when set here, but
setAllInternalDefaultsValid(boolean)
is not (originally) invoked from the GUI.- Since:
- 2.9.4
- See Also:
SystemConnectionMemo.provides(java.lang.Class)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ManagerDefaultSelector.Item
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALL_INTERNAL_DEFAULTS
java.util.HashMap<java.lang.Class<?>,java.lang.String>
defaults
ManagerDefaultSelector.Item[]
knownManagers
-
Fields inherited from class jmri.beans.Bean
propertyChangeSupport
-
-
Constructor Summary
Constructors Constructor Description ManagerDefaultSelector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InitializationException
configure(Profile profile)
Load into InstanceManagerjava.lang.String
getDefault(java.lang.Class<?> managerClass)
Return the userName of the system that provides the default instance for a specific class.void
initialize(Profile profile)
Initialize the PreferencesManager with preferences associated with the provided Profile.boolean
isAllInternalDefaultsValid()
Check if having all defaults assigned to internal connections should be considered is valid in the presence of an external System Connection.boolean
isPreferencesValid(Profile profile)
(package private) void
removeConnectionAsDefault(java.lang.String removedName)
void
savePreferences(Profile profile)
Save the preferences that this provider manages for the provided Profile.void
setAllInternalDefaultsValid(boolean isAllInternalDefaultsValid)
Set if having all defaults assigned to internal connections should be considered is valid in the presence of an external System Connection.void
setDefault(java.lang.Class<?> managerClass, java.lang.String userName)
Record the userName of the system that provides the default instance for a specific class.-
Methods inherited from class jmri.util.prefs.AbstractPreferencesManager
addInitializationException, getInitializationExceptions, getProvides, 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
-
-
-
-
Field Detail
-
defaults
public final java.util.HashMap<java.lang.Class<?>,java.lang.String> defaults
-
ALL_INTERNAL_DEFAULTS
public static final java.lang.String ALL_INTERNAL_DEFAULTS
- See Also:
- Constant Field Values
-
knownManagers
public final ManagerDefaultSelector.Item[] knownManagers
-
-
Constructor Detail
-
ManagerDefaultSelector
public ManagerDefaultSelector()
-
-
Method Detail
-
removeConnectionAsDefault
void removeConnectionAsDefault(java.lang.String removedName)
-
getDefault
public java.lang.String getDefault(java.lang.Class<?> managerClass)
Return the userName of the system that provides the default instance for a specific class.- Parameters:
managerClass
- the specific type, for example, TurnoutManager, for which a default system is desired- Returns:
- userName of the system, or null if none set
-
setDefault
public void setDefault(java.lang.Class<?> managerClass, java.lang.String userName)
Record the userName of the system that provides the default instance for a specific class.To ensure compatibility of different preference versions, only classes that are current registered are preserved. This way, reading in an old file will just have irrelevant items ignored.
- Parameters:
managerClass
- the specific type, for example, TurnoutManager, for which a default system is desireduserName
- of the system, or null if none set
-
configure
@CheckForNull public InitializationException configure(Profile profile)
Load into InstanceManager- Parameters:
profile
- the profile to configure against- Returns:
- an exception that can be passed to the user or null if no errors occur
-
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.- 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.- 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
-
isPreferencesValid
public boolean isPreferencesValid(Profile profile)
-
isAllInternalDefaultsValid
public boolean isAllInternalDefaultsValid()
Check if having all defaults assigned to internal connections should be considered is valid in the presence of an external System Connection.- Returns:
- true if having all internal defaults should be valid; false otherwise
-
setAllInternalDefaultsValid
public void setAllInternalDefaultsValid(boolean isAllInternalDefaultsValid)
Set if having all defaults assigned to internal connections should be considered is valid in the presence of an external System Connection.- Parameters:
isAllInternalDefaultsValid
- true if having all internal defaults should be valid; false otherwise
-
-