Minor generalization in widget configuration

This commit is contained in:
Alexander Nozik 2019-07-18 19:34:24 +03:00
parent 5ce671ff3f
commit a7fd76a4f5
5 changed files with 35 additions and 13 deletions

View File

@ -1,9 +1,9 @@
val dataforgeVersion by extra("0.1.3-dev-9") val dataforgeVersion by extra("0.1.3-dev-9")
plugins{ plugins{
kotlin("jvm") version "1.3.40" apply false kotlin("jvm") version "1.3.41" apply false
id("kotlin2js") version "1.3.40" apply false id("kotlin2js") version "1.3.41" apply false
id("kotlin-dce-js") version "1.3.40" apply false id("kotlin-dce-js") version "1.3.41" apply false
id("org.jetbrains.kotlin.frontend") version "0.0.45" apply false id("org.jetbrains.kotlin.frontend") version "0.0.45" apply false
id("scientifik.mpp") version "0.1.3" apply false id("scientifik.mpp") version "0.1.3" apply false
id("scientifik.publish") version "0.1.3" apply false id("scientifik.publish") version "0.1.3" apply false

View File

@ -0,0 +1,16 @@
package hep.dataforge.vis.common
import hep.dataforge.descriptors.ValueDescriptor
import hep.dataforge.meta.*
var ValueDescriptor.widget: Meta
get() = this.config["widget"].node?: EmptyMeta
set(value) {
this.config["widget"] = value
}
var ValueDescriptor.widgetType: String?
get() = this["widget.type"].string
set(value) {
this.config["widget.type"] = value
}

View File

@ -14,6 +14,8 @@ import hep.dataforge.provider.Type
import hep.dataforge.provider.provideByType import hep.dataforge.provider.provideByType
import hep.dataforge.values.Null import hep.dataforge.values.Null
import hep.dataforge.values.Value import hep.dataforge.values.Value
import hep.dataforge.vis.common.widget
import hep.dataforge.vis.common.widgetType
import javafx.beans.property.ObjectProperty import javafx.beans.property.ObjectProperty
import javafx.beans.value.ObservableValue import javafx.beans.value.ObservableValue
import javafx.scene.Node import javafx.scene.Node
@ -77,14 +79,18 @@ interface ValueChooser {
} }
} }
private fun build(descriptor: ValueDescriptor?): ValueChooser { private fun build(context: Context, descriptor: ValueDescriptor?): ValueChooser {
return if (descriptor == null) { return if (descriptor == null) {
TextValueChooser(); TextValueChooser();
} else { } else {
//val types = descriptor.type val widgetType = descriptor.widgetType
val chooser: ValueChooser = when { val chooser: ValueChooser = when {
widgetType != null -> {
findWidgetByType(context, widgetType)?.invoke(
descriptor.widget
) ?: TextValueChooser()
}
descriptor.allowedValues.isNotEmpty() -> ComboBoxValueChooser() descriptor.allowedValues.isNotEmpty() -> ComboBoxValueChooser()
descriptor.tags.contains("widget:color") -> ColorValueChooser()
else -> TextValueChooser() else -> TextValueChooser()
} }
chooser.descriptor = descriptor chooser.descriptor = descriptor
@ -93,11 +99,12 @@ interface ValueChooser {
} }
fun build( fun build(
context: Context,
value: ObservableValue<Value?>, value: ObservableValue<Value?>,
descriptor: ValueDescriptor? = null, descriptor: ValueDescriptor? = null,
setter: (Value) -> Unit setter: (Value) -> Unit
): ValueChooser { ): ValueChooser {
val chooser = build(descriptor) val chooser = build(context, descriptor)
chooser.setDisplayValue(value.value ?: Null) chooser.setDisplayValue(value.value ?: Null)
value.onChange { value.onChange {
chooser.setDisplayValue(it ?: Null) chooser.setDisplayValue(it ?: Null)

View File

@ -11,7 +11,7 @@ kotlin {
val commonMain by getting { val commonMain by getting {
dependencies { dependencies {
api(project(":dataforge-vis-spatial")) api(project(":dataforge-vis-spatial"))
api("scientifik:gdml:0.1.1") api("scientifik:gdml:0.1.2")
} }
} }
} }

View File

@ -7,7 +7,6 @@ pluginManagement {
maven("https://dl.bintray.com/mipt-npm/scientifik") maven("https://dl.bintray.com/mipt-npm/scientifik")
} }
val kotlinVersion = "1.3.40"
resolutionStrategy { resolutionStrategy {
eachPlugin { eachPlugin {
when (requested.id.id) { when (requested.id.id) {