All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.jetbrains.datalore.base.observable.children.ChildProperty.kt Maven / Gradle / Ivy

There is a newer version: 4.5.3-alpha1
Show newest version
/*
 * Copyright (c) 2020. JetBrains s.r.o.
 * Use of this source code is governed by the MIT license that can be found in the LICENSE file.
 */

package jetbrains.datalore.base.observable.children

import jetbrains.datalore.base.observable.property.ValueProperty

class ChildProperty>(private val myParent: ParentT) :
        ValueProperty(null) {

    override fun set(value: ChildT?) {
        if (get() === value) return

        if (value != null && value.parent().get() != null) {
            throw IllegalStateException()
        }

        val oldValue = get()
        if (oldValue != null) {
            oldValue.parent().set(null)
            oldValue.setPositionData(null)
        }
        if (value != null) {
            value.parent().set(myParent)
            value.setPositionData(object :
                PositionData {
                override fun get(): Position {
                    return object : Position {

                        override val role: Any
                            get() = this@ChildProperty

                        override fun get(): ChildT? {
                            return [email protected]()
                        }
                    }
                }

                override fun remove() {
                    set(null)
                }
            })
        }

        super.set(value)

        if (oldValue != null) {
            oldValue.parent().flush()
        }
        value?.parent()?.flush()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy