Class ChangeTracker<T>
- java.lang.Object
-
- io.github.jonestimd.swing.table.model.ChangeTracker<T>
-
- Type Parameters:
T- the class representing a row in the table
public abstract class ChangeTracker<T> extends java.lang.ObjectBase class for tracking unsaved changes in a table. Unsaved changes include- unsaved new rows
- unsaved deletes
- unsaved modifications to rows
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedChangeTracker(boolean useEquals)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcancelDeletes(java.util.function.Predicate<? super T> predicate)Cancel pending deletes matching a predicate.voidcommit()Commit all pending changes.java.util.List<T>getAdds()java.util.Set<java.lang.Integer>getChangeIndexes(T item)java.util.stream.Stream<T>getChanges()java.util.List<T>getDeletes()java.util.stream.Stream<T>getUpdates()booleanisChanged(T item, int index)booleanisEmpty()booleanisPendingAdd(T item)booleanisPendingDelete(T item)protected abstract voiditemDeleted(T item)Implementation should remove the row from the table without notifying this change tracker.protected abstract voiditemUpdated(T item)Called when the modification status of a row changes.voidpendingAdd(T item)Mark a row as a pending add.voidpendingDelete(T item)Mark a row as a pending delete.voidreset()Clear all pending changes.voidresetItem(T item)Reset pending changes for a row.voidresetItems(java.util.function.Predicate<? super T> predicate)Reset pending changes for rows matching a predicate.voidrevert()Revert all pending changes.protected abstract voidrevertItemChange(java.lang.Object originalValue, T item, int index)Implementation should update the table model with the original value without notifying this change tracker.voidsetValue(T item, int index, java.lang.Object oldValue, java.lang.Object newValue)Add or remove a pending change for a row property.voidundoChange(T item, int index)Restore the original value of a modified property of a row.voidundoDelete(T item)
-
-
-
Method Detail
-
pendingAdd
public void pendingAdd(T item)
Mark a row as a pending add.
-
pendingDelete
public void pendingDelete(T item)
Mark a row as a pending delete.
-
cancelDeletes
public void cancelDeletes(java.util.function.Predicate<? super T> predicate)
Cancel pending deletes matching a predicate.
-
resetItem
public void resetItem(T item)
Reset pending changes for a row.
-
resetItems
public void resetItems(java.util.function.Predicate<? super T> predicate)
Reset pending changes for rows matching a predicate.
-
isPendingAdd
public boolean isPendingAdd(T item)
- Returns:
- true if the row is a pending add.
-
isPendingDelete
public boolean isPendingDelete(T item)
- Returns:
- true if the row is a pending delete.
-
setValue
public void setValue(T item, int index, java.lang.Object oldValue, java.lang.Object newValue)
Add or remove a pending change for a row property.- Parameters:
item- the row beanindex- the property indexoldValue- the previous value of the propertynewValue- the replacement value for the property
-
isEmpty
public boolean isEmpty()
- Returns:
- true if there are no pending changes for any rows.
-
isChanged
public boolean isChanged(T item, int index)
- Parameters:
item- a row beanindex- a property index- Returns:
- true if the row property has been modified.
-
getChangeIndexes
public java.util.Set<java.lang.Integer> getChangeIndexes(T item)
-
getChanges
public java.util.stream.Stream<T> getChanges()
- Returns:
- all of the rows with pending changes.
-
getAdds
public java.util.List<T> getAdds()
- Returns:
- unsaved new rows.
-
getDeletes
public java.util.List<T> getDeletes()
- Returns:
- rows pending deletion.
-
getUpdates
public java.util.stream.Stream<T> getUpdates()
- Returns:
- unsaved new and modified rows.
-
undoChange
public void undoChange(T item, int index)
Restore the original value of a modified property of a row. If the specified proeprty has been modified thenrevertItemChange(Object, Object, int)is called with the original value.- Parameters:
item- the row to updateindex- the property index
-
undoDelete
public void undoDelete(T item)
-
revert
public void revert()
Revert all pending changes.
-
revertItemChange
protected abstract void revertItemChange(java.lang.Object originalValue, T item, int index)Implementation should update the table model with the original value without notifying this change tracker.
-
itemUpdated
protected abstract void itemUpdated(T item)
Called when the modification status of a row changes. Implementation should fire table model change events.
-
itemDeleted
protected abstract void itemDeleted(T item)
Implementation should remove the row from the table without notifying this change tracker.
-
commit
public void commit()
Commit all pending changes.
-
reset
public void reset()
Clear all pending changes.
-
-