Class DraftsFacetImpl
java.lang.Object
io.jmix.flowui.facet.impl.AbstractFacet
io.jmix.uirecoveryflowui.facet.impl.DraftsFacetImpl
- All Implemented Interfaces:
Facet,DraftsFacet
Default implementation of
DraftsFacet: captures the unsaved state of the owning view's
DataContext into a draft, and offers it back when the view is opened again.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.jmix.uirecoveryflowui.facet.DraftsFacet
DraftsFacet.DraftRestoredEvent -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected CurrentAuthenticationprotected DataContextprotected Dialogsprotected Stringprotected EntityStatesprotected @Nullable EventBusprotected IdSerializationprotected longprotected static final Stringprotected Messagesprotected Durationprotected Notificationsprotected View<?> protected DraftPayloadSupportprotected booleanprotected UiRecoveryDraftsPropertiesprotected Consumer<DraftRestoreContext> protected RestoreModeprotected booleanprotected org.springframework.scheduling.TaskSchedulerprotected TimeSourceprotected @Nullable ScheduledFuture<?> protected ViewDataprotected ViewDraftServiceprotected StringFields inherited from class io.jmix.flowui.facet.impl.AbstractFacet
id, ownerFields inherited from interface io.jmix.uirecoveryflowui.facet.DraftsFacet
FACET_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationAdds aDraftsFacet.DraftRestoredEventlistener.protected booleanapplyDraft(ViewDraft draft) protected voidvoidDeletes the draft associated with the owning view's key.protected voidflush()Writes what is owed ifgetMinSaveInterval()has passed since the last write, and otherwise armstrailingFlushto write it once the interval does pass.protected StringformatTimestamp(ViewDraft draft) protected EventBusReturns the minimum interval between draft writes of the owning view.protected @Nullable com.vaadin.flow.component.UI@Nullable Consumer<DraftRestoreContext> Returns the currently set restore delegate, if any.Returns how a found draft is restored.protected voidinit()Applies the property defaults once the injected fields are available.protected voidprotected voidprotected voidprotected voidLast chance to write what is owed: after detach no change event can come and no flush can be scheduled, so the throttle is bypassed.protected voidonViewReady(View.ReadyEvent event) protected voidopenRestoreDialog(ViewDraft draft) protected voidprotected voidRe-reads the view's collection property containers from their master instances.protected voidrestoreIfDraftPresent(View<?> view) protected voidrunTrailingFlush(com.vaadin.flow.server.VaadinSession session) voidBuilds a draft payload from the current state of the owning view's data context and writes it immediately, bypassing the minimum save interval throttle.protected voidDefers the flush to the end of the current client round trip, so that one user action is captured as a whole.protected voidscheduleTrailingFlush(long delayMillis) The write is handed toVaadinSession.access(com.vaadin.flow.server.Command)because it reads the data context the user is still editing, which may only be touched while holding the session lock.voidsetMinSaveInterval(Duration interval) Sets the minimum interval between draft writes of the owning view.<T extends com.vaadin.flow.component.Composite<?> & FacetOwner>
voidsetOwner(@Nullable T owner) Sets an owner containing this facet.voidsetRestoreDelegate(@Nullable Consumer<DraftRestoreContext> delegate) Sets a delegate invoked when a draft is found for the owning view, allowing custom restore logic or preventing the facet's own restore behavior.voidsetRestoreMode(RestoreMode mode) Sets how a found draft is restored.protected voidprotected voidswitchToDraftedNewInstance(List<Object> applied) For a detail view editing a NEW instance: the drafted instance has a different generated id than the freshly created one, so applying the payload adds it alongside.protected voidupdateEntityKey(StandardDetailView<?> detailView) Methods inherited from class io.jmix.flowui.facet.impl.AbstractFacet
getId, getOwner, setId
-
Field Details
-
MESSAGE_GROUP
- See Also:
-
properties
-
viewDraftService
-
payloadSupport
-
entityStates
-
idSerialization
-
timeSource
-
dialogs
-
notifications
-
messages
-
currentAuthentication
-
taskScheduler
@Autowired @Qualifier("core_ThreadPoolTaskScheduler") protected org.springframework.scheduling.TaskScheduler taskScheduler -
minSaveInterval
-
restoreMode
-
restoreDelegate
-
dataContext
-
viewData
-
owningView
-
viewId
-
entityId
-
lastSaveMillis
protected long lastSaveMillis -
pendingChanges
protected boolean pendingChanges -
roundTripFlushScheduled
protected boolean roundTripFlushScheduled -
applying
protected boolean applying -
trailingFlush
-
eventBus
-
-
Constructor Details
-
DraftsFacetImpl
public DraftsFacetImpl()
-
-
Method Details
-
init
@PostConstruct protected void init()Applies the property defaults once the injected fields are available. The XML loader sets its own values after the facet is created, so an attribute in the descriptor still wins. -
setOwner
public <T extends com.vaadin.flow.component.Composite<?> & FacetOwner> void setOwner(@Nullable T owner) Description copied from interface:FacetSets an owner containing this facet.- Specified by:
setOwnerin interfaceFacet- Overrides:
setOwnerin classAbstractFacet- Type Parameters:
T- the type of the owner- Parameters:
owner- an owner containing this facet
-
onViewReady
-
updateEntityKey
-
onDataContextChange
-
scheduleRoundTripFlush
protected void scheduleRoundTripFlush()Defers the flush to the end of the current client round trip, so that one user action is captured as a whole. Adding a composition element, say, merges the new element into the data context, sets its attributes and only then adds it to the owner's collection - a draft written on the first of those events holds a new instance that nothing references yet.With no UI to hook into there is no round trip to wait for, so the flush runs right away.
-
flush
protected void flush()Writes what is owed ifgetMinSaveInterval()has passed since the last write, and otherwise armstrailingFlushto write it once the interval does pass. The interval caps how often a draft is written; it must not decide whether a change is written. -
scheduleTrailingFlush
protected void scheduleTrailingFlush(long delayMillis) The write is handed toVaadinSession.access(com.vaadin.flow.server.Command)because it reads the data context the user is still editing, which may only be touched while holding the session lock. It is queued on the session and not on theUI: closing the browser window detaches the UI while the session lives on, andUI.accesson a detached UI throws, dropping the one write that matters most. -
runTrailingFlush
protected void runTrailingFlush(com.vaadin.flow.server.VaadinSession session) -
cancelTrailingFlush
protected void cancelTrailingFlush() -
getOwnerUi
protected @Nullable com.vaadin.flow.component.UI getOwnerUi() -
onDataContextPostSave
-
saveDraftNow
public void saveDraftNow()Description copied from interface:DraftsFacetBuilds a draft payload from the current state of the owning view's data context and writes it immediately, bypassing the minimum save interval throttle.- Specified by:
saveDraftNowin interfaceDraftsFacet
-
deleteDrafts
public void deleteDrafts()Description copied from interface:DraftsFacetDeletes the draft associated with the owning view's key.- Specified by:
deleteDraftsin interfaceDraftsFacet
-
onViewDetach
protected void onViewDetach()Last chance to write what is owed: after detach no change event can come and no flush can be scheduled, so the throttle is bypassed. On a normal close a save or an explicit discard has already cleared it and this does nothing. -
onViewAfterClose
-
restoreIfDraftPresent
-
applyDraft
- Returns:
- true if the draft was applied to at least one instance. An empty result means every entry was skipped, so nothing was restored and the user must not be told otherwise.
-
refreshCollectionContainers
protected void refreshCollectionContainers()Re-reads the view's collection property containers from their master instances. Restoring a to-many attribute mutates the owner's collection in place, which fires no property change event, and aCollectionPropertyContainerkeeps its own copy of the list - so without this the data grid bound to it keeps showing the rows from before the restore. -
refreshCollectionContainer
-
switchToDraftedNewInstance
For a detail view editing a NEW instance: the drafted instance has a different generated id than the freshly created one, so applying the payload adds it alongside. Switch the view to the drafted instance and evict the fresh one, which would otherwise stay tracked as new and be sent to the data store by a later save. -
openRestoreDialog
-
showAutoRestoredNotification
-
formatTimestamp
-
getMinSaveInterval
Description copied from interface:DraftsFacetReturns the minimum interval between draft writes of the owning view.- Specified by:
getMinSaveIntervalin interfaceDraftsFacet
-
setMinSaveInterval
Description copied from interface:DraftsFacetSets the minimum interval between draft writes of the owning view.- Specified by:
setMinSaveIntervalin interfaceDraftsFacet
-
getRestoreMode
Description copied from interface:DraftsFacetReturns how a found draft is restored.- Specified by:
getRestoreModein interfaceDraftsFacet
-
setRestoreMode
Description copied from interface:DraftsFacetSets how a found draft is restored.- Specified by:
setRestoreModein interfaceDraftsFacet
-
setRestoreDelegate
Description copied from interface:DraftsFacetSets a delegate invoked when a draft is found for the owning view, allowing custom restore logic or preventing the facet's own restore behavior.- Specified by:
setRestoreDelegatein interfaceDraftsFacet
-
getRestoreDelegate
Description copied from interface:DraftsFacetReturns the currently set restore delegate, if any.- Specified by:
getRestoreDelegatein interfaceDraftsFacet
-
addDraftRestoredListener
public com.vaadin.flow.shared.Registration addDraftRestoredListener(Consumer<DraftsFacet.DraftRestoredEvent> listener) Description copied from interface:DraftsFacetAdds aDraftsFacet.DraftRestoredEventlistener.- Specified by:
addDraftRestoredListenerin interfaceDraftsFacet- Parameters:
listener- a listener to add- Returns:
- a registration object for removing the listener
-
getEventBus
-