Package swingtree.api.mvvm
Interface EntryViewModel
Deprecated.
A view model for a single entry in a
JScrollPanels,
which receives its position and selection state from the component:
whenever an entry view is (re)built, the component first writes the current
position and selection flag into these two properties and then invokes the
ViewSupplier, which may read them back to style the view.-
Method Summary
Modifier and TypeMethodDescriptionsprouts.Var<Boolean> Deprecated.This method implies the existence of a boolean property in this view model determining whether the entry is currently selected or not.sprouts.Var<Integer> position()Deprecated.This method implies the existence of an integer property in this view model determining the position of the entry in the list of all entries.
-
Method Details
-
isSelected
sprouts.Var<Boolean> isSelected()Deprecated.This method implies the existence of a boolean property in this view model determining whether the entry is currently selected or not.- Returns:
- A
Varinstance representing the selected state of the entry.
-
position
sprouts.Var<Integer> position()Deprecated.This method implies the existence of an integer property in this view model determining the position of the entry in the list of all entries.- Returns:
- A
Varinstance representing the position of the entry.
-
EventProcessor.DECOUPLED), by design: the UI thread writes into your view model while building an entry view and the view supplier immediately reads that state back. Since your view model belongs to the application thread, this mid-construction write/read handshake cannot be handed over to the application event queue without breaking it. Change listeners onisSelected()andposition()will consequently run on the UI thread.The recommended alternative: tuple based binding
Model your entries as aVarproperty holding an immutableTupleof plain value objects which implementHasId(so that entry views can be recycled efficiently when the tuple changes). Any state an entry view needs, including its selection flag, is simply data in the value object: This dissolves the threading problem instead of merely patching it: there is no UI owned selection state to synchronize at all. The selection is owned by the application thread like any other view model state, exclusivity ("selecting one deselects the others") is one atomic tuple update, multi-selection and "no selection" fall out naturally, and because the entries are identified throughHasId.id(), flipping a flag on an entry recycles its existing sub-view and channels the new state into it through its item property.The position of an entry is intentionally absent from this pattern: you assemble the tuple, so you already know where each entry sits, and you may store an index in your value objects if a view needs to display it.
Note that this legacy interface remains functional in the coupled threading modes, but binding
EntryViewModels in a UI declaration which uses theEventProcessor.DECOUPLEDevent processor will log a loud warning, because thread safety cannot be guaranteed for it.