Class DefaultNamedTableManager
- java.lang.Object
-
- jmri.beans.PropertyChangeSupport
-
- jmri.beans.VetoableChangeSupport
-
- jmri.managers.AbstractManager<NamedTable>
-
- jmri.jmrit.logixng.implementation.DefaultNamedTableManager
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.beans.VetoableChangeListener
,java.util.EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,SilenceablePropertyChangeProvider
,VetoableChangeFirer
,VetoableChangeProvider
,NamedTableManager
,Manager<NamedTable>
public class DefaultNamedTableManager extends AbstractManager<NamedTable> implements NamedTableManager
Class providing the basic logic of the NamedTable_Manager interface.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.Manager
Manager.ManagerDataEvent<E extends NamedBean>, Manager.ManagerDataListener<E extends NamedBean>, Manager.NameValidity
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static DefaultNamedTableManager
_instance
(package private) java.text.DecimalFormat
paddedNumber
-
Fields inherited from class jmri.managers.AbstractManager
_beans, _tsys, _tuser, memo, silenceableProperties, silencedProperties
-
Fields inherited from class jmri.beans.VetoableChangeSupport
vetoableChangeSupport
-
Fields inherited from class jmri.beans.PropertyChangeSupport
propertyChangeSupport
-
Fields inherited from interface jmri.Manager
ANALOGIOS, AUDIO, BLOCKBOSS, BLOCKS, CONDITIONALS, CTCDATA, ENTRYEXIT, IDTAGS, LAYOUTBLOCKS, LIGHTS, LOGIXNG_ANALOG_ACTIONS, LOGIXNG_ANALOG_EXPRESSIONS, LOGIXNG_CONDITIONALNGS, LOGIXNG_DIGITAL_ACTIONS, LOGIXNG_DIGITAL_BOOLEAN_ACTIONS, LOGIXNG_DIGITAL_EXPRESSIONS, LOGIXNG_GLOBAL_VARIABLES, LOGIXNG_MODULES, LOGIXNG_STRING_ACTIONS, LOGIXNG_STRING_EXPRESSIONS, LOGIXNG_TABLES, LOGIXNGS, LOGIXS, MEMORIES, METERFRAMES, METERS, OBLOCKS, PANELFILES, REPORTERS, ROUTES, SECTIONS, SENSORGROUPS, SENSORS, SIGNALGROUPS, SIGNALHEADS, SIGNALMASTLOGICS, SIGNALMASTS, STRINGIOS, TIMEBASE, TRANSITS, TURNOUTS, WARRANTS
-
-
Constructor Summary
Constructors Constructor Description DefaultNamedTableManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deleteBean(NamedTable namedTable, java.lang.String property)
Method for a UI to delete a bean.void
deleteNamedTable(NamedTable x)
Delete NamedTable by removing it from the manager.void
fireVetoableChange(java.lang.String p, java.lang.Object old)
Inform all registered listeners of a vetoable change.If the propertyName is "CanDelete" ALL listeners with an interest in the bean will throw an exception, which is recorded returned back to the invoking method, so that it can be presented back to the user.However if a listener decides that the bean can not be deleted then it should throw an exception with a property name of "DoNotDelete", this is thrown back up to the user and the delete process should be aborted.java.lang.String
getBeanTypeHandled(boolean plural)
Get the user-readable name of the type of NamedBean handled by this manager.NamedTable
getBySystemName(java.lang.String name)
Locate an existing instance based on a system name.NamedTable
getByUserName(java.lang.String name)
Locate an existing instance based on a user name.java.lang.Class<NamedTable>
getNamedBeanClass()
Get the class of NamedBean supported by this Manager.NamedTable
getNamedTable(java.lang.String name)
Locate via user name, then system name if needed.int
getXMLOrder()
Determine the order that types should be written when storing panel files.static DefaultNamedTableManager
instance()
NamedTable
loadTableFromCSV(java.lang.String sys, java.lang.String user, java.io.File file)
Load a table from a CSV finle.NamedTable
loadTableFromCSV(java.lang.String sys, java.lang.String user, java.lang.String fileName)
Load a table from a CSV finle.NamedTable
loadTableFromCSVData(java.lang.String sys, java.lang.String user, java.lang.String text)
Load a table from a CSV text.AnonymousTable
newAnonymousTable(int numRows, int numColumns)
Create a new anonymous table.NamedTable
newCSVTable(java.lang.String systemName, java.lang.String userName, java.lang.String fileName)
Create a new CSV table.NamedTable
newCSVTable(java.lang.String systemName, java.lang.String userName, java.lang.String fileName, Table.CsvType csvType)
NamedTable
newInternalTable(java.lang.String systemName, java.lang.String userName, int numRows, int numColumns)
Create a new internal named table.void
printTree(java.io.PrintWriter writer, java.lang.String indent)
Print the tree to a stream.void
printTree(java.util.Locale locale, java.io.PrintWriter writer, java.lang.String indent)
Print the tree to a stream.char
typeLetter()
Manager.NameValidity
validSystemNameFormat(java.lang.String systemName)
Test if parameter is a properly formatted system name.-
Methods inherited from class jmri.managers.AbstractManager
addDataListener, checkNumeric, createSystemName, deregister, dispose, fireDataListenersAdded, fireDataListenersRemoved, fireVetoableChange, getAutoSystemName, getBySystemName, getKnownBeanProperties, getMemo, getNamedBean, getNamedBeanSet, getObjectCount, getOuterBean, getSystemPrefix, handleUserNameUniqueness, makeSystemName, propertyChange, register, registerSelf, registerUserName, removeDataListener, setDataListenerMute, setPropertyChangesSilenced, updateAutoNumber, vetoableChange
-
Methods inherited from class jmri.beans.VetoableChangeSupport
addVetoableChangeListener, addVetoableChangeListener, fireVetoableChange, fireVetoableChange, fireVetoableChange, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
Methods inherited from class jmri.beans.PropertyChangeSupport
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.Manager
addDataListener, deregister, dispose, getBeanTypeHandled, getEntryToolTip, getKnownBeanProperties, getMemo, getNamedBean, getNamedBeanSet, getObjectCount, getSystemNamePrefix, getSystemPrefix, isValidSystemNameFormat, makeSystemName, makeSystemName, makeSystemName, register, removeDataListener, setDataListenerMute, validateBadCharsInSystemNameFormat, validateIntegerSystemNameFormat, validateNmraAccessorySystemNameFormat, validateSystemNameFormat, validateSystemNameFormat, validateSystemNameFormatOnlyNumeric, validateSystemNamePrefix, validateTrimmedMin1NumberSystemNameFormat, validateTrimmedSystemNameFormat, validateUppercaseTrimmedSystemNameFormat
-
Methods inherited from interface jmri.jmrit.logixng.NamedTableManager
getAutoSystemName, getSubSystemNamePrefix
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from interface jmri.beans.SilenceablePropertyChangeProvider
setPropertyChangesSilenced
-
Methods inherited from interface jmri.beans.VetoableChangeProvider
addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
-
-
-
Field Detail
-
paddedNumber
java.text.DecimalFormat paddedNumber
-
_instance
static volatile DefaultNamedTableManager _instance
-
-
Constructor Detail
-
DefaultNamedTableManager
public DefaultNamedTableManager()
-
-
Method Detail
-
getXMLOrder
public int getXMLOrder()
Determine the order that types should be written when storing panel files. Uses one of the constants defined in this class.Yes, that's an overly-centralized methodology, but it works for now.
- Specified by:
getXMLOrder
in interfaceManager<NamedTable>
- Returns:
- write order for this Manager; larger is later.
-
typeLetter
public char typeLetter()
- Specified by:
typeLetter
in interfaceManager<NamedTable>
- Returns:
- The type letter for a specific implementation
-
validSystemNameFormat
public Manager.NameValidity validSystemNameFormat(java.lang.String systemName)
Test if parameter is a properly formatted system name. Implementations of this method must not throw an exception, log an error, or otherwise disrupt the user.- Specified by:
validSystemNameFormat
in interfaceManager<NamedTable>
- Overrides:
validSystemNameFormat
in classAbstractManager<NamedTable>
- Parameters:
systemName
- the system name- Returns:
Manager.NameValidity.INVALID
if system name does not start withManager.getSystemNamePrefix()
;Manager.NameValidity.VALID_AS_PREFIX_ONLY
if system name equalsManager.getSystemNamePrefix()
; otherwiseManager.NameValidity.VALID
to allow Managers that do not perform more specific validation to be considered valid.
-
newCSVTable
public NamedTable newCSVTable(java.lang.String systemName, java.lang.String userName, java.lang.String fileName) throws java.lang.IllegalArgumentException
Create a new CSV table. This table is stored in the manager but it's contents does only exists in the CSV file. If the CSV file is changed, the contents will be read on the next start of the program.- Specified by:
newCSVTable
in interfaceNamedTableManager
- Parameters:
systemName
- the system name of the tableuserName
- the user name of the table, or null if no user namefileName
- the file name of the CSV file- Returns:
- the new table
- Throws:
java.lang.IllegalArgumentException
-
newCSVTable
public NamedTable newCSVTable(java.lang.String systemName, java.lang.String userName, java.lang.String fileName, Table.CsvType csvType) throws java.lang.IllegalArgumentException
- Specified by:
newCSVTable
in interfaceNamedTableManager
- Throws:
java.lang.IllegalArgumentException
-
newInternalTable
public NamedTable newInternalTable(java.lang.String systemName, java.lang.String userName, int numRows, int numColumns) throws java.lang.IllegalArgumentException
Create a new internal named table. This table is stored in the manager together with its contents. Note that a big table will take a lot of space in the panel file since the storage of table data has a lot of overhead. For larger tables, a CSV table is recommended.- Specified by:
newInternalTable
in interfaceNamedTableManager
- Parameters:
systemName
- the system name of the tableuserName
- the user name of the table, or null if no user namenumRows
- number of rows in the tablenumColumns
- number of columns in the table- Returns:
- the new table
- Throws:
java.lang.IllegalArgumentException
-
newAnonymousTable
public AnonymousTable newAnonymousTable(int numRows, int numColumns) throws java.lang.IllegalArgumentException
Create a new anonymous table. This table is not stored in the manager.- Specified by:
newAnonymousTable
in interfaceNamedTableManager
- Parameters:
numRows
- number of rows in the tablenumColumns
- number of columns in the table- Returns:
- the new table
- Throws:
java.lang.IllegalArgumentException
-
loadTableFromCSVData
public NamedTable loadTableFromCSVData(@Nonnull java.lang.String sys, @CheckForNull java.lang.String user, @Nonnull java.lang.String text) throws NamedBean.BadUserNameException, NamedBean.BadSystemNameException, java.io.IOException
Load a table from a CSV text.- Specified by:
loadTableFromCSVData
in interfaceNamedTableManager
- Parameters:
sys
- the system name of the new tableuser
- the user name of the new table or null if no user nametext
- the CSV text- Returns:
- the loaded table
- Throws:
java.io.IOException
- in case of an exceptionNamedBean.BadUserNameException
NamedBean.BadSystemNameException
-
loadTableFromCSV
public NamedTable loadTableFromCSV(@Nonnull java.lang.String sys, @CheckForNull java.lang.String user, @Nonnull java.lang.String fileName) throws NamedBean.BadUserNameException, NamedBean.BadSystemNameException, java.io.IOException
Load a table from a CSV finle.- Specified by:
loadTableFromCSV
in interfaceNamedTableManager
- Parameters:
sys
- the system name of the new tableuser
- the user name of the new table or null if no user namefileName
- the file name of the CSV table- Returns:
- the loaded table
- Throws:
java.io.IOException
- in case of an exceptionNamedBean.BadUserNameException
NamedBean.BadSystemNameException
-
loadTableFromCSV
public NamedTable loadTableFromCSV(@Nonnull java.lang.String sys, @CheckForNull java.lang.String user, @Nonnull java.io.File file) throws NamedBean.BadUserNameException, NamedBean.BadSystemNameException, java.io.IOException
Load a table from a CSV finle.- Specified by:
loadTableFromCSV
in interfaceNamedTableManager
- Parameters:
sys
- the system name of the new tableuser
- the user name of the new table or null if no user namefile
- the CSV file- Returns:
- the loaded table
- Throws:
java.io.IOException
- in case of an exceptionNamedBean.BadUserNameException
NamedBean.BadSystemNameException
-
getNamedTable
public NamedTable getNamedTable(java.lang.String name)
Locate via user name, then system name if needed. Does not create a new one if nothing found- Specified by:
getNamedTable
in interfaceNamedTableManager
- Parameters:
name
- User name or system name to match- Returns:
- null if no match found
-
getByUserName
public NamedTable getByUserName(java.lang.String name)
Locate an existing instance based on a user name.- Specified by:
getByUserName
in interfaceManager<NamedTable>
- Specified by:
getByUserName
in interfaceNamedTableManager
- Overrides:
getByUserName
in classAbstractManager<NamedTable>
- Parameters:
name
- System Name of the required NamedBean- Returns:
- requested NamedBean object or null if none exists
-
getBySystemName
public NamedTable getBySystemName(java.lang.String name)
Locate an existing instance based on a system name.- Specified by:
getBySystemName
in interfaceManager<NamedTable>
- Specified by:
getBySystemName
in interfaceNamedTableManager
- Overrides:
getBySystemName
in classAbstractManager<NamedTable>
- Parameters:
name
- System Name of the required NamedBean- Returns:
- requested NamedBean object or null if none exists
-
getBeanTypeHandled
public java.lang.String getBeanTypeHandled(boolean plural)
Get the user-readable name of the type of NamedBean handled by this manager.For instance, in the code where we are dealing with just a bean and a message that needs to be passed to the user or in a log.
- Specified by:
getBeanTypeHandled
in interfaceManager<NamedTable>
- Parameters:
plural
- true to return plural form of the type; false to return singular form- Returns:
- a string of the bean type that the manager handles, eg Turnout, Sensor etc
-
deleteNamedTable
public void deleteNamedTable(NamedTable x)
Delete NamedTable by removing it from the manager.- Specified by:
deleteNamedTable
in interfaceNamedTableManager
- Parameters:
x
- the NamedTable to delete
-
printTree
public void printTree(java.io.PrintWriter writer, java.lang.String indent)
Print the tree to a stream.- Specified by:
printTree
in interfaceNamedTableManager
- Parameters:
writer
- the stream to print the tree toindent
- the indentation of each level
-
printTree
public void printTree(java.util.Locale locale, java.io.PrintWriter writer, java.lang.String indent)
Print the tree to a stream.- Specified by:
printTree
in interfaceNamedTableManager
- Parameters:
locale
- The locale to be usedwriter
- the stream to print the tree toindent
- the indentation of each level
-
instance
@InvokeOnGuiThread public static DefaultNamedTableManager instance()
-
getNamedBeanClass
public java.lang.Class<NamedTable> getNamedBeanClass()
Get the class of NamedBean supported by this Manager. This should be the generic class used in the Manager's class declaration.- Specified by:
getNamedBeanClass
in interfaceManager<NamedTable>
- Returns:
- the class supported by this Manager.
-
fireVetoableChange
@OverridingMethodsMustInvokeSuper public void fireVetoableChange(java.lang.String p, java.lang.Object old) throws java.beans.PropertyVetoException
Inform all registered listeners of a vetoable change.If the propertyName is "CanDelete" ALL listeners with an interest in the bean will throw an exception, which is recorded returned back to the invoking method, so that it can be presented back to the user.However if a listener decides that the bean can not be deleted then it should throw an exception with a property name of "DoNotDelete", this is thrown back up to the user and the delete process should be aborted.- Parameters:
p
- The programmatic name of the property that is to be changed. "CanDelete" will inquire with all listeners if the item can be deleted. "DoDelete" tells the listener to delete the item.old
- The old value of the property.- Throws:
java.beans.PropertyVetoException
- If the recipients wishes the delete to be aborted (see above)
-
deleteBean
public final void deleteBean(@Nonnull NamedTable namedTable, @Nonnull java.lang.String property) throws java.beans.PropertyVetoException
Method for a UI to delete a bean.The UI should first request a "CanDelete", this will return a list of locations (and descriptions) where the bean is in use via throwing a VetoException, then if that comes back clear, or the user agrees with the actions, then a "DoDelete" can be called which inform the listeners to delete the bean, then it will be deregistered and disposed of.
If a property name of "DoNotDelete" is thrown back in the VetoException then the delete process should be aborted.
- Specified by:
deleteBean
in interfaceManager<NamedTable>
- Overrides:
deleteBean
in classAbstractManager<NamedTable>
- Parameters:
namedTable
- The NamedBean to be deletedproperty
- The programmatic name of the request. "CanDelete" will enquire with all listeners if the item can be deleted. "DoDelete" tells the listener to delete the item- Throws:
java.beans.PropertyVetoException
- If the recipients wishes the delete to be aborted (see above)
-
-