Class NceConsistRoster

java.lang.Object
jmri.jmrit.XmlFile
jmri.jmrix.nce.consist.NceConsistRoster
All Implemented Interfaces:
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:
  • Field Details

  • Constructor Details

  • Method Details

    • addEntry

      Add a RosterEntry object to the in-memory Roster.
      Parameters:
      e - Entry to add
    • removeEntry

      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

      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 JComboBox<String> matchingComboBox(String roadName, String roadNumber, String consistNumber, String eng1Address, String eng2Address, String eng3Address, String eng4Address, String eng5Address, String eng6Address, 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(JComboBox<String> box)
    • entryFromTitle

      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 List<NceConsistRosterEntry> matchingList(String roadName, String roadNumber, String consistNumber, String eng1Address, String eng2Address, String eng3Address, String eng4Address, String eng5Address, String eng6Address, 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, String roadName, String roadNumber, String consistNumber, String loco1Address, String loco2Address, String loco3Address, String loco4Address, String loco5Address, String loco6Address, 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

      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:
      FileNotFoundException - when file not found
      IOException - when fault accessing file
    • readFile

      void readFile(String name) throws org.jdom2.JDOMException, 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 errors
      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

      Return the filename String for the default ConsistRoster file, including location.
      Returns:
      consist roster file name
    • setNceConsistRosterFileName

      public static void setNceConsistRosterFileName(String name)
    • addPropertyChangeListener

    • firePropertyChange

      protected void firePropertyChange(String p, Object old, Object n)
    • removePropertyChangeListener

    • entryIdChanged

      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 interface InstanceManagerAutoInitialize