Package jmri.jmrit.beantable
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:
java.beans.PropertyChangeListener,java.io.Serializable,java.util.EventListener,javax.swing.table.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 javax.swing.table.AbstractTableModel implements java.beans.PropertyChangeListener
Abstract Table data model for display of NamedBean manager contents.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classBeanTableDataModel.BeanTableTooltipHeaderRenderer(package private) static classBeanTableDataModel.DateRenderer(package private) classBeanTableDataModel.DeleteBeanWorker(package private) static classBeanTableDataModel.HeaderActionListenerListener class which processes Column Menu button clicks.(package private) classBeanTableDataModel.PopupListenerListener to trigger display of table cell menu.(package private) classBeanTableDataModel.TableHeaderListenerListener to trigger display of table header column menu.
-
Field Summary
Fields Modifier and Type Field Description static intCOMMENTCOLstatic intDELETECOLstatic intNUMCOLUMNstatic intSYSNAMECOLprotected java.util.List<java.lang.String>sysNameListstatic intUSERNAMECOLstatic intVALUECOL
-
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 voidaddMouseListenerToHeader(javax.swing.JTable table)(package private) booleanallowBlockNameChange(java.lang.String changeType, T bean, java.lang.String newName)Determine whether it is safe to rename/remove a Block user name.protected abstract voidclickOn(T t)Process a click on The value cell.protected voidconfigDeleteColumn(javax.swing.JTable table)javax.swing.JButtonconfigureButton()protected javax.swing.JTableconfigureJTable(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.voidconfigureTable(javax.swing.JTable table)Configure a table to have our standard rows and columns.protected voidconfigValueColumn(javax.swing.JTable table)voidcopySystemName(int row, int column)voidcopyUserName(int row, int column)protected voiddeleteBean(int row, int col)voiddispose()Removes property change listeners from Beans.protected voiddoDelete(T bean)Delete the bean after all the checking has been done.voideditComment(int row, int column)voidexportToCSV(java.io.File file)Export the contents of table to a CSV file.protected java.lang.StringformatToolTip(java.lang.String tooltip)Format a tool tip string.protected java.lang.StringgetBeanType()Get String of the Single Bean Type.protected abstract TgetBySystemName(java.lang.String name)protected abstract TgetByUserName(java.lang.String name)java.lang.StringgetCellToolTip(javax.swing.JTable table, int modelRow, int modelCol)Display the comment text for the current row as a tool tip.java.lang.Class<?>getColumnClass(int col)intgetColumnCount()Get Column Count INCLUDING Bean Property Columns.java.lang.StringgetColumnName(int col)intgetDisplayDeleteMsg()java.util.function.Predicate<? super T>getFilter()Get the filter to select which beans to include in the table.protected java.lang.StringgetHeaderTooltip(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.StringgetMasterClassName()intgetPreferredWidth(int col)protected intgetPropertyColumnCount()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.intgetRowCount()abstract java.lang.StringgetValue(java.lang.String systemName)Get the current Bean state value in human readable form.java.lang.ObjectgetValueAt(int row, int col)SYSNAMECOL returns the actual Bean, NOT the System Name.booleanisCellEditable(int row, int col)protected booleanisClearUserNameAllowed()Is a bean allowed to have the user name cleared?javax.swing.JTablemakeJTable(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 booleanmatchPropertyName(java.beans.PropertyChangeEvent e)Is this property event announcing a change this table should display?voidmoveBean(int row, int column)voidpersistTable(javax.swing.JTable table)Persist the state of the table after first setting the table to the last persisted state.protected voidprintColumns(HardcopyWriter w, java.lang.String[] columnStrings, int columnSize)voidprintTable(HardcopyWriter w)Method to self print or print preview the table.voidpropertyChange(java.beans.PropertyChangeEvent e)voidremoveName(int modelRow, int column)voidrenameBean(int row, int column)Change the bean User Name in a dialog.protected voidsetColumnIdentities(javax.swing.JTable table)Set identities for any columns that need an identity.protected voidsetColumnToHoldButton(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.voidsetDisplayDeleteMsg(int boo)voidsetFilter(java.util.function.Predicate<? super T> filter)Set the filter to select which beans to include in the table.protected voidsetManager(Manager<T> man)Set the Model Bean Manager.voidsetPropertyColumnsVisible(javax.swing.JTable table, boolean visible)Updates the visibility settings of the property columns.voidsetValueAt(java.lang.Object value, int row, int col)protected voidshowPopup(JmriMouseEvent e)Display popup menu when right clicked on table cell.protected voidshowTableHeaderPopup(JmriMouseEvent e, javax.swing.JTable table)Show the Table Column Menu.voidstopPersistingTable(javax.swing.JTable table)Stop persisting the state of the table.protected voidupdateNameList()-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Field Detail
-
SYSNAMECOL
public static final int SYSNAMECOL
- See Also:
- Constant Field Values
-
USERNAMECOL
public static final int USERNAMECOL
- See Also:
- Constant Field Values
-
VALUECOL
public static final int VALUECOL
- See Also:
- Constant Field Values
-
COMMENTCOL
public static final int COMMENTCOL
- See Also:
- Constant Field Values
-
DELETECOL
public static final int DELETECOL
- See Also:
- Constant Field Values
-
NUMCOLUMN
public static final int NUMCOLUMN
- See Also:
- Constant Field Values
-
sysNameList
protected java.util.List<java.lang.String> sysNameList
-
-
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.
-
getPropertyColumnDescriptor
@CheckForNull protected NamedBeanPropertyDescriptor<?> getPropertyColumnDescriptor(int column)
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
public void propertyChange(java.beans.PropertyChangeEvent e)
- Specified by:
propertyChangein interfacejava.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:
getRowCountin interfacejavax.swing.table.TableModel
-
getColumnCount
public int getColumnCount()
Get Column Count INCLUDING Bean Property Columns.- Specified by:
getColumnCountin interfacejavax.swing.table.TableModel
-
getColumnName
public java.lang.String getColumnName(int col)
- Specified by:
getColumnNamein interfacejavax.swing.table.TableModel- Overrides:
getColumnNamein classjavax.swing.table.AbstractTableModel
-
getColumnClass
public java.lang.Class<?> getColumnClass(int col)
- Specified by:
getColumnClassin interfacejavax.swing.table.TableModel- Overrides:
getColumnClassin classjavax.swing.table.AbstractTableModel
-
isCellEditable
public boolean isCellEditable(int row, int col)
- Specified by:
isCellEditablein interfacejavax.swing.table.TableModel- Overrides:
isCellEditablein classjavax.swing.table.AbstractTableModel
-
getValueAt
public java.lang.Object getValueAt(int row, int col)
SYSNAMECOL returns the actual Bean, NOT the System Name.- Specified by:
getValueAtin interfacejavax.swing.table.TableModel
-
getPreferredWidth
public int getPreferredWidth(int col)
-
getValue
public abstract java.lang.String getValue(@Nonnull 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<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 java.lang.String name)
-
getByUserName
protected abstract T getByUserName(@Nonnull java.lang.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 java.lang.String getMasterClassName()
-
setValueAt
public void setValueAt(java.lang.Object value, int row, int col)
- Specified by:
setValueAtin interfacejavax.swing.table.TableModel- Overrides:
setValueAtin classjavax.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-JTableto configure
-
configValueColumn
protected void configValueColumn(javax.swing.JTable table)
-
configureButton
public javax.swing.JButton configureButton()
-
configDeleteColumn
protected void configDeleteColumn(javax.swing.JTable table)
-
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-JTableto usecolumn- index for column to setupsample- 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, java.lang.String[] columnStrings, int columnSize)
-
exportToCSV
public void exportToCSV(java.io.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
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 tablemodel- the data model for the tablesorter- 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 configurename- the table namesorter- 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.
-
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 beancolumn- always passed in as 0, not used
-
removeName
public void removeName(int modelRow, 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 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 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 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, javax.swing.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(javax.swing.JTable table)
-
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 aXTableColumnModel, 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
-
-