Class BufferedBeanListTableModel<T>
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- io.github.jonestimd.swing.table.model.BeanListTableModel<T>
-
- io.github.jonestimd.swing.table.model.BufferedBeanListTableModel<T>
-
- All Implemented Interfaces:
ChangeBuffer
,BeanTableModel<T>
,ChangeBufferTableModel<T>
,ColumnIdentifier
,java.io.Serializable
,javax.swing.table.TableModel
- Direct Known Subclasses:
ValidatedBeanListTableModel
public class BufferedBeanListTableModel<T> extends BeanListTableModel<T> implements ChangeBufferTableModel<T>
This class overridesBeanListTableModel
to add change tracking. Changes to cells are queued byBeanListTableModel.setValueAt(Object, int, int)
. The following methods are used to update pending changes for rows:queueAdd(Object)
queueAdd(int, Object)
(cancelled byqueueDelete(Object)
queueDelete(Object)
undoChangedAt(int, int)
undoDelete(int)
commit()
method should be called after all pending changes have been saved. Therevert()
method is used to revert all pending changes.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class io.github.jonestimd.swing.table.model.BeanListTableModel
beanTableAdapter
-
-
Constructor Summary
Constructors Constructor Description BufferedBeanListTableModel(ColumnAdapter<? super T,?>... columnAdapters)
BufferedBeanListTableModel(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
commit()
Save any pending changes.java.util.stream.Stream<T>
getChangedRows()
java.util.List<T>
getPendingAdds()
java.util.List<T>
getPendingDeletes()
java.util.stream.Stream<T>
getPendingUpdates()
boolean
isCellEditable(int rowIndex, int columnIndex)
Override to disable editing on a pending delete.boolean
isChanged()
boolean
isChangedAt(int rowIndex, int columnIndex)
boolean
isPendingAdd(int rowIndex)
boolean
isPendingDelete(int rowIndex)
void
queueAdd(int row, T bean)
Insert an unsaved bean.void
queueAdd(T bean)
Append an unsaved bean.boolean
queueDelete(T bean)
void
revert()
Undo any pending changes.void
setBeans(java.util.Collection<T> beans)
Replace all rows of the table model.void
setRow(int row, T bean)
Override to merge pending changes with new bean.protected void
setValue(java.lang.Object value, int rowIndex, int columnIndex)
void
undoChangedAt(int rowIndex, int columnIndex)
void
undoDelete(int rowIndex)
-
Methods inherited from class io.github.jonestimd.swing.table.model.BeanListTableModel
addRow, addRow, getBean, getBeanCount, getBeans, getColumnAdapter, getColumnClass, getColumnCount, getColumnIdentifier, getColumnName, getCursor, getRow, getRowCount, getValue, getValueAt, handleClick, indexOf, notifyDataProviders, removeAll, removeRow, removeRowAt, setValueAt, updateBeans
-
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
-
Methods inherited from interface io.github.jonestimd.swing.table.model.BeanTableModel
getBean, getBeanCount, getCursor, getValue, handleClick, updateBeans
-
Methods inherited from interface io.github.jonestimd.swing.table.model.ColumnIdentifier
getColumnIdentifier
-
-
-
-
Constructor Detail
-
BufferedBeanListTableModel
@SafeVarargs public BufferedBeanListTableModel(ColumnAdapter<? super T,?>... columnAdapters)
-
BufferedBeanListTableModel
public BufferedBeanListTableModel(java.util.List<? extends ColumnAdapter<? super T,?>> columnAdapters, java.lang.Iterable<? extends TableDataProvider<T>> dataProviders)
-
-
Method Detail
-
setValue
protected void setValue(java.lang.Object value, int rowIndex, int columnIndex)
- Overrides:
setValue
in classBeanListTableModel<T>
-
getChangedRows
public java.util.stream.Stream<T> getChangedRows()
- Specified by:
getChangedRows
in interfaceChangeBufferTableModel<T>
- Returns:
- updated, added and deleted rows.
-
getPendingAdds
public java.util.List<T> getPendingAdds()
- Specified by:
getPendingAdds
in interfaceChangeBufferTableModel<T>
-
getPendingDeletes
public java.util.List<T> getPendingDeletes()
- Specified by:
getPendingDeletes
in interfaceChangeBufferTableModel<T>
-
getPendingUpdates
public java.util.stream.Stream<T> getPendingUpdates()
- Specified by:
getPendingUpdates
in interfaceChangeBufferTableModel<T>
- Returns:
- added and changed rows.
-
revert
public void revert()
Description copied from interface:ChangeBuffer
Undo any pending changes.- Specified by:
revert
in interfaceChangeBuffer
-
commit
public void commit()
Description copied from interface:ChangeBuffer
Save any pending changes.- Specified by:
commit
in interfaceChangeBuffer
-
isChanged
public boolean isChanged()
- Specified by:
isChanged
in interfaceChangeBuffer
- Returns:
- true if there are pending changes
-
isChangedAt
public boolean isChangedAt(int rowIndex, int columnIndex)
- Specified by:
isChangedAt
in interfaceChangeBufferTableModel<T>
-
undoChangedAt
public void undoChangedAt(int rowIndex, int columnIndex)
- Specified by:
undoChangedAt
in interfaceChangeBufferTableModel<T>
-
isPendingAdd
public boolean isPendingAdd(int rowIndex)
-
isPendingDelete
public boolean isPendingDelete(int rowIndex)
- Specified by:
isPendingDelete
in interfaceChangeBufferTableModel<T>
-
undoDelete
public void undoDelete(int rowIndex)
- Specified by:
undoDelete
in interfaceChangeBufferTableModel<T>
-
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>
- Overrides:
setBeans
in classBeanListTableModel<T>
- Parameters:
beans
- the new rows
-
setRow
public void setRow(int row, T bean)
Override to merge pending changes with new bean. Copies changed column values from the old bean to the new bean. If the row was a pending add or delete then it will still be a pending add or delete.- Overrides:
setRow
in classBeanListTableModel<T>
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)
Override to disable editing on a pending delete.- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classBeanListTableModel<T>
-
queueAdd
public void queueAdd(T bean)
Description copied from interface:ChangeBufferTableModel
Append an unsaved bean.- Specified by:
queueAdd
in interfaceChangeBufferTableModel<T>
-
queueAdd
public void queueAdd(int row, T bean)
Description copied from interface:ChangeBufferTableModel
Insert an unsaved bean.- Specified by:
queueAdd
in interfaceChangeBufferTableModel<T>
-
queueDelete
public boolean queueDelete(T bean)
- Specified by:
queueDelete
in interfaceChangeBufferTableModel<T>
- Returns:
- true if the delete was queued, false if the row was an unsaved addition and was deleted immediately.
-
-