Class BeanTableDataModel<T extends NamedBean>

java.lang.Object
javax.swing.table.AbstractTableModel
jmri.jmrit.beantable.BeanTableDataModel<T>
Type Parameters:
T - the type of NamedBean supported by this model
All Implemented Interfaces:
PropertyChangeListener, Serializable, EventListener, TableModel
Direct Known Subclasses:
AbstractLogixNGTableAction.TableModel, AudioTableAction.AudioTableDataModel, BlockTableDataModel, IdTagTableDataModel, LightTableDataModel, LRouteTableAction.LBeanTableDataModel, MemoryTableDataModel, OBlockTableModel, PickListModel, RailComTableDataModel, ReporterTableDataModel, RouteTableDataModel, SensorTableDataModel, SignalHeadTableModel, SignalMastLogicTableDataModel, SignalMastTableDataModel, StringIOTableDataModel, TurnoutTableDataModel, WarrantTableModel

public abstract class BeanTableDataModel<T extends NamedBean> extends AbstractTableModel implements PropertyChangeListener
Abstract Table data model for display of NamedBean manager contents.
See Also:
  • Field Details

  • Constructor Details

    • BeanTableDataModel

      Create a new Bean Table Data Model. The default Manager for the bean type may well be a Proxy Manager.
  • Method Details

    • 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.
    • getPropertyColumnDescriptor

      Get the Named Bean Property Descriptor for a given column number.
      Parameters:
      column - table column number.
      Returns:
      the descriptor if available, else null.
    • updateNameList

      protected void updateNameList()
    • propertyChange

      Specified by:
      propertyChange in interface PropertyChangeListener
    • matchPropertyName

      protected boolean matchPropertyName(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 TableModel
    • getColumnCount

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

      public String getColumnName(int col)
      Specified by:
      getColumnName in interface TableModel
      Overrides:
      getColumnName in class AbstractTableModel
    • getColumnClass

      public Class<?> getColumnClass(int col)
      Specified by:
      getColumnClass in interface TableModel
      Overrides:
      getColumnClass in class AbstractTableModel
    • isCellEditable

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

      public Object getValueAt(int row, int col)
      SYSNAMECOL returns the actual Bean, NOT the System Name.
      Specified by:
      getValueAt in interface TableModel
    • getPreferredWidth

      public int getPreferredWidth(int col)
    • getValue

      public abstract String getValue(@Nonnull 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<T> getManager()
      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.
    • getBySystemName

      protected abstract T getBySystemName(@Nonnull String name)
    • getByUserName

      protected abstract T getByUserName(@Nonnull String name)
    • clickOn

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

      public int getDisplayDeleteMsg()
    • setDisplayDeleteMsg

      public void setDisplayDeleteMsg(int boo)
    • getMasterClassName

      protected abstract String getMasterClassName()
    • setValueAt

      public void setValueAt(Object value, int row, int col)
      Specified by:
      setValueAt in interface TableModel
      Overrides:
      setValueAt in class 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(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
    • configValueColumn

      protected void configValueColumn(JTable table)
    • configureButton

    • configDeleteColumn

      protected void configDeleteColumn(JTable table)
    • setColumnToHoldButton

      protected void setColumnToHoldButton(JTable table, int column, 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
    • printColumns

      protected void printColumns(HardcopyWriter w, String[] columnStrings, int columnSize)
    • exportToCSV

      public void exportToCSV(File file)
      Export the contents of table to a CSV file.

      The content is exported in column order from the table model

      If the provided file name is null, the user will be prompted with a file dialog.

      Parameters:
      file - file
    • makeJTable

      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:
      NullPointerException - if name or model is null
    • configureJTable

      protected JTable configureJTable(@Nonnull String name, @Nonnull JTable table, @CheckForNull RowSorter<? extends 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:
      NullPointerException - if table or the table name is null
    • getBeanType

      protected 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(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.
    • addEditProperty

      void addEditProperty(int row, int column)
    • copyUserName

      public void copyUserName(int row, int column)
    • copySystemName

      public void copySystemName(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 modelRow, int column)
    • allowBlockNameChange

      boolean allowBlockNameChange(String changeType, T bean, 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 String getCellToolTip(JTable table, int modelRow, int modelCol)
      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.
      modelRow - The current row.
      modelCol - The current column.
      Returns:
      a formatted tool tip or null if there is none.
    • getHeaderTooltip

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

      protected String formatToolTip(String tooltip)
      Format a tool tip string. Multi line tooltips are supported.
      Parameters:
      tooltip - The tooltip string to be formatted
      Returns:
      a html formatted string or null if the comment is empty.
    • showTableHeaderPopup

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

      protected void addMouseListenerToHeader(JTable table)
    • persistTable

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

      Stop persisting the state of the table.
      Parameters:
      table - the table to stop persisting
      Throws:
      NullPointerException - if the name of the table is null
    • setColumnIdentities

      protected void setColumnIdentities(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(Predicate<? super T> filter)
      Set the filter to select which beans to include in the table.
      Parameters:
      filter - the filter
    • getFilter

      public Predicate<? super T> getFilter()
      Get the filter to select which beans to include in the table.
      Returns:
      the filter