Class BeanListTableModel<T>
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- io.github.jonestimd.swing.table.model.BeanListTableModel<T>
-
- Type Parameters:
T
- the class representing a row in the table
- All Implemented Interfaces:
BeanTableModel<T>
,ColumnIdentifier
,java.io.Serializable
,javax.swing.table.TableModel
- Direct Known Subclasses:
BufferedBeanListTableModel
public class BeanListTableModel<T> extends javax.swing.table.AbstractTableModel implements ColumnIdentifier, BeanTableModel<T>
ATableModel
that uses a list of beans for table rows and maps bean properties to table columns.- See Also:
ColumnAdapter
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected BeanTableAdapter<T>
beanTableAdapter
-
Constructor Summary
Constructors Constructor Description BeanListTableModel(java.util.List<? extends ColumnAdapter<? super T,?>> columnAdapters)
BeanListTableModel(java.util.List<? extends ColumnAdapter<? super T,?>> columnAdapters, java.lang.Iterable<? extends TableDataProvider<T>> dataProviders)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRow(int row, T bean)
void
addRow(T bean)
T
getBean(int index)
Get the bean at the specified index.int
getBeanCount()
Get the number of beans in the model.java.util.List<T>
getBeans()
protected ColumnAdapter<? super T,?>
getColumnAdapter(int index)
java.lang.Class<?>
getColumnClass(int columnIndex)
int
getColumnCount()
ColumnAdapter<? super T,?>
getColumnIdentifier(int columnIndex)
java.lang.String
getColumnName(int columnIndex)
java.awt.Cursor
getCursor(java.awt.event.MouseEvent event, javax.swing.JTable table, int rowIndex, int columnIndex)
Get the mouse cursor to display for a cell.T
getRow(int index)
int
getRowCount()
java.lang.Object
getValue(T row, int columnIndex)
Get a column cell value for a bean.java.lang.Object
getValueAt(int rowIndex, int columnIndex)
void
handleClick(java.awt.event.MouseEvent event, javax.swing.JTable table, int rowIndex, int columnIndex)
Handle a mouse click on a cell.int
indexOf(T bean)
boolean
isCellEditable(int rowIndex, int columnIndex)
protected void
notifyDataProviders(T row, java.lang.String columnId, java.lang.Object oldValue)
void
removeAll(java.lang.Iterable<T> rowBeans)
void
removeRow(T bean)
protected void
removeRowAt(int index)
void
setBeans(java.util.Collection<T> beans)
Replace all rows of the table model.void
setRow(int row, T bean)
protected void
setValue(java.lang.Object value, int rowIndex, int columnIndex)
void
setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
void
updateBeans(java.util.Collection<T> beans, java.util.function.BiPredicate<T,T> isEqual)
Update existing rows and add missing rows to the table model.-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Field Detail
-
beanTableAdapter
protected final BeanTableAdapter<T> beanTableAdapter
-
-
Constructor Detail
-
BeanListTableModel
public BeanListTableModel(java.util.List<? extends ColumnAdapter<? super T,?>> columnAdapters)
-
BeanListTableModel
public BeanListTableModel(java.util.List<? extends ColumnAdapter<? super T,?>> columnAdapters, java.lang.Iterable<? extends TableDataProvider<T>> dataProviders)
-
-
Method Detail
-
getBeanCount
public int getBeanCount()
Description copied from interface:BeanTableModel
Get the number of beans in the model. Need not be the same as the number of the rows in the table.- Specified by:
getBeanCount
in interfaceBeanTableModel<T>
-
getBean
public T getBean(int index)
Description copied from interface:BeanTableModel
Get the bean at the specified index.- Specified by:
getBean
in interfaceBeanTableModel<T>
- Parameters:
index
- the index of the bean.
-
getRowCount
public int getRowCount()
- Specified by:
getRowCount
in interfacejavax.swing.table.TableModel
-
getColumnAdapter
protected ColumnAdapter<? super T,?> getColumnAdapter(int index)
-
getColumnCount
public int getColumnCount()
- Specified by:
getColumnCount
in interfacejavax.swing.table.TableModel
-
getColumnName
public java.lang.String getColumnName(int columnIndex)
- Specified by:
getColumnName
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnName
in classjavax.swing.table.AbstractTableModel
-
getColumnClass
public java.lang.Class<?> getColumnClass(int columnIndex)
- Specified by:
getColumnClass
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnClass
in classjavax.swing.table.AbstractTableModel
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)
- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classjavax.swing.table.AbstractTableModel
-
getCursor
public java.awt.Cursor getCursor(java.awt.event.MouseEvent event, javax.swing.JTable table, int rowIndex, int columnIndex)
Description copied from interface:BeanTableModel
Get the mouse cursor to display for a cell.- Specified by:
getCursor
in interfaceBeanTableModel<T>
rowIndex
- the row index of the cellcolumnIndex
- the column index of the cell- Returns:
- the mouse cursor to use for the cell or
null
to use the default cursor.
-
handleClick
public void handleClick(java.awt.event.MouseEvent event, javax.swing.JTable table, int rowIndex, int columnIndex)
Description copied from interface:BeanTableModel
Handle a mouse click on a cell.- Specified by:
handleClick
in interfaceBeanTableModel<T>
- Parameters:
event
- the click eventrowIndex
- the row containing the cellcolumnIndex
- the column index of the cell
-
getRow
public T getRow(int index)
-
setRow
public void setRow(int row, T bean)
-
getColumnIdentifier
public ColumnAdapter<? super T,?> getColumnIdentifier(int columnIndex)
- Specified by:
getColumnIdentifier
in interfaceColumnIdentifier
-
getValueAt
public java.lang.Object getValueAt(int rowIndex, int columnIndex)
- Specified by:
getValueAt
in interfacejavax.swing.table.TableModel
-
setValueAt
public void setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
- Specified by:
setValueAt
in interfacejavax.swing.table.TableModel
- Overrides:
setValueAt
in classjavax.swing.table.AbstractTableModel
-
setValue
protected void setValue(java.lang.Object value, int rowIndex, int columnIndex)
-
notifyDataProviders
protected void notifyDataProviders(T row, java.lang.String columnId, java.lang.Object oldValue)
-
getValue
public java.lang.Object getValue(T row, int columnIndex)
Description copied from interface:BeanTableModel
Get a column cell value for a bean.- Specified by:
getValue
in interfaceBeanTableModel<T>
-
getBeans
public java.util.List<T> getBeans()
-
setBeans
public void setBeans(java.util.Collection<T> beans)
Description copied from interface:BeanTableModel
Replace all rows of the table model.- Specified by:
setBeans
in interfaceBeanTableModel<T>
- Parameters:
beans
- the new rows
-
indexOf
public int indexOf(T bean)
-
addRow
public void addRow(T bean)
-
addRow
public void addRow(int row, T bean)
-
updateBeans
public void updateBeans(java.util.Collection<T> beans, java.util.function.BiPredicate<T,T> isEqual)
Description copied from interface:BeanTableModel
Update existing rows and add missing rows to the table model.- Specified by:
updateBeans
in interfaceBeanTableModel<T>
- Parameters:
beans
- beans to update/appendisEqual
- used to determine if a row is already in the model
-
removeRow
public void removeRow(T bean)
-
removeRowAt
protected void removeRowAt(int index)
-
removeAll
public void removeAll(java.lang.Iterable<T> rowBeans)
-
-