Class BeanTableDataModel<T extends NamedBean>

    • Constructor Summary

      Constructors 
      Constructor Description
      BeanTableDataModel()
      Create a new Bean Table Data Model.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addMouseListenerToHeader​(javax.swing.JTable table)  
      (package private) boolean allowBlockNameChange​(java.lang.String changeType, T bean, java.lang.String newName)
      Determine whether it is safe to rename/remove a Block user name.
      protected abstract void clickOn​(T t)
      Process a click on The value cell.
      protected void configDeleteColumn​(javax.swing.JTable table)  
      javax.swing.JButton configureButton()  
      protected javax.swing.JTable configureJTable​(java.lang.String name, javax.swing.JTable table, javax.swing.RowSorter<? extends javax.swing.table.TableModel> sorter)
      Configure a new table using the given model and row sorter.
      void configureTable​(javax.swing.JTable table)
      Configure a table to have our standard rows and columns.
      protected void configValueColumn​(javax.swing.JTable table)  
      void copyName​(int row, int column)  
      protected void deleteBean​(int row, int col)  
      void dispose()
      Removes property change listeners from Beans.
      protected void doDelete​(T bean)
      Delete the bean after all the checking has been done.
      void editComment​(int row, int column)  
      protected java.lang.String formatToolTip​(java.lang.String comment)
      Format a comment field as a tool tip string.
      protected java.lang.String getBeanType()
      Get String of the Single Bean Type.
      protected abstract T getBySystemName​(java.lang.String name)  
      protected abstract T getByUserName​(java.lang.String name)  
      java.lang.String getCellToolTip​(javax.swing.JTable table, int row, int col)
      Display the comment text for the current row as a tool tip.
      java.lang.Class<?> getColumnClass​(int col)
      int getColumnCount()
      Get Column Count INCLUDING Bean Property Columns.
      java.lang.String getColumnName​(int col)
      int getDisplayDeleteMsg()  
      java.util.function.Predicate<? super T> getFilter()
      Get the filter to select which beans to include in the table.
      protected java.lang.String getHeaderTooltip​(int columnModelIndex)
      Get a ToolTip for a Table Column Header.
      protected abstract Manager<T> getManager()
      Get the Table Model Bean Manager.
      protected abstract java.lang.String getMasterClassName()  
      int getPreferredWidth​(int col)  
      protected int getPropertyColumnCount()
      Get the total number of custom bean property columns.
      protected NamedBeanPropertyDescriptor<?> getPropertyColumnDescriptor​(int column)
      Get the Named Bean Property Descriptor for a given column number.
      int getRowCount()
      abstract java.lang.String getValue​(java.lang.String systemName)
      Get the current Bean state value in human readable form.
      java.lang.Object getValueAt​(int row, int col)
      SYSNAMECOL returns the actual Bean, NOT the System Name.
      boolean isCellEditable​(int row, int col)
      protected boolean isClearUserNameAllowed()
      Is a bean allowed to have the user name cleared?
      javax.swing.JTable makeJTable​(java.lang.String name, javax.swing.table.TableModel model, javax.swing.RowSorter<? extends javax.swing.table.TableModel> sorter)
      Create and configure a new table using the given model and row sorter.
      protected boolean matchPropertyName​(java.beans.PropertyChangeEvent e)
      Is this property event announcing a change this table should display?
      void moveBean​(int row, int column)  
      void persistTable​(javax.swing.JTable table)
      Persist the state of the table after first setting the table to the last persisted state.
      protected void printColumns​(HardcopyWriter w, java.lang.String[] columnStrings, int columnSize)  
      void printTable​(HardcopyWriter w)
      Method to self print or print preview the table.
      void propertyChange​(java.beans.PropertyChangeEvent e)
      void removeName​(int row, int column)  
      void renameBean​(int row, int column)
      Change the bean User Name in a dialog.
      protected void setColumnIdentities​(javax.swing.JTable table)
      Set identities for any columns that need an identity.
      protected void setColumnToHoldButton​(javax.swing.JTable table, int column, javax.swing.JButton sample)
      Service method to setup a column so that it will hold a button for its values.
      void setDisplayDeleteMsg​(int boo)  
      void setFilter​(java.util.function.Predicate<? super T> filter)
      Set the filter to select which beans to include in the table.
      protected void setManager​(Manager<T> man)
      Set the Model Bean Manager.
      void setPropertyColumnsVisible​(javax.swing.JTable table, boolean visible)
      Updates the visibility settings of the property columns.
      void setValueAt​(java.lang.Object value, int row, int col)
      protected void showPopup​(JmriMouseEvent e)
      Display popup menu when right clicked on table cell.
      protected void showTableHeaderPopup​(JmriMouseEvent e, javax.swing.JTable table)
      Show the Table Column Menu.
      void stopPersistingTable​(javax.swing.JTable table)
      Stop persisting the state of the table.
      protected void updateNameList()  
      • Methods inherited from class javax.swing.table.AbstractTableModel

        addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BeanTableDataModel

        public BeanTableDataModel()
        Create a new Bean Table Data Model. The default Manager for the bean type may well be a Proxy Manager.
    • Method Detail

      • getPropertyColumnCount

        protected int getPropertyColumnCount()
        Get the total number of custom bean property columns. Proxy managers will return the total number of custom columns for all hardware types of that Bean type. Single hardware types will return the total just for that hardware.
        Returns:
        total number of custom columns within the table.
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent e)
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
      • matchPropertyName

        protected boolean matchPropertyName​(java.beans.PropertyChangeEvent e)
        Is this property event announcing a change this table should display?

        Note that events will come both from the NamedBeans and also from the manager

        Parameters:
        e - the event to match
        Returns:
        true if the property name is of interest, false otherwise
      • getRowCount

        public int getRowCount()
        Specified by:
        getRowCount in interface javax.swing.table.TableModel
      • getColumnCount

        public int getColumnCount()
        Get Column Count INCLUDING Bean Property Columns.
        Specified by:
        getColumnCount in interface javax.swing.table.TableModel
      • getColumnName

        public java.lang.String getColumnName​(int col)
        Specified by:
        getColumnName in interface javax.swing.table.TableModel
        Overrides:
        getColumnName in class javax.swing.table.AbstractTableModel
      • getColumnClass

        public java.lang.Class<?> getColumnClass​(int col)
        Specified by:
        getColumnClass in interface javax.swing.table.TableModel
        Overrides:
        getColumnClass in class javax.swing.table.AbstractTableModel
      • isCellEditable

        public boolean isCellEditable​(int row,
                                      int col)
        Specified by:
        isCellEditable in interface javax.swing.table.TableModel
        Overrides:
        isCellEditable in class javax.swing.table.AbstractTableModel
      • getValueAt

        public java.lang.Object getValueAt​(int row,
                                           int col)
        SYSNAMECOL returns the actual Bean, NOT the System Name.
        Specified by:
        getValueAt in interface javax.swing.table.TableModel
      • getValue

        public abstract java.lang.String getValue​(java.lang.String systemName)
        Get the current Bean state value in human readable form.
        Parameters:
        systemName - System name of Bean.
        Returns:
        state value in localised human readable form.
      • getManager

        protected abstract Manager<TgetManager()
        Get the Table Model Bean Manager. In many cases, especially around Model startup, this will be the Proxy Manager, which is then changed to the hardware specific manager.
        Returns:
        current Manager in use by the Model.
      • setManager

        protected void setManager​(@Nonnull
                                  Manager<T> man)
        Set the Model Bean Manager. Note that for many Models this may not work as the manager is currently obtained directly from the Action class.
        Parameters:
        man - Bean Manager that the Model should use.
      • clickOn

        protected abstract void clickOn​(T t)
        Process a click on The value cell.
        Parameters:
        t - the Bean that has been clicked.
      • setValueAt

        public void setValueAt​(java.lang.Object value,
                               int row,
                               int col)
        Specified by:
        setValueAt in interface javax.swing.table.TableModel
        Overrides:
        setValueAt in class javax.swing.table.AbstractTableModel
      • deleteBean

        protected void deleteBean​(int row,
                                  int col)
      • doDelete

        protected void doDelete​(T bean)
        Delete the bean after all the checking has been done.

        Separate so that it can be easily subclassed if other functionality is needed.

        Parameters:
        bean - NamedBean to delete
      • configureTable

        public void configureTable​(javax.swing.JTable table)
        Configure a table to have our standard rows and columns. This is optional, in that other table formats can use this table model. But we put it here to help keep it consistent. This also persists the table user interface state.
        Parameters:
        table - JTable to configure
      • setColumnToHoldButton

        protected void setColumnToHoldButton​(javax.swing.JTable table,
                                             int column,
                                             javax.swing.JButton sample)
        Service method to setup a column so that it will hold a button for its values.
        Parameters:
        table - JTable to use
        column - index for column to setup
        sample - typical button, used to determine preferred size
      • dispose

        public void dispose()
        Removes property change listeners from Beans.
      • printTable

        public void printTable​(HardcopyWriter w)
        Method to self print or print preview the table. Printed in equally sized columns across the page with headings and vertical lines between each column. Data is word wrapped within a column. Can handle data as strings, comboboxes or booleans
        Parameters:
        w - the printer writer
      • makeJTable

        public javax.swing.JTable makeJTable​(@Nonnull
                                             java.lang.String name,
                                             @Nonnull
                                             javax.swing.table.TableModel model,
                                             @CheckForNull
                                             javax.swing.RowSorter<? extends javax.swing.table.TableModel> sorter)
        Create and configure a new table using the given model and row sorter.
        Parameters:
        name - the name of the table
        model - the data model for the table
        sorter - the row sorter for the table; if null, the table will not be sortable
        Returns:
        the table
        Throws:
        java.lang.NullPointerException - if name or model is null
      • configureJTable

        protected javax.swing.JTable configureJTable​(@Nonnull
                                                     java.lang.String name,
                                                     @Nonnull
                                                     javax.swing.JTable table,
                                                     @CheckForNull
                                                     javax.swing.RowSorter<? extends javax.swing.table.TableModel> sorter)
        Configure a new table using the given model and row sorter.
        Parameters:
        table - the table to configure
        name - the table name
        sorter - the row sorter for the table; if null, the table will not be sortable
        Returns:
        the table
        Throws:
        java.lang.NullPointerException - if table or the table name is null
      • getBeanType

        protected java.lang.String getBeanType()
        Get String of the Single Bean Type. In many cases the return is Bundle localised so should not be used for matching Bean types.
        Returns:
        Bean Type String.
      • setPropertyColumnsVisible

        public void setPropertyColumnsVisible​(javax.swing.JTable table,
                                              boolean visible)
        Updates the visibility settings of the property columns.
        Parameters:
        table - the JTable object for the current display.
        visible - true to make the property columns visible, false to hide.
      • isClearUserNameAllowed

        protected boolean isClearUserNameAllowed()
        Is a bean allowed to have the user name cleared?
        Returns:
        true if clear is allowed, false otherwise
      • showPopup

        protected void showPopup​(JmriMouseEvent e)
        Display popup menu when right clicked on table cell.

        Copy UserName Rename Remove UserName Move Edit Comment Delete

        Parameters:
        e - source event.
      • copyName

        public void copyName​(int row,
                             int column)
      • renameBean

        public void renameBean​(int row,
                               int column)
        Change the bean User Name in a dialog.
        Parameters:
        row - table model row number of bean
        column - always passed in as 0, not used
      • removeName

        public void removeName​(int row,
                               int column)
      • allowBlockNameChange

        boolean allowBlockNameChange​(java.lang.String changeType,
                                     T bean,
                                     java.lang.String newName)
        Determine whether it is safe to rename/remove a Block user name.

        The user name is used by the LayoutBlock to link to the block and by Layout Editor track components to link to the layout block.

        Parameters:
        changeType - This will be Remove or Rename.
        bean - The affected bean. Only the Block bean is of interest.
        newName - For Remove this will be empty, for Rename it will be the new user name.
        Returns:
        true to continue with the user name change.
      • moveBean

        public void moveBean​(int row,
                             int column)
      • editComment

        public void editComment​(int row,
                                int column)
      • getCellToolTip

        public java.lang.String getCellToolTip​(javax.swing.JTable table,
                                               int row,
                                               int col)
        Display the comment text for the current row as a tool tip. Most of the bean tables use the standard model with comments in column 3.
        Parameters:
        table - The current table.
        row - The current row.
        col - The current column.
        Returns:
        a formatted tool tip or null if there is none.
      • getHeaderTooltip

        @OverridingMethodsMustInvokeSuper
        protected java.lang.String getHeaderTooltip​(int columnModelIndex)
        Get a ToolTip for a Table Column Header.
        Parameters:
        columnModelIndex - the model column number.
        Returns:
        ToolTip, else null.
      • formatToolTip

        protected java.lang.String formatToolTip​(java.lang.String comment)
        Format a comment field as a tool tip string. Multi line comments are supported.
        Parameters:
        comment - The comment string.
        Returns:
        a html formatted string or null if the comment is empty.
      • showTableHeaderPopup

        protected void showTableHeaderPopup​(JmriMouseEvent e,
                                            javax.swing.JTable table)
        Show the Table Column Menu.
        Parameters:
        e - Instigating event ( e.g. from Mouse click )
        table - table to get columns from
      • persistTable

        public void persistTable​(@Nonnull
                                 javax.swing.JTable table)
                          throws java.lang.NullPointerException
        Persist the state of the table after first setting the table to the last persisted state.
        Parameters:
        table - the table to persist
        Throws:
        java.lang.NullPointerException - if the name of the table is null
      • stopPersistingTable

        public void stopPersistingTable​(@Nonnull
                                        javax.swing.JTable table)
                                 throws java.lang.NullPointerException
        Stop persisting the state of the table.
        Parameters:
        table - the table to stop persisting
        Throws:
        java.lang.NullPointerException - if the name of the table is null
      • setColumnIdentities

        protected void setColumnIdentities​(javax.swing.JTable table)
        Set identities for any columns that need an identity. It is recommended that all columns get a constant identity to prevent identities from being subject to changes due to translation.

        The default implementation sets column identities to the String Column# where # is the model index for the column. Note that if the TableColumnModel is a XTableColumnModel, the index includes hidden columns.

        Parameters:
        table - the table to set identities for.
      • setFilter

        public void setFilter​(java.util.function.Predicate<? super T> filter)
        Set the filter to select which beans to include in the table.
        Parameters:
        filter - the filter
      • getFilter

        public java.util.function.Predicate<? super TgetFilter()
        Get the filter to select which beans to include in the table.
        Returns:
        the filter