Class NceConsistRoster
- java.lang.Object
-
- jmri.jmrit.XmlFile
-
- jmri.jmrix.nce.consist.NceConsistRoster
-
- All Implemented Interfaces:
InstanceManagerAutoDefault
,InstanceManagerAutoInitialize
public class NceConsistRoster extends XmlFile implements InstanceManagerAutoDefault, InstanceManagerAutoInitialize
NCE Consist Roster manages and manipulates a roster of consists.It works with the "consist-roster-config" XML DTD 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.
This predates the "XmlFile" base class, so doesn't use it. Not sure whether it should...
The only bound property is the list of s; 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.
- See Also:
NceConsistRosterEntry
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrit.XmlFile
XmlFile.Validate
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<NceConsistRosterEntry>
_list
List of contained RosterEntry elements.(package private) java.beans.PropertyChangeSupport
pcs
-
Fields inherited from class jmri.jmrit.XmlFile
dtdLocation, xsltLocation
-
-
Constructor Summary
Constructors Constructor Description NceConsistRoster()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEntry(NceConsistRosterEntry e)
Add a RosterEntry object to the in-memory Roster.void
addPropertyChangeListener(java.beans.PropertyChangeListener l)
boolean
checkEntry(int i, java.lang.String roadName, java.lang.String roadNumber, java.lang.String consistNumber, java.lang.String loco1Address, java.lang.String loco2Address, java.lang.String loco3Address, java.lang.String loco4Address, java.lang.String loco5Address, java.lang.String loco6Address, java.lang.String id)
Check if an entry consistent with specific properties.static java.lang.String
defaultNceConsistRosterFilename()
Return the filename String for the default ConsistRoster file, including location.void
dispose()
NceConsistRosterEntry
entryFromTitle(java.lang.String title)
Return RosterEntry from a "title" string, ala selection in matchingComboBoxvoid
entryIdChanged(NceConsistRosterEntry r)
Notify that the ID of an entry has changed.protected void
firePropertyChange(java.lang.String p, java.lang.Object old, java.lang.Object n)
javax.swing.JComboBox<java.lang.String>
fullRosterComboBox()
Return a combo box containing the entire ConsistRoster.void
initialize()
Perform any initialization that occurs after this object has been constructed and made available by the InstanceManager.(package private) boolean
isDirty()
javax.swing.JComboBox<java.lang.String>
matchingComboBox(java.lang.String roadName, java.lang.String roadNumber, java.lang.String consistNumber, java.lang.String eng1Address, java.lang.String eng2Address, java.lang.String eng3Address, java.lang.String eng4Address, java.lang.String eng5Address, java.lang.String eng6Address, java.lang.String id)
Get a JComboBox representing the choices that match.java.util.List<NceConsistRosterEntry>
matchingList(java.lang.String roadName, java.lang.String roadNumber, java.lang.String consistNumber, java.lang.String eng1Address, java.lang.String eng2Address, java.lang.String eng3Address, java.lang.String eng4Address, java.lang.String eng5Address, java.lang.String eng6Address, java.lang.String id)
Get a List of entries matching some information.int
numEntries()
(package private) void
readFile(java.lang.String name)
Read the contents of a roster XML file into this object.void
reloadRosterFile()
update the in-memory Roster to be consistent with the current roster file.void
removeEntry(NceConsistRosterEntry e)
Remove a RosterEntry object from the in-memory Roster.void
removePropertyChangeListener(java.beans.PropertyChangeListener l)
(package private) void
setDirty(boolean b)
static void
setNceConsistRosterFileName(java.lang.String name)
void
updateComboBox(javax.swing.JComboBox<java.lang.String> box)
(package private) void
writeFile(java.lang.String name)
Write the entire roster to a file.void
writeRosterFile()
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
-
_list
protected java.util.List<NceConsistRosterEntry> _list
List of contained RosterEntry elements.
-
pcs
java.beans.PropertyChangeSupport pcs
-
-
Constructor Detail
-
NceConsistRoster
public NceConsistRoster()
-
-
Method Detail
-
addEntry
public void addEntry(NceConsistRosterEntry e)
Add a RosterEntry object to the in-memory Roster.- Parameters:
e
- Entry to add
-
removeEntry
public void removeEntry(NceConsistRosterEntry 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
-
fullRosterComboBox
public javax.swing.JComboBox<java.lang.String> fullRosterComboBox()
Return a combo box containing the entire ConsistRoster.This is based on a single model, so it can be updated when the ConsistRoster changes.
- Returns:
- combo box of whole roster
-
matchingComboBox
public javax.swing.JComboBox<java.lang.String> matchingComboBox(java.lang.String roadName, java.lang.String roadNumber, java.lang.String consistNumber, java.lang.String eng1Address, java.lang.String eng2Address, java.lang.String eng3Address, java.lang.String eng4Address, java.lang.String eng5Address, java.lang.String eng6Address, java.lang.String id)
Get a JComboBox representing the choices that match. There's 10 elements.- Parameters:
roadName
- value to match against roster roadname fieldroadNumber
- value to match against roster roadnumber fieldconsistNumber
- value to match against roster consist number fieldeng1Address
- value to match against roster 1st engine address fieldeng2Address
- value to match against roster 2nd engine address fieldeng3Address
- value to match against roster 3rd engine address fieldeng4Address
- value to match against roster 4th engine address fieldeng5Address
- value to match against roster 5th engine address fieldeng6Address
- value to match against roster 6th engine address fieldid
- value to match against roster id field- Returns:
- combo box of matching roster entries
-
updateComboBox
public void updateComboBox(javax.swing.JComboBox<java.lang.String> box)
-
entryFromTitle
public NceConsistRosterEntry entryFromTitle(java.lang.String title)
Return RosterEntry from a "title" string, ala selection in matchingComboBox- Parameters:
title
- title to search for in consist roster- Returns:
- matching consist roster entry
-
matchingList
public java.util.List<NceConsistRosterEntry> matchingList(java.lang.String roadName, java.lang.String roadNumber, java.lang.String consistNumber, java.lang.String eng1Address, java.lang.String eng2Address, java.lang.String eng3Address, java.lang.String eng4Address, java.lang.String eng5Address, java.lang.String eng6Address, java.lang.String id)
Get a List of entries matching some information. The list may have null contents.- Parameters:
roadName
- value to match against roster roadname fieldroadNumber
- value to match against roster roadnumber fieldconsistNumber
- value to match against roster consist number fieldeng1Address
- value to match against roster 1st engine address fieldeng2Address
- value to match against roster 2nd engine address fieldeng3Address
- value to match against roster 3rd engine address fieldeng4Address
- value to match against roster 4th engine address fieldeng5Address
- value to match against roster 5th engine address fieldeng6Address
- value to match against roster 6th engine address fieldid
- value to match against roster id field- Returns:
- list of consist roster entries matching request
-
checkEntry
public boolean checkEntry(int i, java.lang.String roadName, java.lang.String roadNumber, java.lang.String consistNumber, java.lang.String loco1Address, java.lang.String loco2Address, java.lang.String loco3Address, java.lang.String loco4Address, java.lang.String loco5Address, java.lang.String loco6Address, java.lang.String id)
Check if an entry consistent with specific properties. A null String entry always matches. Strings are used for convenience in GUI building.- Parameters:
i
- index to consist roster entryroadName
- value to match against roster roadname fieldroadNumber
- value to match against roster roadnumber fieldconsistNumber
- value to match against roster consist number fieldloco1Address
- value to match against roster 1st engine address fieldloco2Address
- value to match against roster 2nd engine address fieldloco3Address
- value to match against roster 3rd engine address fieldloco4Address
- value to match against roster 4th engine address fieldloco5Address
- value to match against roster 5th engine address fieldloco6Address
- value to match against roster 6th engine address fieldid
- value to match against roster id field- Returns:
- true if values provided matches indexed entry
-
writeFile
void writeFile(java.lang.String name) throws java.io.FileNotFoundException, java.io.IOException
Write the entire roster to a file. This does not do backup; that has to be done separately. See writeRosterFile() for a function that finds the default location, does a backup and then calls this.- Parameters:
name
- Filename for new file, including path info as needed.- Throws:
java.io.FileNotFoundException
- when file not foundjava.io.IOException
- when fault accessing file
-
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
- file name for consist roster- Throws:
org.jdom2.JDOMException
- other errorsjava.io.IOException
- error accessing file
-
setDirty
void setDirty(boolean b)
-
isDirty
boolean isDirty()
-
dispose
public void dispose()
-
writeRosterFile
public void writeRosterFile()
Store the roster in the default place, including making a backup if needed
-
reloadRosterFile
public void reloadRosterFile()
update the in-memory Roster to be consistent with the current roster file. This removes the existing roster entries!
-
defaultNceConsistRosterFilename
public static java.lang.String defaultNceConsistRosterFilename()
Return the filename String for the default ConsistRoster file, including location.- Returns:
- consist roster file name
-
setNceConsistRosterFileName
public static void setNceConsistRosterFileName(java.lang.String name)
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
-
firePropertyChange
protected void firePropertyChange(java.lang.String p, java.lang.Object old, java.lang.Object n)
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
-
entryIdChanged
public void entryIdChanged(NceConsistRosterEntry r)
Notify that the ID of an entry has changed. This doesn't actually change the ConsistRoster per se, but triggers recreation.- Parameters:
r
- consist roster to recreate due to changes
-
initialize
public void initialize()
Description copied from interface:InstanceManagerAutoInitialize
Perform any initialization that occurs after this object has been constructed and made available by the InstanceManager.- Specified by:
initialize
in interfaceInstanceManagerAutoInitialize
-
-