Class BufferedHeaderDetailTableModel<H>
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- io.github.jonestimd.swing.table.model.HeaderDetailTableModel<H>
-
- io.github.jonestimd.swing.table.model.BufferedHeaderDetailTableModel<H>
-
- All Implemented Interfaces:
ChangeBuffer
,BeanTableModel<H>
,ChangeBufferTableModel<H>
,ColumnIdentifier
,MixedRowTableModel
,ValidatedTableModel
,java.io.Serializable
,javax.swing.table.TableModel
public class BufferedHeaderDetailTableModel<H> extends HeaderDetailTableModel<H> implements ChangeBufferTableModel<H>, ValidatedTableModel
This class overridesHeaderDetailTableModel
to add change tracking and validation. Changes to cells are queued bysetValueAt(java.lang.Object, int, int)
. The following methods are used to queue pending changes for rows: Thecommit()
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.HeaderDetailTableModel
detailAdapter
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BufferedHeaderDetailTableModel(DetailAdapter<H> detailAdapter, java.util.function.Function<? super H,?> idFunction)
BufferedHeaderDetailTableModel(DetailAdapter<H> detailAdapter, java.util.function.Function<? super H,?> idFunction, java.util.List<? extends ColumnAdapter<H,?>> columnAdapters, java.util.List<? extends java.util.List<? extends ColumnAdapter<?,?>>> detailColumnAdapters)
BufferedHeaderDetailTableModel(DetailAdapter<H> detailAdapter, java.util.List<? extends ColumnAdapter<H,?>> columnAdapters, java.util.List<? extends java.util.List<? extends ColumnAdapter<?,?>>> detailColumnAdapters)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBean(int index, H bean)
Insert a saved group.void
addBean(H bean)
Append a saved group.void
commit()
Save any pending changes.protected void
fireSubRowInserted(H bean, int subRowIndex)
Mark the sub-row as an unsaved addition unless the header bean is already an unsaved addition.void
fireTableCellUpdated(int row, int column)
Overridden to update validation.void
fireTableRowsDeleted(int firstRow, int lastRow)
Overridden to update validation.void
fireTableRowsInserted(int firstRow, int lastRow)
Overridden to update validation.java.util.stream.Stream<H>
getChangedRows()
java.util.List<H>
getPendingAdds()
java.util.List<H>
getPendingDeletes()
java.util.stream.Stream<H>
getPendingUpdates()
boolean
isCellEditable(int rowIndex, int columnIndex)
Override so that pending deletes can not be edited.boolean
isChanged()
boolean
isChanged(H bean)
boolean
isChangedAt(int rowIndex, int columnIndex)
boolean
isNoErrors()
boolean
isPendingAdd(int rowIndex)
boolean
isPendingDelete(int rowIndex)
boolean
isPendingDelete(H bean)
void
queueAdd(int groupNumber, H bean)
Insert an unsaved group.void
queueAdd(H bean)
Append an unsaved group.int
queueAppendSubRow(int currentRow)
Append a detail row to a group.boolean
queueDelete(int rowIndex)
Mark a row as a pending delete or remove the row if it is a pending addition.boolean
queueDelete(H bean)
void
removeBean(H bean)
Remove a group from the table.protected void
removeSubRow(H bean, java.lang.Object subRow)
void
revert()
Undo any pending changes.void
setBean(int index, H bean)
Overridden to reset pending changes and validation for the group.void
setBeans(java.util.Collection<H> beans)
Overridden to reset change tracking and validation.protected void
setCellValue(java.lang.Object value, int rowIndex, int columnIndex)
Set a value on a header or detail.void
setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
Overridden to update change tracking and validation.void
undoChangedAt(int rowIndex, int columnIndex)
void
undoDelete(int rowIndex)
protected void
updateGroupValidation(int groupNumber)
Update the errors for all rows in a group without firing change events.protected void
updateRowValidation(int rowIndex)
Update the errors for a row without firing change events.java.lang.String
validateAt(int rowIndex, int columnIndex)
<V> java.lang.String
validateAt(int rowIndex, int columnIndex, V value)
protected boolean
validateCell(int rowIndex, int columnIndex)
-
Methods inherited from class io.github.jonestimd.swing.table.model.HeaderDetailTableModel
getBean, getBeanAtRow, getBeanCount, getBeans, getCellClass, getColumnAdapter, getColumnClass, getColumnClass, getColumnCount, getColumnIdentifier, getColumnIdentifier, getColumnIndex, getColumnName, getColumnName, getCursor, getDetailColumnAdapter, getDetailColumnIndex, getDetailValueAt, getGroupNumber, getInsertionIndex, getLeadRowForGroup, getRowCount, getRowCount, getRowTypeCount, getRowTypeIndex, getSubRowIndex, getValue, getValueAt, handleClick, indexOf, indexOf, isSubRow, removeAll, rowIndexOf, setColumnAdapters, setDetailColumnAdapters, updateBeans, updateRowOffsets
-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableChanged, fireTableDataChanged, 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
-
BufferedHeaderDetailTableModel
protected BufferedHeaderDetailTableModel(DetailAdapter<H> detailAdapter, java.util.function.Function<? super H,?> idFunction)
-
BufferedHeaderDetailTableModel
public BufferedHeaderDetailTableModel(DetailAdapter<H> detailAdapter, java.util.List<? extends ColumnAdapter<H,?>> columnAdapters, java.util.List<? extends java.util.List<? extends ColumnAdapter<?,?>>> detailColumnAdapters)
-
BufferedHeaderDetailTableModel
public BufferedHeaderDetailTableModel(DetailAdapter<H> detailAdapter, java.util.function.Function<? super H,?> idFunction, java.util.List<? extends ColumnAdapter<H,?>> columnAdapters, java.util.List<? extends java.util.List<? extends ColumnAdapter<?,?>>> detailColumnAdapters)
-
-
Method Detail
-
setBeans
public void setBeans(java.util.Collection<H> beans)
Overridden to reset change tracking and validation.- Specified by:
setBeans
in interfaceBeanTableModel<H>
- Overrides:
setBeans
in classHeaderDetailTableModel<H>
- Parameters:
beans
- the new rows
-
queueDelete
public boolean queueDelete(H bean)
- Specified by:
queueDelete
in interfaceChangeBufferTableModel<H>
- Returns:
- true if the delete was queued, false if the row was an unsaved addition and was deleted immediately.
-
queueDelete
public boolean queueDelete(int rowIndex)
Mark a row as a pending delete or remove the row if it is a pending addition. If the specified row is the header of a group then the operation is applied to the entire group.- Returns:
- true if the delete was queued or false if the row was an unsaved addition and was deleted immediately.
-
queueAdd
public void queueAdd(H bean)
Append an unsaved group.- Specified by:
queueAdd
in interfaceChangeBufferTableModel<H>
-
queueAdd
public void queueAdd(int groupNumber, H bean)
Insert an unsaved group.- Specified by:
queueAdd
in interfaceChangeBufferTableModel<H>
-
queueAppendSubRow
public int queueAppendSubRow(int currentRow)
Append a detail row to a group.- Parameters:
currentRow
- the index of a row in the group.- Returns:
- the index of the new row.
-
addBean
public void addBean(H bean)
Append a saved group.
-
addBean
public void addBean(int index, H bean)
Insert a saved group.- Overrides:
addBean
in classHeaderDetailTableModel<H>
- Parameters:
index
- the insertion point in the list of groupsbean
- the group to add
-
setBean
public void setBean(int index, H bean)
Overridden to reset pending changes and validation for the group.- Overrides:
setBean
in classHeaderDetailTableModel<H>
- Parameters:
index
- the index in the list of groups.bean
- the replacement group
-
fireTableRowsDeleted
public void fireTableRowsDeleted(int firstRow, int lastRow)
Overridden to update validation.- Overrides:
fireTableRowsDeleted
in classHeaderDetailTableModel<H>
-
removeBean
public void removeBean(H bean)
Description copied from class:HeaderDetailTableModel
Remove a group from the table.- Overrides:
removeBean
in classHeaderDetailTableModel<H>
- Parameters:
bean
- the group to remove
-
removeSubRow
protected void removeSubRow(H bean, java.lang.Object subRow)
-
fireTableRowsInserted
public void fireTableRowsInserted(int firstRow, int lastRow)
Overridden to update validation.- Overrides:
fireTableRowsInserted
in classHeaderDetailTableModel<H>
-
fireSubRowInserted
protected void fireSubRowInserted(H bean, int subRowIndex)
Mark the sub-row as an unsaved addition unless the header bean is already an unsaved addition.
-
updateGroupValidation
protected void updateGroupValidation(int groupNumber)
Update the errors for all rows in a group without firing change events.
-
updateRowValidation
protected void updateRowValidation(int rowIndex)
Update the errors for a row without firing change events.
-
validateCell
protected boolean validateCell(int rowIndex, int columnIndex)
- Returns:
- true if the cell validation changed
-
validateAt
public java.lang.String validateAt(int rowIndex, int columnIndex)
- Specified by:
validateAt
in interfaceValidatedTableModel
- Returns:
- error messages or
null
if current value valid.
-
validateAt
public <V> java.lang.String validateAt(int rowIndex, int columnIndex, V value)
- Specified by:
validateAt
in interfaceValidatedTableModel
- Returns:
- error message or
null
if specified value is valid.
-
isNoErrors
public boolean isNoErrors()
- Specified by:
isNoErrors
in interfaceValidatedTableModel
- Returns:
- true if there are no validation errors.
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)
Override so that pending deletes can not be edited.- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classHeaderDetailTableModel<H>
- Returns:
- the result of
ColumnAdapter.isEditable(Object)
-
setValueAt
public void setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
Overridden to update change tracking and validation.- Specified by:
setValueAt
in interfacejavax.swing.table.TableModel
- Overrides:
setValueAt
in classjavax.swing.table.AbstractTableModel
-
fireTableCellUpdated
public void fireTableCellUpdated(int row, int column)
Overridden to update validation.- Overrides:
fireTableCellUpdated
in classjavax.swing.table.AbstractTableModel
-
setCellValue
protected void setCellValue(java.lang.Object value, int rowIndex, int columnIndex)
Description copied from class:HeaderDetailTableModel
Set a value on a header or detail.- Overrides:
setCellValue
in classHeaderDetailTableModel<H>
- Parameters:
value
- the cell valuerowIndex
- the table row indexcolumnIndex
- the table column index
-
getChangedRows
public java.util.stream.Stream<H> getChangedRows()
- Specified by:
getChangedRows
in interfaceChangeBufferTableModel<H>
- Returns:
- updated, added and deleted rows.
-
getPendingAdds
public java.util.List<H> getPendingAdds()
- Specified by:
getPendingAdds
in interfaceChangeBufferTableModel<H>
-
getPendingDeletes
public java.util.List<H> getPendingDeletes()
- Specified by:
getPendingDeletes
in interfaceChangeBufferTableModel<H>
-
getPendingUpdates
public java.util.stream.Stream<H> getPendingUpdates()
- Specified by:
getPendingUpdates
in interfaceChangeBufferTableModel<H>
- Returns:
- added and changed rows.
-
isChanged
public boolean isChanged()
- Specified by:
isChanged
in interfaceChangeBuffer
- Returns:
- true if there are pending changes
-
isChanged
public boolean isChanged(H bean)
- Returns:
- true if there are pending changes for the group.
-
isChangedAt
public boolean isChangedAt(int rowIndex, int columnIndex)
- Specified by:
isChangedAt
in interfaceChangeBufferTableModel<H>
-
undoChangedAt
public void undoChangedAt(int rowIndex, int columnIndex)
- Specified by:
undoChangedAt
in interfaceChangeBufferTableModel<H>
-
isPendingAdd
public boolean isPendingAdd(int rowIndex)
-
isPendingDelete
public boolean isPendingDelete(int rowIndex)
- Specified by:
isPendingDelete
in interfaceChangeBufferTableModel<H>
-
undoDelete
public void undoDelete(int rowIndex)
- Specified by:
undoDelete
in interfaceChangeBufferTableModel<H>
-
isPendingDelete
public boolean isPendingDelete(H bean)
-
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
-
-