Class 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
    • Method Detail

      • 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 field
        roadNumber - value to match against roster roadnumber field
        consistNumber - value to match against roster consist number field
        eng1Address - value to match against roster 1st engine address field
        eng2Address - value to match against roster 2nd engine address field
        eng3Address - value to match against roster 3rd engine address field
        eng4Address - value to match against roster 4th engine address field
        eng5Address - value to match against roster 5th engine address field
        eng6Address - value to match against roster 6th engine address field
        id - 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<NceConsistRosterEntrymatchingList​(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 field
        roadNumber - value to match against roster roadnumber field
        consistNumber - value to match against roster consist number field
        eng1Address - value to match against roster 1st engine address field
        eng2Address - value to match against roster 2nd engine address field
        eng3Address - value to match against roster 3rd engine address field
        eng4Address - value to match against roster 4th engine address field
        eng5Address - value to match against roster 5th engine address field
        eng6Address - value to match against roster 6th engine address field
        id - 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 entry
        roadName - value to match against roster roadname field
        roadNumber - value to match against roster roadnumber field
        consistNumber - value to match against roster consist number field
        loco1Address - value to match against roster 1st engine address field
        loco2Address - value to match against roster 2nd engine address field
        loco3Address - value to match against roster 3rd engine address field
        loco4Address - value to match against roster 4th engine address field
        loco5Address - value to match against roster 5th engine address field
        loco6Address - value to match against roster 6th engine address field
        id - 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 found
        java.io.IOException - when fault accessing file
      • readFile

        void readFile​(java.lang.String name)
               throws 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:
        JDOMException - other errors
        java.io.IOException - error accessing file
      • setDirty

        void setDirty​(boolean b)
      • 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
      • firePropertyChange

        protected void firePropertyChange​(java.lang.String p,
                                          java.lang.Object old,
                                          java.lang.Object n)
      • 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