Class 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 interface Manager<NamedTable>
        Returns:
        write order for this Manager; larger is later.
      • 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 interface NamedTableManager
        Parameters:
        systemName - the system name of the table
        userName - the user name of the table, or null if no user name
        fileName - the file name of the CSV file
        Returns:
        the new table
        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 interface NamedTableManager
        Parameters:
        systemName - the system name of the table
        userName - the user name of the table, or null if no user name
        numRows - number of rows in the table
        numColumns - 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 interface NamedTableManager
        Parameters:
        numRows - number of rows in the table
        numColumns - number of columns in the table
        Returns:
        the new table
        Throws:
        java.lang.IllegalArgumentException
      • 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 interface NamedTableManager
        Parameters:
        name - User name or system name to match
        Returns:
        null if no match found
      • 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 interface Manager<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
      • printTree

        public void printTree​(java.io.PrintWriter writer,
                              java.lang.String indent)
        Print the tree to a stream.
        Specified by:
        printTree in interface NamedTableManager
        Parameters:
        writer - the stream to print the tree to
        indent - 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 interface NamedTableManager
        Parameters:
        locale - The locale to be used
        writer - the stream to print the tree to
        indent - the indentation of each level
      • getNamedBeanClass

        public java.lang.Class<NamedTablegetNamedBeanClass()
        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 interface Manager<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 interface Manager<NamedTable>
        Overrides:
        deleteBean in class AbstractManager<NamedTable>
        Parameters:
        namedTable - The NamedBean to be deleted
        property - 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)