Package io.jmix.flowui.model.impl
Class DataContextChangeTracker
java.lang.Object
io.jmix.flowui.model.impl.DataContextChangeTracker
Per-attribute dirty state of a
DataContextImpl: which attributes of which managed
instances the user changed, and the baseline value each change is measured against.
Baselines exist only for dirty attributes; an attribute whose current value returns to its
baseline is removed. Entity-level dirty membership is signalled through the two callbacks.-
Constructor Summary
ConstructorsConstructorDescriptionDataContextChangeTracker(Consumer<Object> onEntityDirty, Consumer<Object> onEntityClean) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Drops all baselines and dirty attributes for every entity (e.g.dirtyAttributes(Object entity) voidForgets all tracked state (baselines, dirty attributes and set-loaded markers) for an entity that is leaving the context, firing the clean callback if it was dirty.getModifiedAttributes(Object entity) The names of the entity's currently-dirty attributes (embedded sub-attributes as dotted paths), as an unmodifiable snapshot; empty if the entity is clean.booleanisAttributeDirty(Object entity, String attribute) Whether the given attribute of the entity currently carries an unsaved change.protected voidmarkAttributeDirty(Object entity, String attribute) voidMarks an attribute dirty with an explicit baseline, without a value comparison.voidmarkSetLoaded(Object entity, String attribute) Remembers that an attribute was made loaded by a user set or a non-null merge-install, so the loaded flag can be re-asserted after a fresh merge installs a narrower loaded-state cache (seesetLoadedAttributes(java.lang.Object)andDataContextImpl.reapplySetLoaded).membershipBag(Collection<?> collection) The membership bag (element key->count) of a collection, used as a to-many attribute's baseline.protected voidvoidrebaseline(Object entity, String attribute, @Nullable Object incomingValue, @Nullable Object currentValue, boolean reference) Moves a dirty scalar or single-reference attribute's baseline to an incoming (merged) value, so the user's edit is henceforth measured against it; the attribute is un-dirtied if it now equals that value.voidrebaselineCollection(Object entity, String attribute, Collection<?> incoming, Collection<?> current) The to-many counterpart ofrebaseline(java.lang.Object, java.lang.String, java.lang.Object, java.lang.Object, boolean): moves a dirty collection attribute's baseline to the membership of an incoming (merged) collection, un-dirtying it if the current membership now matches.protected static @Nullable Objectprotected voidremoveDirty(Object entity, String attribute) protected voidremoveDirtyKeepBaseline(Object entity, String attribute) setLoadedAttributes(Object entity) The attributes previously recorded bymarkSetLoaded(java.lang.Object, java.lang.String)for the entity; empty if none.voidsnapshotCollectionBaseline(Object entity, String attribute, Collection<?> baselineContents) Snapshots the membership of a to-many attribute as its baseline, so a later mutation can be compared against it (seetrackCollectionChange(java.lang.Object, java.lang.String, java.util.Collection<?>)).voidtrackChange(Object entity, String attribute, @Nullable Object prevValue, @Nullable Object newValue, boolean reference) Records a scalar or single-reference attribute change against its baseline.voidtrackCollectionChange(Object entity, String attribute, Collection<?> current) Records the current membership of a to-many attribute against its snapshotted baseline: the attribute is un-dirtied when the membership matches the baseline again, and marked dirty when it differs.
-
Constructor Details
-
DataContextChangeTracker
- Parameters:
onEntityDirty- callback invoked when an entity becomes dirty (gains its first dirty attribute)onEntityClean- callback invoked when an entity becomes clean again (loses its last dirty attribute)
-
-
Method Details
-
trackChange
public void trackChange(Object entity, String attribute, @Nullable Object prevValue, @Nullable Object newValue, boolean reference) Records a scalar or single-reference attribute change against its baseline. If a baseline already exists for the attribute, the change is measured against it: the attribute is un-dirtied when the current value returns to the baseline, and nothing else happens otherwise. With no baseline yet, the attribute becomes dirty (withprevValueas baseline) only when the value actually changed.- Parameters:
reference-trueto compare by entity id / identity rather than by value
-
snapshotCollectionBaseline
public void snapshotCollectionBaseline(Object entity, String attribute, Collection<?> baselineContents) Snapshots the membership of a to-many attribute as its baseline, so a later mutation can be compared against it (seetrackCollectionChange(java.lang.Object, java.lang.String, java.util.Collection<?>)). Called by the merge when it installs a collection. Only a clean attribute's baseline is (re)snapshotted; a dirty attribute keeps its existing baseline so an unsaved user edit is not measured against freshly merged contents. -
trackCollectionChange
Records the current membership of a to-many attribute against its snapshotted baseline: the attribute is un-dirtied when the membership matches the baseline again, and marked dirty when it differs. When no baseline was snapshotted the attribute is marked dirty conservatively (the change cannot be reconstructed). Called from the observable-collection mutation callback. -
isAttributeDirty
Whether the given attribute of the entity currently carries an unsaved change. -
getModifiedAttributes
The names of the entity's currently-dirty attributes (embedded sub-attributes as dotted paths), as an unmodifiable snapshot; empty if the entity is clean. -
rebaseline
public void rebaseline(Object entity, String attribute, @Nullable Object incomingValue, @Nullable Object currentValue, boolean reference) Moves a dirty scalar or single-reference attribute's baseline to an incoming (merged) value, so the user's edit is henceforth measured against it; the attribute is un-dirtied if it now equals that value. No-op when the attribute is not dirty. Used by a fresh merge, which rebaselines protected user edits rather than overwriting them.- Parameters:
reference-trueto compare by entity id / identity rather than by value
-
rebaselineCollection
public void rebaselineCollection(Object entity, String attribute, Collection<?> incoming, Collection<?> current) The to-many counterpart ofrebaseline(java.lang.Object, java.lang.String, java.lang.Object, java.lang.Object, boolean): moves a dirty collection attribute's baseline to the membership of an incoming (merged) collection, un-dirtying it if the current membership now matches. No-op when the attribute is not dirty. -
markDirty
Marks an attribute dirty with an explicit baseline, without a value comparison. Used to import dirty state from a child context (seeDataContextImpl.mergeFromChild). -
markSetLoaded
Remembers that an attribute was made loaded by a user set or a non-null merge-install, so the loaded flag can be re-asserted after a fresh merge installs a narrower loaded-state cache (seesetLoadedAttributes(java.lang.Object)andDataContextImpl.reapplySetLoaded). -
setLoadedAttributes
The attributes previously recorded bymarkSetLoaded(java.lang.Object, java.lang.String)for the entity; empty if none. Survivesclear(), and is dropped only when the entity leaves the context (seedrop(java.lang.Object)). -
drop
Forgets all tracked state (baselines, dirty attributes and set-loaded markers) for an entity that is leaving the context, firing the clean callback if it was dirty. -
clear
public void clear()Drops all baselines and dirty attributes for every entity (e.g. on save or clear-changes). Set-loaded markers are intentionally kept, unlikedrop(java.lang.Object). -
dirtyAttributes
-
putDirty
-
markAttributeDirty
-
removeDirty
-
removeDirtyKeepBaseline
-
refKey
-
membershipBag
The membership bag (element key->count) of a collection, used as a to-many attribute's baseline. Each element is keyed by its entity id, or by identity when it has none.
-