forked from kscience/visionforge
Minor generalization in widget configuration
This commit is contained in:
parent
5ce671ff3f
commit
a7fd76a4f5
@ -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
|
||||||
|
@ -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
|
||||||
|
}
|
@ -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
|
||||||
@ -62,29 +64,33 @@ interface ValueChooser {
|
|||||||
fun setCallback(callback: ValueCallback)
|
fun setCallback(callback: ValueCallback)
|
||||||
|
|
||||||
@Type("hep.dataforge.vis.fx.valueChooserFactory")
|
@Type("hep.dataforge.vis.fx.valueChooserFactory")
|
||||||
interface Factory: Named {
|
interface Factory : Named {
|
||||||
operator fun invoke(meta: Meta = EmptyMeta): ValueChooser
|
operator fun invoke(meta: Meta = EmptyMeta): ValueChooser
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private fun findWidgetByType(context: Context, type: String): Factory? {
|
private fun findWidgetByType(context: Context, type: String): Factory? {
|
||||||
return when(type){
|
return when (type) {
|
||||||
TextValueChooser.name -> TextValueChooser
|
TextValueChooser.name -> TextValueChooser
|
||||||
ColorValueChooser.name -> ColorValueChooser
|
ColorValueChooser.name -> ColorValueChooser
|
||||||
ComboBoxValueChooser.name -> ComboBoxValueChooser
|
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) {
|
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)
|
||||||
|
@ -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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user