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:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class(package private) static class(package private) class(package private) static classListener class which processes Column Menu button clicks.(package private) classListener to trigger display of table cell menu.(package private) classListener to trigger display of table header column menu. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from class javax.swing.table.AbstractTableModel
listenerList -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddEditProperty(int row, int column) protected voidaddMouseListenerToHeader(JTable table) (package private) booleanallowBlockNameChange(String changeType, T bean, String newName) Determine whether it is safe to rename/remove a Block user name.protected abstract voidProcess a click on The value cell.protected voidconfigDeleteColumn(JTable table) protected JTableconfigureJTable(String name, JTable table, RowSorter<? extends TableModel> sorter) Configure a new table using the given model and row sorter.voidconfigureTable(JTable table) Configure a table to have our standard rows and columns.protected voidconfigValueColumn(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 voidDelete the bean after all the checking has been done.voideditComment(int row, int column) voidexportToCSV(File file) Export the contents of table to a CSV file.protected StringformatToolTip(String tooltip) Format a tool tip string.protected StringGet String of the Single Bean Type.protected abstract TgetBySystemName(String name) protected abstract TgetByUserName(String name) getCellToolTip(JTable table, int modelRow, int modelCol) Display the comment text for the current row as a tool tip.Class<?>getColumnClass(int col) intGet Column Count INCLUDING Bean Property Columns.getColumnName(int col) intGet the filter to select which beans to include in the table.protected StringgetHeaderTooltip(int columnModelIndex) Get a ToolTip for a Table Column Header.Get the Table Model Bean Manager.protected abstract StringintgetPreferredWidth(int col) protected intGet the total number of custom bean property columns.protected NamedBeanPropertyDescriptor<?>getPropertyColumnDescriptor(int column) Get the Named Bean Property Descriptor for a given column number.intabstract StringGet the current Bean state value in human readable form.getValueAt(int row, int col) SYSNAMECOL returns the actual Bean, NOT the System Name.booleanisCellEditable(int row, int col) protected booleanIs a bean allowed to have the user name cleared?makeJTable(String name, TableModel model, RowSorter<? extends TableModel> sorter) Create and configure a new table using the given model and row sorter.protected booleanIs this property event announcing a change this table should display?voidmoveBean(int row, int column) voidpersistTable(JTable table) Persist the state of the table after first setting the table to the last persisted state.protected voidprintColumns(HardcopyWriter w, String[] columnStrings, int columnSize) voidMethod to self print or print preview the table.voidvoidremoveName(int modelRow, int column) voidrenameBean(int row, int column) Change the bean User Name in a dialog.protected voidsetColumnIdentities(JTable table) Set identities for any columns that need an identity.protected voidsetColumnToHoldButton(JTable table, int column, JButton sample) Service method to setup a column so that it will hold a button for its values.voidsetDisplayDeleteMsg(int boo) voidSet the filter to select which beans to include in the table.protected voidsetManager(Manager<T> man) Set the Model Bean Manager.voidsetPropertyColumnsVisible(JTable table, boolean visible) Updates the visibility settings of the property columns.voidsetValueAt(Object value, int row, int col) protected voidDisplay popup menu when right clicked on table cell.protected voidshowTableHeaderPopup(JmriMouseEvent e, JTable table) Show the Table Column Menu.voidstopPersistingTable(JTable table) Stop persisting the state of the table.protected voidMethods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
Field Details
-
SYSNAMECOL
- See Also:
-
USERNAMECOL
- See Also:
-
VALUECOL
- See Also:
-
COMMENTCOL
- See Also:
-
DELETECOL
- See Also:
-
NUMCOLUMN
- See Also:
-
sysNameList
-
-
Constructor Details
-
BeanTableDataModel
public BeanTableDataModel()Create a new Bean Table Data Model. The default Manager for the bean type may well be a Proxy Manager.
-
-
Method Details
-
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
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-
matchPropertyName
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
- Specified by:
getRowCountin interfaceTableModel
-
getColumnCount
Get Column Count INCLUDING Bean Property Columns.- Specified by:
getColumnCountin interfaceTableModel
-
getColumnName
- Specified by:
getColumnNamein interfaceTableModel- Overrides:
getColumnNamein classAbstractTableModel
-
getColumnClass
- Specified by:
getColumnClassin interfaceTableModel- Overrides:
getColumnClassin classAbstractTableModel
-
isCellEditable
- Specified by:
isCellEditablein interfaceTableModel- Overrides:
isCellEditablein classAbstractTableModel
-
getValueAt
SYSNAMECOL returns the actual Bean, NOT the System Name.- Specified by:
getValueAtin interfaceTableModel
-
getPreferredWidth
-
getValue
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
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
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
-
getByUserName
-
clickOn
Process a click on The value cell.- Parameters:
t- the Bean that has been clicked.
-
getDisplayDeleteMsg
-
setDisplayDeleteMsg
-
getMasterClassName
-
setValueAt
- Specified by:
setValueAtin interfaceTableModel- Overrides:
setValueAtin classAbstractTableModel
-
deleteBean
-
doDelete
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
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
-
configureButton
-
configDeleteColumn
-
setColumnToHoldButton
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
Removes property change listeners from Beans. -
printTable
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
-
exportToCSV
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 JTable makeJTable(@Nonnull String name, @Nonnull TableModel model, @CheckForNull RowSorter<? extends 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:
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 configurename- the table namesorter- 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
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
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
Is a bean allowed to have the user name cleared?- Returns:
- true if clear is allowed, false otherwise
-
showPopup
Display popup menu when right clicked on table cell.Copy UserName Rename Remove UserName Move Edit Comment Delete
- Parameters:
e- source event.
-
addEditProperty
-
copyUserName
-
copySystemName
-
renameBean
Change the bean User Name in a dialog.- Parameters:
row- table model row number of beancolumn- always passed in as 0, not used
-
removeName
-
allowBlockNameChange
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
-
editComment
-
getCellToolTip
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
Get a ToolTip for a Table Column Header.- Parameters:
columnModelIndex- the model column number.- Returns:
- ToolTip, else null.
-
formatToolTip
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
Show the Table Column Menu.- Parameters:
e- Instigating event ( e.g. from Mouse click )table- table to get columns from
-
addMouseListenerToHeader
-
persistTable
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
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
Set the filter to select which beans to include in the table.- Parameters:
filter- the filter
-
getFilter
Get the filter to select which beans to include in the table.- Returns:
- the filter
-