Class DefaultGlobalVariableManager
- java.lang.Object
-
- jmri.beans.PropertyChangeSupport
-
- jmri.beans.VetoableChangeSupport
-
- jmri.managers.AbstractManager<GlobalVariable>
-
- jmri.jmrit.logixng.implementation.DefaultGlobalVariableManager
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.beans.VetoableChangeListener
,java.util.EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,SilenceablePropertyChangeProvider
,VetoableChangeFirer
,VetoableChangeProvider
,GlobalVariableManager
,Manager<GlobalVariable>
public class DefaultGlobalVariableManager extends AbstractManager<GlobalVariable> implements GlobalVariableManager
Class providing the basic logic of the GlobalVariable_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 DefaultGlobalVariableManager
_instance
-
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 DefaultGlobalVariableManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GlobalVariable
createGlobalVariable(java.lang.String userName)
For use with User GUI, to allow the auto generation of systemNames, where the user can optionally supply a username.GlobalVariable
createGlobalVariable(java.lang.String systemName, java.lang.String userName)
Method to create a new GlobalVariable if the GlobalVariable does not exist.void
deleteBean(GlobalVariable globalVariable, java.lang.String property)
Method for a UI to delete a bean.void
deleteGlobalVariable(GlobalVariable x)
Delete GlobalVariable 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.GlobalVariable
getBySystemName(java.lang.String name)
Locate an existing instance based on a system name.GlobalVariable
getByUserName(java.lang.String name)
Locate an existing instance based on a user name.GlobalVariable
getGlobalVariable(java.lang.String name)
Locate via user name, then system name if needed.java.lang.Class<GlobalVariable>
getNamedBeanClass()
Get the class of NamedBean supported by this Manager.int
getXMLOrder()
Determine the order that types should be written when storing panel files.static DefaultGlobalVariableManager
instance()
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.jmrit.logixng.GlobalVariableManager
getAutoSystemName, getSubSystemNamePrefix
-
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.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
-
_instance
static volatile DefaultGlobalVariableManager _instance
-
-
Constructor Detail
-
DefaultGlobalVariableManager
public DefaultGlobalVariableManager()
-
-
Method Detail
-
getXMLOrder
public int getXMLOrder()
Description copied from interface:Manager
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<GlobalVariable>
- Returns:
- write order for this Manager; larger is later.
-
typeLetter
public char typeLetter()
- Specified by:
typeLetter
in interfaceManager<GlobalVariable>
- 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.- Specified by:
validSystemNameFormat
in interfaceManager<GlobalVariable>
- Overrides:
validSystemNameFormat
in classAbstractManager<GlobalVariable>
- Parameters:
systemName
- the system name- Returns:
- enum indicating current validity, which might be just as a prefix
-
createGlobalVariable
public GlobalVariable createGlobalVariable(java.lang.String systemName, java.lang.String userName) throws java.lang.IllegalArgumentException
Method to create a new GlobalVariable if the GlobalVariable does not exist.Returns null if a GlobalVariable with the same systemName or userName already exists, or if there is trouble creating a new GlobalVariable.
- Specified by:
createGlobalVariable
in interfaceGlobalVariableManager
- Parameters:
systemName
- the system nameuserName
- the user name- Returns:
- a new GlobalVariable or null if unable to create
- Throws:
java.lang.IllegalArgumentException
-
createGlobalVariable
public GlobalVariable createGlobalVariable(java.lang.String userName) throws java.lang.IllegalArgumentException
Description copied from interface:GlobalVariableManager
For use with User GUI, to allow the auto generation of systemNames, where the user can optionally supply a username.- Specified by:
createGlobalVariable
in interfaceGlobalVariableManager
- Parameters:
userName
- the user name- Returns:
- a new GlobalVariable or null if unable to create
- Throws:
java.lang.IllegalArgumentException
-
getGlobalVariable
public GlobalVariable getGlobalVariable(java.lang.String name)
Description copied from interface:GlobalVariableManager
Locate via user name, then system name if needed. Does not create a new one if nothing found- Specified by:
getGlobalVariable
in interfaceGlobalVariableManager
- Parameters:
name
- User name or system name to match- Returns:
- null if no match found
-
getByUserName
public GlobalVariable getByUserName(java.lang.String name)
Description copied from class:AbstractManager
Locate an existing instance based on a user name.- Specified by:
getByUserName
in interfaceGlobalVariableManager
- Specified by:
getByUserName
in interfaceManager<GlobalVariable>
- Overrides:
getByUserName
in classAbstractManager<GlobalVariable>
- Parameters:
name
- System Name of the required NamedBean- Returns:
- requested NamedBean object or null if none exists
-
getBySystemName
public GlobalVariable getBySystemName(java.lang.String name)
Description copied from class:AbstractManager
Locate an existing instance based on a system name.- Specified by:
getBySystemName
in interfaceGlobalVariableManager
- Specified by:
getBySystemName
in interfaceManager<GlobalVariable>
- Overrides:
getBySystemName
in classAbstractManager<GlobalVariable>
- 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<GlobalVariable>
- 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
-
deleteGlobalVariable
public void deleteGlobalVariable(GlobalVariable x)
Delete GlobalVariable by removing it from the manager. The GlobalVariable must first be deactivated so it stops processing.- Specified by:
deleteGlobalVariable
in interfaceGlobalVariableManager
- Parameters:
x
- the GlobalVariable to delete
-
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 interfaceGlobalVariableManager
- Parameters:
locale
- The locale to be usedwriter
- the stream to print the tree toindent
- the indentation of each level
-
instance
@InvokeOnGuiThread public static DefaultGlobalVariableManager instance()
-
getNamedBeanClass
public java.lang.Class<GlobalVariable> 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<GlobalVariable>
- 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 GlobalVariable globalVariable, @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<GlobalVariable>
- Overrides:
deleteBean
in classAbstractManager<GlobalVariable>
- Parameters:
globalVariable
- 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)
-
-