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")
plugins{
kotlin("jvm") version "1.3.40" apply false
id("kotlin2js") version "1.3.40" apply false
id("kotlin-dce-js") version "1.3.40" apply false
kotlin("jvm") version "1.3.41" apply false
id("kotlin2js") version "1.3.41" apply false
id("kotlin-dce-js") version "1.3.41" apply false
id("org.jetbrains.kotlin.frontend") version "0.0.45" apply false
id("scientifik.mpp") 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.values.Null
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.value.ObservableValue
import javafx.scene.Node
@ -62,29 +64,33 @@ interface ValueChooser {
fun setCallback(callback: ValueCallback)
@Type("hep.dataforge.vis.fx.valueChooserFactory")
interface Factory: Named {
interface Factory : Named {
operator fun invoke(meta: Meta = EmptyMeta): ValueChooser
}
companion object {
private fun findWidgetByType(context: Context, type: String): Factory? {
return when(type){
return when (type) {
TextValueChooser.name -> TextValueChooser
ColorValueChooser.name -> ColorValueChooser
ComboBoxValueChooser.name -> ComboBoxValueChooser
else-> context.provideByType(type)//Search for additional factories in the plugin
else -> context.provideByType(type)//Search for additional factories in the plugin
}
}
private fun build(descriptor: ValueDescriptor?): ValueChooser {
private fun build(context: Context, descriptor: ValueDescriptor?): ValueChooser {
return if (descriptor == null) {
TextValueChooser();
} else {
//val types = descriptor.type
val widgetType = descriptor.widgetType
val chooser: ValueChooser = when {
widgetType != null -> {
findWidgetByType(context, widgetType)?.invoke(
descriptor.widget
) ?: TextValueChooser()
}
descriptor.allowedValues.isNotEmpty() -> ComboBoxValueChooser()
descriptor.tags.contains("widget:color") -> ColorValueChooser()
else -> TextValueChooser()
}
chooser.descriptor = descriptor
@ -93,11 +99,12 @@ interface ValueChooser {
}
fun build(
context: Context,
value: ObservableValue<Value?>,
descriptor: ValueDescriptor? = null,
setter: (Value) -> Unit
): ValueChooser {
val chooser = build(descriptor)
val chooser = build(context, descriptor)
chooser.setDisplayValue(value.value ?: Null)
value.onChange {
chooser.setDisplayValue(it ?: Null)

View File

@ -11,7 +11,7 @@ kotlin {
val commonMain by getting {
dependencies {
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")
}
val kotlinVersion = "1.3.40"
resolutionStrategy {
eachPlugin {
when (requested.id.id) {