From 6f7736b85e0889aff26860e2960f52b301f460c5 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Mon, 22 Apr 2019 19:07:16 +0200 Subject: Allow more general model in the data container. --- .../pl/treksoft/kvision/data/DataContainer.kt | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft') diff --git a/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt index 69851b29..6c05da4b 100644 --- a/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt +++ b/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt @@ -37,13 +37,13 @@ enum class SorterType { } /** - * A container class with support for observable data model. + * A container class with support for mutable/observable data model. * * @constructor Creates DataContainer bound to given data model. * @param M data model type * @param C visual component type * @param CONT container type - * @param model data model of type *ObservableList* + * @param model data model of type *MutableList* * @param factory a function which creates component C from data model at given index * @param container internal container * @param containerAdd function to add component C to the internal container CONT @@ -53,8 +53,8 @@ enum class SorterType { * @param init an initializer extension function */ class DataContainer( - private val model: ObservableList, - private val factory: (M, Int, ObservableList) -> C, + private val model: MutableList, + private val factory: (M, Int, MutableList) -> C, private val container: CONT, private val containerAdd: (CONT.(C, M) -> Unit)? = null, private val filter: ((M) -> Boolean)? = null, @@ -74,8 +74,10 @@ class DataContainer( init { container.parent = this - model.onUpdate += { - update() + if (model is ObservableList) { + model.onUpdate += { + update() + } } update() @Suppress("LeakingThis") @@ -180,8 +182,8 @@ class DataContainer( * It takes the same parameters as the constructor of the built component. */ fun Container.dataContainer( - model: ObservableList, - factory: (M, Int, ObservableList) -> C, + model: MutableList, + factory: (M, Int, MutableList) -> C, container: CONT, containerAdd: (CONT.(C, M) -> Unit)? = null, filter: ((M) -> Boolean)? = null, @@ -200,8 +202,8 @@ class DataContainer( * It takes the same parameters as the constructor of the built component. */ fun Container.dataContainer( - model: ObservableList, - factory: (M, Int, ObservableList) -> C, + model: MutableList, + factory: (M, Int, MutableList) -> C, containerAdd: (VPanel.(C, M) -> Unit)? = null, filter: ((M) -> Boolean)? = null, sorter: ((M) -> Comparable<*>?)? = null, -- cgit