mirror of
https://github.com/corda/corda.git
synced 2025-04-12 21:53:17 +00:00
client: Document fx utilities
This commit is contained in:
parent
0c8f58b2ac
commit
4c36072849
@ -7,8 +7,28 @@ import javafx.collections.transformation.TransformationList
|
||||
import kotlin.comparisons.compareValues
|
||||
|
||||
/**
|
||||
* [AggregatedList] provides an [ObservableList] that is an aggregate of the underlying list based on key [K].
|
||||
* Internally it uses a sorted list TODO think of a more efficient representation
|
||||
* Given an [ObservableList]<[E]>s and a grouping key [K], [AggregatedList] groups the elements by the key into a fresh
|
||||
* [ObservableList] for each group and exposes the groups as an observable list of [A]s by calling [assemble] on each group.
|
||||
*
|
||||
* Changes done to elements of the input list are reflected in the observable list of the respective group, whereas
|
||||
* additions/removals of elements in the underlying list are reflected in the exposed [ObservableList]<[A]> by
|
||||
* adding/deleting aggregations as expected.
|
||||
*
|
||||
* The ordering of the exposed list is based on the [hashCode] of keys.
|
||||
*
|
||||
* Example:
|
||||
* val statesGroupedByCurrency = AggregatedList(states, { state -> state.currency }) { currency, group ->
|
||||
* object {
|
||||
* val currency = currency
|
||||
* val states = group
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* The above creates an observable list of (currency, statesOfCurrency) pairs.
|
||||
*
|
||||
* @param list The underlying list.
|
||||
* @param toKey Function to extract the key from an element.
|
||||
* @param assemble Function to assemble the aggregation into the exposed [A].
|
||||
*/
|
||||
class AggregatedList<A, E, K : Any>(
|
||||
list: ObservableList<out E>,
|
||||
|
@ -10,6 +10,9 @@ import org.fxmisc.easybind.EasyBind
|
||||
import java.util.*
|
||||
import java.util.stream.Collectors
|
||||
|
||||
/**
|
||||
* Utility bindings for the [Amount] type, similar in spirit to [Bindings]
|
||||
*/
|
||||
class AmountBindings {
|
||||
companion object {
|
||||
fun <T> sum(amounts: ObservableList<Amount<T>>, token: T) = EasyBind.map(
|
||||
|
@ -7,9 +7,18 @@ import javafx.collections.ObservableList
|
||||
import javafx.collections.ObservableListBase
|
||||
|
||||
/**
|
||||
* [ChosenList] is essentially a monadic join of an [ObservableValue] of an [ObservableList] into an [ObservableList].
|
||||
* Whenever the underlying [ObservableValue] changes the exposed list changes to the new value. Changes to the list are
|
||||
* simply propagated.
|
||||
* [ChosenList] manages an [ObservableList] that may be changed by the wrapping [ObservableValue]. Whenever the underlying
|
||||
* [ObservableValue] changes the exposed list changes to the new value. Changes to the list are simply propagated.
|
||||
*
|
||||
* Example:
|
||||
* val filteredStates = ChosenList(EasyBind.map(filterCriteriaType) { type ->
|
||||
* when (type) {
|
||||
* is (ByCurrency) -> statesFilteredByCurrency
|
||||
* is (ByIssuer) -> statesFilteredByIssuer
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* The above will create a list that chooses and delegates to the appropriate filtered list based on the type of filter.
|
||||
*/
|
||||
class ChosenList<E>(
|
||||
private val chosenListObservable: ObservableValue<ObservableList<E>>
|
||||
|
Loading…
x
Reference in New Issue
Block a user