Class ProfileManager
- All Implemented Interfaces:
BeanInterface,PropertyChangeFirer,PropertyChangeProvider
This manager, and its configuration, fall outside the control of the
ConfigureManager since the ConfigureManager's configuration is
influenced by this manager.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class jmri.beans.Bean
propertyChangeSupport -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddProfile(Profile profile) protected voidaddSearchPath(File path) Create a default profile if no profiles exist.static StringGenerate a reasonably pseudorandom unique id.voidExport theProfileto a zip file.Get theProfilethat is currently in use.Get the name of theProfilethat is currently in use.Get an ArrayList ofProfileobjects.intSeconds to display profile selector before automatically starting.Get the file used to configure the ProfileManager.static ProfileManagerGet the defaultProfileManager.protected FileProfile[]Get an array of enabledProfileobjects.getProfiles(int index) Get the enabledProfileat index.File[]Get the paths that are searched for Profiles when presenting the user with a list of Profiles.getSearchPaths(int index) Get the search path at index.static ProfileGet the active profile.booleanShould the app automatically start with the activeProfilewithout offering the user an opportunity to change the Profile?migrateConfigToProfile(File config, String name) Copy a JMRI configuration not in a profile and its user preferences to a profile.booleanmigrateToProfiles(String configFilename) Migrate a JMRI application to usingProfiles.(package private) voidprofileNameChange(Profile profile, String oldName) voidRead the activeProfileand automatic start setting from the ProfileManager config file.protected voidremoveProfile(Profile profile) protected voidremoveSearchPath(File path) voidSave the activeProfileand automatic start setting.protected voidsaveActiveProfile(Profile profile, boolean autoStart) voidsetActiveProfile(String identifier) Set theProfileto use.voidsetActiveProfile(Profile profile) Set theProfileto use.voidsetAutoStartActiveProfile(boolean autoStartActiveProfile) Set if the app will next start without offering the user an opportunity to change theProfile.voidsetAutoStartActiveProfileTimeout(int autoStartActiveProfileTimeout) Set the number of seconds to display the profile selector before automatically starting.voidsetConfigFile(File configFile) Set the file used to configure the ProfileManager.protected voidsetDefaultSearchPath(File defaultSearchPath) protected voidsetNextActiveProfile(Profile profile) voidsetProfiles(Profile profile, int index) Set the enabledProfileat index.Methods inherited from class jmri.beans.Bean
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, isNotifyOnEDT, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from class jmri.beans.UnboundBean
getIndexedProperty, getProperty, getPropertyNames, hasIndexedProperty, hasProperty, setIndexedProperty, setProperty
-
Field Details
-
ACTIVE_PROFILE
- See Also:
-
NEXT_PROFILE
- See Also:
-
PROFILES
- See Also:
-
SEARCH_PATHS
- See Also:
-
DEFAULT
- See Also:
-
DEFAULT_SEARCH_PATH
- See Also:
-
SYSTEM_PROPERTY
- See Also:
-
-
Method Details
-
getDefault
Get the defaultProfileManager.The default ProfileManager needs to be loaded before the InstanceManager since user interaction with the ProfileManager may change how the InstanceManager is configured.
- Returns:
- the default ProfileManager.
- Since:
- 3.11.8
-
getActiveProfile
Get theProfilethat is currently in use.Note that this returning null is not an error condition, and should not be treated as such, since there are times when the user interacts with a JMRI application that there should be no active profile.
- Returns:
- the in use Profile or null if there is no Profile in use
-
getActiveProfileName
Get the name of theProfilethat is currently in use.This is a convenience method that avoids a need to check that
getActiveProfile()does not return null when all that is needed is the name of the active profile.- Returns:
- the name of the active profile or null if there is no active profile
-
setActiveProfile
Set theProfileto use. This method finds the Profile by path or Id and callssetActiveProfile(jmri.profile.Profile).- Parameters:
identifier- the profile path or id; can be null
-
setActiveProfile
Set theProfileto use.Once the
ConfigureManageris loaded, this only sets the Profile used at next application start.- Parameters:
profile- the profile to activate
-
getNextActiveProfile
-
setNextActiveProfile
-
saveActiveProfile
Save the activeProfileand automatic start setting.- Throws:
IOException- if unable to save the profile
-
saveActiveProfile
protected void saveActiveProfile(@CheckForNull Profile profile, boolean autoStart) throws IOException - Throws:
IOException
-
readActiveProfile
Read the activeProfileand automatic start setting from the ProfileManager config file.- Throws:
IOException- if unable to read the profile- See Also:
-
getProfiles
Get an array of enabledProfileobjects.- Returns:
- The enabled Profile objects
-
getAllProfiles
Get an ArrayList ofProfileobjects.- Returns:
- A list of all Profile objects
-
getProfiles
Get the enabledProfileat index.- Parameters:
index- the index of the desired Profile- Returns:
- A Profile
-
setProfiles
Set the enabledProfileat index.- Parameters:
profile- the Profile to setindex- the index to set; any existing profile at index is removed
-
addProfile
-
removeProfile
-
getSearchPaths
Get the paths that are searched for Profiles when presenting the user with a list of Profiles. Profiles that are discovered in these paths are automatically added to the catalog.- Returns:
- Paths that may contain profiles
-
getAllSearchPaths
-
getSearchPaths
Get the search path at index.- Parameters:
index- the index of the search path- Returns:
- A path that may contain profiles
-
addSearchPath
- Throws:
IOException
-
removeSearchPath
- Throws:
IOException
-
getDefaultSearchPath
-
setDefaultSearchPath
- Throws:
IOException
-
getConfigFile
Get the file used to configure the ProfileManager.- Returns:
- the appConfigFile
-
setConfigFile
Set the file used to configure the ProfileManager. This is set on a per-application basis.- Parameters:
configFile- the appConfigFile to set
-
isAutoStartActiveProfile
Should the app automatically start with the activeProfilewithout offering the user an opportunity to change the Profile?- Returns:
- true if the app should start without user interaction
-
setAutoStartActiveProfile
Set if the app will next start without offering the user an opportunity to change theProfile.- Parameters:
autoStartActiveProfile- the autoStartActiveProfile to set
-
createDefaultProfile
Create a default profile if no profiles exist.- Returns:
- A new profile or null if profiles already exist
- Throws:
IllegalArgumentException- if profile already exists at default locationIOException- if unable to create a Profile
-
migrateConfigToProfile
@Nonnull public Profile migrateConfigToProfile(@Nonnull File config, @Nonnull String name) throws IllegalArgumentException, IOException Copy a JMRI configuration not in a profile and its user preferences to a profile.- Parameters:
config- the configuration filename- the name of the configuration- Returns:
- The profile with the migrated configuration
- Throws:
IOException- if unable to create a ProfileIllegalArgumentException- if profile already exists for config
-
migrateToProfiles
public boolean migrateToProfiles(@Nonnull String configFilename) throws IllegalArgumentException, IOException Migrate a JMRI application to usingProfiles.Migration occurs when no profile configuration exists, but an application configuration exists. This method also handles the situation where an entirely new user is first starting JMRI, or where a user has deleted all their profiles.
When a JMRI application is starting there are eight potential Profile-related states requiring preparation to use profiles:
This method returns true if a migration occurred, and false in all other circumstances.Matrix of states determining if migration required. Profile Catalog Profile Config App Config Action YES YES YES No preparation required - migration from earlier JMRI complete YES YES NO No preparation required - JMRI installed after profiles feature introduced YES NO YES Migration required - other JMRI applications migrated to profiles by this user, but not this one YES NO NO No preparation required - prompt user for desired profile if multiple profiles exist, use default otherwise NO NO NO New user - create and use default profile NO NO YES Migration required - need to create first profile NO YES YES No preparation required - catalog will be automatically regenerated NO YES NO No preparation required - catalog will be automatically regenerated - Parameters:
configFilename- the name of the app config file- Returns:
- true if a user's existing config was migrated, false otherwise
- Throws:
IOException- if unable to to create a ProfileIllegalArgumentException- if profile already exists for configFilename
-
export
public void export(@Nonnull Profile profile, @Nonnull File target, boolean exportExternalUserFiles, boolean exportExternalRoster) throws IOException, org.jdom2.JDOMException, InitializationException Export theProfileto a zip file.- Parameters:
profile- The profile to exporttarget- The file to export the profile intoexportExternalUserFiles- If the User Files are not within the profile directory, should they be included?exportExternalRoster- It the roster is not within the profile directory, should it be included?- Throws:
IOException- if unable to write a file during the exportorg.jdom2.JDOMException- if unable to create a new profile configuration file in the exported ProfileInitializationException- if unable to read profile to export
-
getStartingProfile
Get the active profile.This method initiates the process of setting the active profile when a headless app launches.
- Returns:
- The active
Profile - Throws:
IOException- if unable to read the current active profile- See Also:
-
createUniqueId
Generate a reasonably pseudorandom unique id.This can be used to generate the id for a
NullProfile. Implementing applications should save this value so that the id of a NullProfile is consistent across application launches.- Returns:
- String of alphanumeric characters.
-
profileNameChange
-
getAutoStartActiveProfileTimeout
Seconds to display profile selector before automatically starting.If 0, selector will not automatically dismiss.
- Returns:
- Seconds to display selector.
-
setAutoStartActiveProfileTimeout
Set the number of seconds to display the profile selector before automatically starting.If negative or greater than 300 (5 minutes), set to 0 to prevent automatically starting with any profile.
Call
saveActiveProfile()after setting this to persist the value across application restarts.- Parameters:
autoStartActiveProfileTimeout- Seconds to display profile selector
-