Class Roster
- java.lang.Object
-
- jmri.jmrit.XmlFile
-
- jmri.jmrit.roster.Roster
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.util.EventListener
,PropertyChangeProvider
,RosterGroupSelector
public class Roster extends XmlFile implements RosterGroupSelector, PropertyChangeProvider, java.beans.PropertyChangeListener
Roster manages and manipulates a roster of locomotives.It works with the "roster-config" XML schema to load and store its information.
This is an in-memory representation of the roster xml file (see below for constants defining name and location). As such, this class is also responsible for the "dirty bit" handling to ensure it gets written. As a temporary reliability enhancement, all changes to this structure are now being written to a backup file, and a copy is made when the file is opened.
Multiple Roster objects don't make sense, so we use an "instance" member to navigate to a single one.
The only bound property is the list of RosterEntrys; a PropertyChangedEvent is fired every time that changes.
The entries are stored in an ArrayList, sorted alphabetically. That sort is done manually each time an entry is added.
The roster is stored in a "Roster Index", which can be read or written. Each individual entry (once stored) contains a filename which can be used to retrieve the locomotive information for that roster entry. Note that the RosterEntry information is duplicated in both the Roster (stored in the roster.xml file) and in the specific file for the entry.
Originally, JMRI managed just one global roster, held in a global Roster object. With the rise of more complicated layouts, code has been added to address multiple rosters, with the primary one now held in Roster.default(). We're moving references to Roster.default() out to the using code, so that eventually we can make those explicit references to other Roster objects as/when needed.
- See Also:
RosterEntry
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrit.XmlFile
XmlFile.Validate
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ADD
Name for the property change fired when adding a roster entry.static java.lang.String
ALLENTRIES
Title of the "All Entries" roster group.static java.lang.String
CHANGE
Name for the property change fired when changing the ID of a roster entry.static java.lang.String
DEFAULT_ROSTER_INDEX
Name of the default roster index file.static java.lang.String
REMOVE
Name for the property change fired when removing a roster entry.static java.lang.String
ROSTER_GROUP_ADDED
Property change fired when adding a roster group.static java.lang.String
ROSTER_GROUP_PREFIX
String prefixed to roster group names in the roster entry XML.static java.lang.String
ROSTER_GROUP_REMOVED
Property change fired when removing a roster group.static java.lang.String
ROSTER_GROUP_RENAMED
Property change fired when renaming a roster group.static java.lang.String
SAVED
Property change event fired when saving the roster.static java.lang.String
schemaVersion
-
Fields inherited from class jmri.jmrit.XmlFile
dtdLocation, xsltLocation
-
Fields inherited from interface jmri.jmrit.roster.rostergroup.RosterGroupSelector
SELECTED_ROSTER_GROUP
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEntry(RosterEntry e)
Add a RosterEntry object to the in-memory Roster.void
addPropertyChangeListener(java.beans.PropertyChangeListener l)
Add aPropertyChangeListener
to the listener list.void
addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
Add aPropertyChangeListener
for a specific property.void
addRosterGroup(java.lang.String rg)
Add a roster group, notifying all listeners of the change.void
addRosterGroup(RosterGroup rg)
Add a roster group, notifying all listeners of the change.void
addRosterGroups(java.util.List<RosterGroup> groups)
Add a list ofRosterGroup
.static java.lang.String
allEntries(java.util.Locale locale)
Get the identifier for all entries in the roster.boolean
checkEntry(int i, java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group)
Check if an entry is consistent with specific properties.boolean
checkEntry(java.util.List<RosterEntry> list, int i, java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group)
Check if an entry is consistent with specific properties.boolean
checkEntry(RosterEntry r, java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group, java.lang.String developerID, java.lang.String manufacturerID, java.lang.String productID)
Check if an entry is consistent with specific properties.void
copyRosterGroupList(java.lang.String oldName, java.lang.String newName)
Copy a roster group, adding every entry in the roster group to the new group.void
delRosterGroupList(java.lang.String rg)
Delete a roster group, notifying all listeners of the change.void
dispose()
RosterEntry
entryFromTitle(java.lang.String title)
Return RosterEntry from a "title" string, ala selection in matchingComboBox.void
entryIdChanged(RosterEntry r)
Notify that the ID of an entry has changed.java.lang.String
fileFromTitle(java.lang.String title)
Return filename from a "title" string, ala selection in matchingComboBox.protected void
firePropertyChange(java.lang.String p, java.lang.Object old, java.lang.Object n)
java.util.Set<java.lang.String>
getAllAttributeKeys()
java.util.List<RosterEntry>
getAllEntries()
Get all roster entries.(package private) static java.lang.String[]
getAllFileNames()
Get an array of all the RosterEntry-containing files in the target directory.static Roster
getDefault()
Get the roster for the profile returned byProfileManager.getActiveProfile()
.java.lang.String
getDefaultRosterGroup()
java.util.List<RosterEntry>
getEntriesByDccAddress(java.lang.String a)
Return a list of RosterEntry which have a particular DCC address.java.util.List<RosterEntry>
getEntriesInGroup(java.lang.String group)
java.util.List<RosterEntry>
getEntriesMatchingCriteria(java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group)
Get a List ofRosterEntry
objects in Roster matching some information.java.util.List<RosterEntry>
getEntriesMatchingCriteria(java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group, java.lang.String developerID, java.lang.String manufacturerID, java.lang.String productID)
Get a List ofRosterEntry
objects in Roster matching some information.java.util.List<RosterEntry>
getEntriesWithAttributeKey(java.lang.String key)
java.util.List<RosterEntry>
getEntriesWithAttributeKeyValue(java.lang.String key, java.lang.String value)
RosterEntry
getEntry(int i)
Return a specific entry by indexRosterEntry
getEntryForId(java.lang.String id)
Return RosterEntry from a "id" string.RosterEntry
getGroupEntry(java.lang.String group, int i)
Get the Nth RosterEntry in the groupint
getGroupIndex(java.lang.String group, RosterEntry re)
java.beans.PropertyChangeListener[]
getPropertyChangeListeners()
Get allPropertyChangeListener
s currently attached to this object.java.beans.PropertyChangeListener[]
getPropertyChangeListeners(java.lang.String propertyName)
Get allPropertyChangeListener
s currently listening to changes to the specified property.static Roster
getRoster(Profile profile)
Get the roster for the specified profile.java.lang.String
getRosterFilesLocation()
java.util.ArrayList<java.lang.String>
getRosterGroupList()
Get a list of the user defined roster group names.static java.lang.String
getRosterGroupName(java.lang.String rosterGroup)
static java.lang.String
getRosterGroupProperty(java.lang.String name)
Get the string for a RosterGroup property in a RosterEntryjava.util.HashMap<java.lang.String,RosterGroup>
getRosterGroups()
Get the groups known to the roster itself.java.lang.String
getRosterIndexFileName()
java.lang.String
getRosterIndexPath()
java.lang.String
getRosterLocation()
Absolute path to roster file location.java.lang.String
getSelectedRosterGroup()
Get the default roster group.(package private) boolean
isDirty()
static java.lang.String
makeValidFilename(java.lang.String entry)
Name a valid roster entry filename from an entry name.java.util.List<RosterEntry>
matchingList(java.lang.String dccAddress, java.lang.String productID)
Get a List ofRosterEntry
objects in Roster matching some information.java.util.List<RosterEntry>
matchingList(java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id)
Get a List ofRosterEntry
objects in Roster matching some information.java.util.List<RosterEntry>
matchingList(java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String developerID, java.lang.String manufacturerID, java.lang.String productID)
Get a List ofRosterEntry
objects in Roster matching some information.int
numEntries()
int
numGroupEntries(java.lang.String group)
void
propertyChange(java.beans.PropertyChangeEvent evt)
(package private) void
readFile(java.lang.String name)
Read the contents of a roster XML file into this object.void
reindex()
Rebuild the Roster index and store it.void
reloadRosterFile()
Update the in-memory Roster to be consistent with the current roster file.void
remapRosterGroup(RosterGroup group, java.lang.String newKey)
Changes the key used to lookup a RosterGroup by name.void
removeEntry(RosterEntry e)
Remove a RosterEntry object from the in-memory Roster.void
removePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove the specified listener from this object.void
removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
Remove the specified listener of the specified property from this object.void
removeRosterGroup(RosterGroup rg)
void
renameRosterGroupList(java.lang.String oldName, java.lang.String newName)
Rename a roster group, while keeping every entry in the roster group.void
rosterGroupRenamed(java.lang.String oldName, java.lang.String newName)
void
setDefaultRosterGroup(java.lang.String defaultRosterGroup)
(package private) void
setDirty(boolean b)
void
setRosterIndexFileName(java.lang.String fileName)
void
setRosterLocation(java.lang.String f)
Set the default location for the Roster file, and all individual locomotive files.(package private) void
writeFile(java.io.File file)
Write the entire roster to a file object.(package private) void
writeFile(java.lang.String name)
Write the entire roster to a file.void
writeRoster()
Store the roster in the default place, including making a backup if needed.-
Methods inherited from class jmri.jmrit.XmlFile
addDefaultInfo, backupFileName, checkFile, createFileNameWithDate, dumpElement, findFile, getBuilder, getDefaultDtdLocation, getDefaultValidate, getDtdLocation, getProcessingInstructionHRef, getProcessingInstructionType, getRoot, getValidate, makeBackupFile, makeBackupFile, newDocument, newDocument, revertBackupFile, rootFromFile, rootFromInputStream, rootFromName, rootFromURL, setDefaultDtdLocation, setDefaultValidate, setDtdLocation, setValidate, userFileChooser, userFileChooser, writeXML, xmlDir
-
-
-
-
Field Detail
-
schemaVersion
public static final java.lang.String schemaVersion
- See Also:
- Constant Field Values
-
DEFAULT_ROSTER_INDEX
public static final java.lang.String DEFAULT_ROSTER_INDEX
Name of the default roster index file. "roster.xml"- See Also:
- Constant Field Values
-
ADD
public static final java.lang.String ADD
Name for the property change fired when adding a roster entry. "add"- See Also:
- Constant Field Values
-
REMOVE
public static final java.lang.String REMOVE
Name for the property change fired when removing a roster entry. "remove"- See Also:
- Constant Field Values
-
CHANGE
public static final java.lang.String CHANGE
Name for the property change fired when changing the ID of a roster entry. "change"- See Also:
- Constant Field Values
-
SAVED
public static final java.lang.String SAVED
Property change event fired when saving the roster. "saved"- See Also:
- Constant Field Values
-
ROSTER_GROUP_ADDED
public static final java.lang.String ROSTER_GROUP_ADDED
Property change fired when adding a roster group. "RosterGroupAdded"- See Also:
- Constant Field Values
-
ROSTER_GROUP_REMOVED
public static final java.lang.String ROSTER_GROUP_REMOVED
Property change fired when removing a roster group. "RosterGroupRemoved"- See Also:
- Constant Field Values
-
ROSTER_GROUP_RENAMED
public static final java.lang.String ROSTER_GROUP_RENAMED
Property change fired when renaming a roster group. "RosterGroupRenamed"- See Also:
- Constant Field Values
-
ROSTER_GROUP_PREFIX
public static final java.lang.String ROSTER_GROUP_PREFIX
String prefixed to roster group names in the roster entry XML. "RosterGroup:"- See Also:
- Constant Field Values
-
ALLENTRIES
public static final java.lang.String ALLENTRIES
Title of the "All Entries" roster group. As this varies by locale, do not rely on being able to store this value.
-
-
Method Detail
-
getDefault
public static Roster getDefault()
Get the roster for the profile returned byProfileManager.getActiveProfile()
.- Returns:
- the roster for the active profile
-
getRoster
@Nonnull public static Roster getRoster(@CheckForNull Profile profile)
Get the roster for the specified profile.- Parameters:
profile
- the Profile to get the roster for- Returns:
- the roster for the profile
-
addEntry
public void addEntry(RosterEntry e)
Add a RosterEntry object to the in-memory Roster. This method notifies the UI of changes so should not be used when adding or reloading many roster entries at once.- Parameters:
e
- Entry to add
-
removeEntry
public void removeEntry(RosterEntry e)
Remove a RosterEntry object from the in-memory Roster. This does not delete the file for the RosterEntry!- Parameters:
e
- Entry to remove
-
numEntries
public int numEntries()
- Returns:
- number of entries in the roster
-
numGroupEntries
public int numGroupEntries(java.lang.String group)
- Parameters:
group
- The group being queried or null for all entries in the roster.- Returns:
- The Number of roster entries in the specified group or 0 if the group does not exist.
-
entryFromTitle
public RosterEntry entryFromTitle(java.lang.String title)
Return RosterEntry from a "title" string, ala selection in matchingComboBox.- Parameters:
title
- The title for the RosterEntry.- Returns:
- The matching RosterEntry or null
-
getEntryForId
@CheckForNull public RosterEntry getEntryForId(java.lang.String id)
Return RosterEntry from a "id" string.- Parameters:
id
- The id for the RosterEntry.- Returns:
- The matching RosterEntry or null
-
getEntriesByDccAddress
@Nonnull public java.util.List<RosterEntry> getEntriesByDccAddress(java.lang.String a)
Return a list of RosterEntry which have a particular DCC address.- Parameters:
a
- The address.- Returns:
- a List of matching entries, empty if there are not matches.
-
getEntry
@Nonnull public RosterEntry getEntry(int i)
Return a specific entry by index- Parameters:
i
- The RosterEntry at position i in the roster.- Returns:
- The matching RosterEntry
-
getAllEntries
@Nonnull public java.util.List<RosterEntry> getAllEntries()
Get all roster entries.- Returns:
- a list of roster entries; the list is empty if the roster is empty
-
getGroupEntry
public RosterEntry getGroupEntry(java.lang.String group, int i)
Get the Nth RosterEntry in the group- Parameters:
group
- The group being queried.i
- The index within the group of the requested entry.- Returns:
- The specified entry in the group or null if i is larger than the group, or the group does not exist.
-
getGroupIndex
public int getGroupIndex(java.lang.String group, RosterEntry re)
-
fileFromTitle
public java.lang.String fileFromTitle(java.lang.String title)
Return filename from a "title" string, ala selection in matchingComboBox.- Parameters:
title
- The title for the entry.- Returns:
- The filename for the RosterEntry matching title, or null if no such RosterEntry exists.
-
getEntriesWithAttributeKey
public java.util.List<RosterEntry> getEntriesWithAttributeKey(java.lang.String key)
-
getEntriesWithAttributeKeyValue
public java.util.List<RosterEntry> getEntriesWithAttributeKeyValue(java.lang.String key, java.lang.String value)
-
getAllAttributeKeys
public java.util.Set<java.lang.String> getAllAttributeKeys()
-
getEntriesInGroup
public java.util.List<RosterEntry> getEntriesInGroup(java.lang.String group)
-
getEntriesMatchingCriteria
@Nonnull public java.util.List<RosterEntry> getEntriesMatchingCriteria(java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group, java.lang.String developerID, java.lang.String manufacturerID, java.lang.String productID)
Get a List ofRosterEntry
objects in Roster matching some information. The list will be empty if there are no matches.- Parameters:
roadName
- road name of entry or null for any road nameroadNumber
- road number of entry of null for any numberdccAddress
- address of entry or null for any addressmfg
- manufacturer of entry or null for any manufacturerdecoderModel
- decoder model of entry or null for any modeldecoderFamily
- decoder family of entry or null for any familyid
- id of entry or null for any idgroup
- group entry is member of or null for any groupdeveloperID
- developerID of entry, or null for any developerIDmanufacturerID
- manufacturerID of entry, or null for any manufacturerIDproductID
- productID of entry, or null for any productID- Returns:
- List of matching RosterEntries or an empty List
-
getEntriesMatchingCriteria
@Nonnull public java.util.List<RosterEntry> getEntriesMatchingCriteria(java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group)
Get a List ofRosterEntry
objects in Roster matching some information. The list will be empty if there are no matches.- Parameters:
roadName
- road name of entry or null for any road nameroadNumber
- road number of entry of null for any numberdccAddress
- address of entry or null for any addressmfg
- manufacturer of entry or null for any manufacturerdecoderModel
- decoder model of entry or null for any modeldecoderFamily
- decoder family of entry or null for any familyid
- id of entry or null for any idgroup
- group entry is member of or null for any group- Returns:
- List of matching RosterEntries or an empty List
-
matchingList
@Nonnull public java.util.List<RosterEntry> matchingList(java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id)
Get a List ofRosterEntry
objects in Roster matching some information. The list will be empty if there are no matches.This method calls
getEntriesMatchingCriteria(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
with a null group.- Parameters:
roadName
- road name of entry or null for any road nameroadNumber
- road number of entry of null for any numberdccAddress
- address of entry or null for any addressmfg
- manufacturer of entry or null for any manufacturerdecoderModel
- decoder model of entry or null for any modeldecoderFamily
- decoder family of entry or null for any familyid
- id (unique name) of entry or null for any id- Returns:
- List of matching RosterEntries or an empty List
- See Also:
getEntriesMatchingCriteria(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
-
matchingList
@Nonnull public java.util.List<RosterEntry> matchingList(java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String developerID, java.lang.String manufacturerID, java.lang.String productID)
Get a List ofRosterEntry
objects in Roster matching some information. The list will be empty if there are no matches.This method calls
getEntriesMatchingCriteria(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
with a null group.- Parameters:
roadName
- road name of entry or null for any road nameroadNumber
- road number of entry of null for any numberdccAddress
- address of entry or null for any addressmfg
- manufacturer of entry or null for any manufacturerdecoderModel
- decoder model of entry or null for any modeldecoderFamily
- decoder family of entry or null for any familyid
- id of entry or null for any iddeveloperID
- developerID numbermanufacturerID
- manufacturerID numberproductID
- productID number- Returns:
- List of matching RosterEntries or an empty List
- See Also:
getEntriesMatchingCriteria(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
-
matchingList
@Nonnull public java.util.List<RosterEntry> matchingList(java.lang.String dccAddress, java.lang.String productID)
Get a List ofRosterEntry
objects in Roster matching some information. The list will be empty if there are no matches.This method calls
getEntriesMatchingCriteria(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
with a null group. This pattern is specifically for LNCV (since 4.22).- Parameters:
dccAddress
- address of entry or null for any addressproductID
- productID number- Returns:
- List of matching RosterEntries or an empty List
- See Also:
getEntriesMatchingCriteria(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
-
checkEntry
public boolean checkEntry(int i, java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group)
Check if an entry is consistent with specific properties.A null String argument always matches. Strings are used for convenience in GUI building.
- Parameters:
i
- index in the roster for the RosterEntryroadName
- road name of entry or null for any road nameroadNumber
- road number of entry of null for any numberdccAddress
- address of entry or null for any addressmfg
- manufacturer of entry or null for any manufacturerdecoderModel
- decoder model of entry or null for any modeldecoderFamily
- decoder family of entry or null for any familyid
- id of entry or null for any idgroup
- group entry is member of or null for any group- Returns:
- true if the entry matches
-
checkEntry
public boolean checkEntry(java.util.List<RosterEntry> list, int i, java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group)
Check if an entry is consistent with specific properties.A null String argument always matches. Strings are used for convenience in GUI building.
- Parameters:
list
- the list of RosterEntrys being searchedi
- the index of the roster entry in the listroadName
- road name of entry or null for any road nameroadNumber
- road number of entry of null for any numberdccAddress
- address of entry or null for any addressmfg
- manufacturer of entry or null for any manufacturerdecoderModel
- decoder model of entry or null for any modeldecoderFamily
- decoder family of entry or null for any familyid
- id of entry or null for any idgroup
- group entry is member of or null for any group- Returns:
- True if the entry matches
-
checkEntry
public boolean checkEntry(RosterEntry r, java.lang.String roadName, java.lang.String roadNumber, java.lang.String dccAddress, java.lang.String mfg, java.lang.String decoderModel, java.lang.String decoderFamily, java.lang.String id, java.lang.String group, java.lang.String developerID, java.lang.String manufacturerID, java.lang.String productID)
Check if an entry is consistent with specific properties.A null String argument always matches. Strings are used for convenience in GUI building.
- Parameters:
r
- the roster entry being checkedroadName
- road name of entry or null for any road nameroadNumber
- road number of entry of null for any numberdccAddress
- address of entry or null for any addressmfg
- manufacturer of entry or null for any manufacturerdecoderModel
- decoder model of entry or null for any modeldecoderFamily
- decoder family of entry or null for any familyid
- id of entry or null for any idgroup
- group entry is member of or null for any groupdeveloperID
- developerID of entry, or null for any developerIDmanufacturerID
- manufacturerID of entry, or null for any manufacturerIDproductID
- productID of entry, or null for any productID- Returns:
- True if the entry matches
-
writeFile
void writeFile(java.lang.String name) throws java.io.FileNotFoundException, java.io.IOException
Write the entire roster to a file.Creates a new file with the given name, and then calls writeFile (File) to perform the actual work.
- Parameters:
name
- Filename for new file, including path info as needed.- Throws:
java.io.FileNotFoundException
- if file does not existjava.io.IOException
- if unable to write file
-
writeFile
void writeFile(java.io.File file) throws java.io.IOException
Write the entire roster to a file object. This does not do backup; that has to be done separately. See writeRosterFile() for a public function that finds the default location, does a backup and then calls this.- Parameters:
file
- the file to write to- Throws:
java.io.IOException
- if unable to write file
-
makeValidFilename
public static java.lang.String makeValidFilename(java.lang.String entry)
Name a valid roster entry filename from an entry name.- Replaces all problematic characters with "_".
- Append .xml suffix
- Parameters:
entry
- the getId() entry name from the RosterEntry- Returns:
- Filename for RosterEntry
- Throws:
java.lang.IllegalArgumentException
- if called with null or empty entry name- Since:
- 2.1.5
- See Also:
RosterEntry.ensureFilenameExists()
-
readFile
void readFile(java.lang.String name) throws org.jdom2.JDOMException, java.io.IOException
Read the contents of a roster XML file into this object.Note that this does not clear any existing entries.
- Parameters:
name
- filename of roster file- Throws:
org.jdom2.JDOMException
- if file is invalid XMLjava.io.IOException
- if unable to read file
-
setDirty
void setDirty(boolean b)
-
isDirty
boolean isDirty()
-
dispose
public void dispose()
-
writeRoster
public void writeRoster()
Store the roster in the default place, including making a backup if needed.Uses writeFile(String), a protected method that can write to a specific location.
-
reindex
public void reindex()
Rebuild the Roster index and store it.
-
reloadRosterFile
public void reloadRosterFile()
Update the in-memory Roster to be consistent with the current roster file. This removes any existing roster entries!
-
setRosterIndexFileName
public void setRosterIndexFileName(java.lang.String fileName)
-
getRosterIndexFileName
public java.lang.String getRosterIndexFileName()
-
getRosterIndexPath
public java.lang.String getRosterIndexPath()
-
getRosterFilesLocation
public java.lang.String getRosterFilesLocation()
-
setRosterLocation
public void setRosterLocation(java.lang.String f)
Set the default location for the Roster file, and all individual locomotive files.- Parameters:
f
- Absolute pathname to use. A null or "" argument flags a return to the original default in the user's files directory. This parameter must be a potentially valid path on the system.
-
getRosterLocation
@Nonnull public java.lang.String getRosterLocation()
Absolute path to roster file location.Default is in the user's files directory, but can be set to anything.
- Returns:
- location of the Roster file
- See Also:
FileUtil.getUserFilesPath()
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Description copied from interface:PropertyChangeProvider
Add aPropertyChangeListener
to the listener list.- Specified by:
addPropertyChangeListener
in interfacePropertyChangeProvider
- Specified by:
addPropertyChangeListener
in interfaceRosterGroupSelector
- Parameters:
l
- The PropertyChangeListener to be added
-
addPropertyChangeListener
public void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
Description copied from interface:PropertyChangeProvider
Add aPropertyChangeListener
for a specific property.- Specified by:
addPropertyChangeListener
in interfacePropertyChangeProvider
- Specified by:
addPropertyChangeListener
in interfaceRosterGroupSelector
- Parameters:
propertyName
- The name of the property to listen on.listener
- The PropertyChangeListener to be added
-
firePropertyChange
protected void firePropertyChange(java.lang.String p, java.lang.Object old, java.lang.Object n)
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Description copied from interface:PropertyChangeProvider
Remove the specified listener from this object.- Specified by:
removePropertyChangeListener
in interfacePropertyChangeProvider
- Specified by:
removePropertyChangeListener
in interfaceRosterGroupSelector
- Parameters:
l
- ThePropertyChangeListener
to remove.
-
removePropertyChangeListener
public void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
Description copied from interface:PropertyChangeProvider
Remove the specified listener of the specified property from this object.- Specified by:
removePropertyChangeListener
in interfacePropertyChangeProvider
- Specified by:
removePropertyChangeListener
in interfaceRosterGroupSelector
- Parameters:
propertyName
- The name of the property to stop listening to.listener
- ThePropertyChangeListener
to remove.
-
getPropertyChangeListeners
public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
Description copied from interface:PropertyChangeProvider
Get allPropertyChangeListener
s currently attached to this object.- Specified by:
getPropertyChangeListeners
in interfacePropertyChangeProvider
- Returns:
- An array of PropertyChangeListeners.
-
getPropertyChangeListeners
public java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
Description copied from interface:PropertyChangeProvider
Get allPropertyChangeListener
s currently listening to changes to the specified property.- Specified by:
getPropertyChangeListeners
in interfacePropertyChangeProvider
- Parameters:
propertyName
- the name of the property of interest- Returns:
- an array of PropertyChangeListeners
-
entryIdChanged
public void entryIdChanged(RosterEntry r)
Notify that the ID of an entry has changed. This doesn't actually change the roster contents, but triggers a reordering of the roster contents.- Parameters:
r
- the entry with a changed Id
-
getRosterGroupName
public static java.lang.String getRosterGroupName(java.lang.String rosterGroup)
-
getRosterGroupProperty
public static java.lang.String getRosterGroupProperty(java.lang.String name)
Get the string for a RosterGroup property in a RosterEntry- Parameters:
name
- The name of the rosterGroup- Returns:
- The full property string
-
addRosterGroup
public void addRosterGroup(RosterGroup rg)
Add a roster group, notifying all listeners of the change.This method fires the property change notification "RosterGroupAdded".
- Parameters:
rg
- The group to be added
-
addRosterGroup
public void addRosterGroup(java.lang.String rg)
Add a roster group, notifying all listeners of the change.This method creates a
RosterGroup
. UseaddRosterGroup(jmri.jmrit.roster.rostergroup.RosterGroup)
if you need to add a subclass of RosterGroup. This method fires the property change notification "RosterGroupAdded".- Parameters:
rg
- The name of the group to be added
-
addRosterGroups
public void addRosterGroups(java.util.List<RosterGroup> groups)
Add a list ofRosterGroup
. RosterGroups that are already known to the Roster are ignored.- Parameters:
groups
- RosterGroups to add to the roster. RosterGroups already in the roster will not be added again.
-
removeRosterGroup
public void removeRosterGroup(RosterGroup rg)
-
delRosterGroupList
public void delRosterGroupList(java.lang.String rg)
Delete a roster group, notifying all listeners of the change.This method fires the property change notification ""RosterGroupRemoved"".
- Parameters:
rg
- The group to be deleted
-
copyRosterGroupList
public void copyRosterGroupList(java.lang.String oldName, java.lang.String newName)
Copy a roster group, adding every entry in the roster group to the new group.If a roster group with the target name already exists, this method silently fails to rename the roster group. The GUI method CopyRosterGroupAction.performAction() catches this error and informs the user. This method fires the property change ""RosterGroupAdded"".
- Parameters:
oldName
- Name of the roster group to be copiednewName
- Name of the new roster group- See Also:
RenameRosterGroupAction
-
rosterGroupRenamed
public void rosterGroupRenamed(java.lang.String oldName, java.lang.String newName)
-
renameRosterGroupList
public void renameRosterGroupList(java.lang.String oldName, java.lang.String newName)
Rename a roster group, while keeping every entry in the roster group.If a roster group with the target name already exists, this method silently fails to rename the roster group. The GUI method RenameRosterGroupAction.performAction() catches this error and informs the user. This method fires the property change ""RosterGroupRenamed"".
- Parameters:
oldName
- Name of the roster group to be renamednewName
- New name for the roster group- See Also:
RenameRosterGroupAction
-
getRosterGroupList
public java.util.ArrayList<java.lang.String> getRosterGroupList()
Get a list of the user defined roster group names.Strings are immutable, so deleting an item from the copy should not affect the system-wide list of roster groups.
- Returns:
- A list of the roster group names.
-
allEntries
public static java.lang.String allEntries(java.util.Locale locale)
Get the identifier for all entries in the roster.- Parameters:
locale
- The desired locale- Returns:
- "All Entries" in the specified locale
-
getSelectedRosterGroup
public java.lang.String getSelectedRosterGroup()
Get the default roster group.This method ensures adherence to the RosterGroupSelector protocol
- Specified by:
getSelectedRosterGroup
in interfaceRosterGroupSelector
- Returns:
- The entire roster
-
getDefaultRosterGroup
public java.lang.String getDefaultRosterGroup()
- Returns:
- the defaultRosterGroup
-
setDefaultRosterGroup
public void setDefaultRosterGroup(java.lang.String defaultRosterGroup)
- Parameters:
defaultRosterGroup
- the defaultRosterGroup to set
-
getAllFileNames
static java.lang.String[] getAllFileNames()
Get an array of all the RosterEntry-containing files in the target directory.- Returns:
- the list of file names for entries in this roster
-
getRosterGroups
@Nonnull public java.util.HashMap<java.lang.String,RosterGroup> getRosterGroups()
Get the groups known to the roster itself. Note that changes to the returned Map will not be reflected in the Roster.- Returns:
- the rosterGroups
-
remapRosterGroup
public void remapRosterGroup(RosterGroup group, java.lang.String newKey)
Changes the key used to lookup a RosterGroup by name. This is a helper method that does not fire a notification to any propertyChangeListeners.To rename a RosterGroup, use
RosterGroup.setName(java.lang.String)
.- Parameters:
group
- The group being associated with newKey and will be disassociated with the key matchingRosterGroup.getName()
.newKey
- The new key by which group can be found in the map of RosterGroups. This should match the intended new name of group.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
-