[Editor] Add support for manual committing in Parameters Table Fragment
This commit is contained in:
@@ -2,6 +2,8 @@ package com.bartlomiejpluta.base.editor.common.parameter.component
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.common.parameter.model.Parameter
|
import com.bartlomiejpluta.base.editor.common.parameter.model.Parameter
|
||||||
import javafx.scene.control.TableCell
|
import javafx.scene.control.TableCell
|
||||||
|
import javafx.scene.input.KeyCode
|
||||||
|
import javafx.scene.input.KeyEvent
|
||||||
|
|
||||||
class ParameterValueEditingCell : TableCell<Parameter<*>, Any>() {
|
class ParameterValueEditingCell : TableCell<Parameter<*>, Any>() {
|
||||||
|
|
||||||
@@ -26,6 +28,11 @@ class ParameterValueEditingCell : TableCell<Parameter<*>, Any>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun commitEdit(newValue: Any?) {
|
||||||
|
super.commitEdit(newValue)
|
||||||
|
tableView.items[index]?.commit()
|
||||||
|
}
|
||||||
|
|
||||||
override fun startEdit() {
|
override fun startEdit() {
|
||||||
if (index < 0 || index >= tableView.items.size) {
|
if (index < 0 || index >= tableView.items.size) {
|
||||||
return
|
return
|
||||||
@@ -37,7 +44,15 @@ class ParameterValueEditingCell : TableCell<Parameter<*>, Any>() {
|
|||||||
|
|
||||||
super.startEdit()
|
super.startEdit()
|
||||||
text = null
|
text = null
|
||||||
graphic = tableView.items[index].editor
|
val parameter = tableView.items[index]
|
||||||
|
graphic = parameter.editor.apply {
|
||||||
|
addEventHandler(KeyEvent.KEY_PRESSED) {
|
||||||
|
if (it.code == KeyCode.ENTER) {
|
||||||
|
commitEdit(parameter.value)
|
||||||
|
it.consume()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun cancelEdit() {
|
override fun cancelEdit() {
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
package com.bartlomiejpluta.base.editor.common.parameter.model
|
package com.bartlomiejpluta.base.editor.common.parameter.model
|
||||||
|
|
||||||
|
import javafx.beans.property.Property
|
||||||
import javafx.scene.control.ComboBox
|
import javafx.scene.control.ComboBox
|
||||||
|
|
||||||
class EnumParameter<E : Enum<E>>(
|
class EnumParameter<E : Enum<E>>(
|
||||||
key: String,
|
key: String,
|
||||||
initialValue: E,
|
initialValue: E,
|
||||||
editable: Boolean = true
|
editable: Boolean = true,
|
||||||
) : Parameter<E>(key, initialValue, editable) {
|
autocommit: Boolean = false
|
||||||
override val editor = ComboBox<E>().apply {
|
) : Parameter<E>(key, initialValue, editable, autocommit) {
|
||||||
items.setAll(initialValue.javaClass.enumConstants.toList())
|
override val editor = ComboBox<E>().apply { items.setAll(initialValue.javaClass.enumConstants.toList()) }
|
||||||
valueProperty().bindBidirectional(valueProperty)
|
override val editorValueProperty: Property<E>
|
||||||
|
get() = editor.valueProperty()
|
||||||
|
|
||||||
|
init {
|
||||||
|
super.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.bartlomiejpluta.base.editor.common.parameter.model
|
package com.bartlomiejpluta.base.editor.common.parameter.model
|
||||||
|
|
||||||
|
import javafx.beans.property.Property
|
||||||
import javafx.scene.control.Spinner
|
import javafx.scene.control.Spinner
|
||||||
|
|
||||||
class IntegerParameter(
|
class IntegerParameter(
|
||||||
@@ -8,9 +9,13 @@ class IntegerParameter(
|
|||||||
minValue: Int,
|
minValue: Int,
|
||||||
maxValue: Int,
|
maxValue: Int,
|
||||||
editable: Boolean = true,
|
editable: Boolean = true,
|
||||||
) : Parameter<Int>(key, initialValue, editable) {
|
autocommit: Boolean = false
|
||||||
override val editor = Spinner<Int>(minValue, maxValue, initialValue).apply {
|
) : Parameter<Int>(key, initialValue, editable, autocommit) {
|
||||||
isEditable = true
|
override val editor = Spinner<Int>(minValue, maxValue, initialValue).apply { isEditable = true }
|
||||||
valueFactory.valueProperty().bindBidirectional(valueProperty)
|
override val editorValueProperty: Property<Int>
|
||||||
|
get() = editor.valueFactory.valueProperty()
|
||||||
|
|
||||||
|
init {
|
||||||
|
super.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,12 @@ import javafx.scene.Node
|
|||||||
import tornadofx.getValue
|
import tornadofx.getValue
|
||||||
import tornadofx.setValue
|
import tornadofx.setValue
|
||||||
|
|
||||||
abstract class Parameter<T>(key: String, initialValue: T? = null, editable: Boolean = true) {
|
abstract class Parameter<T>(
|
||||||
|
key: String,
|
||||||
|
initialValue: T? = null,
|
||||||
|
editable: Boolean = true,
|
||||||
|
private val autocommit: Boolean = false
|
||||||
|
) {
|
||||||
val keyProperty = ReadOnlyStringWrapper(key)
|
val keyProperty = ReadOnlyStringWrapper(key)
|
||||||
val key by keyProperty
|
val key by keyProperty
|
||||||
|
|
||||||
@@ -15,6 +20,23 @@ abstract class Parameter<T>(key: String, initialValue: T? = null, editable: Bool
|
|||||||
val valueProperty: ObjectProperty<T> = SimpleObjectProperty(initialValue)
|
val valueProperty: ObjectProperty<T> = SimpleObjectProperty(initialValue)
|
||||||
var value by valueProperty
|
var value by valueProperty
|
||||||
|
|
||||||
|
fun commit() {
|
||||||
|
if (!autocommit) {
|
||||||
|
value = editorValueProperty.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun init() {
|
||||||
|
if (autocommit) {
|
||||||
|
editorValueProperty.bindBidirectional(valueProperty)
|
||||||
|
} else {
|
||||||
|
editorValueProperty.value = value
|
||||||
|
valueProperty.addListener { _, _, v -> editorValueProperty.value = v }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract val editorValueProperty: Property<T>
|
||||||
|
|
||||||
abstract val editor: Node
|
abstract val editor: Node
|
||||||
|
|
||||||
open val valueString: String
|
open val valueString: String
|
||||||
|
|||||||
@@ -1,8 +1,20 @@
|
|||||||
package com.bartlomiejpluta.base.editor.common.parameter.model
|
package com.bartlomiejpluta.base.editor.common.parameter.model
|
||||||
|
|
||||||
|
import javafx.beans.property.Property
|
||||||
import javafx.scene.control.TextField
|
import javafx.scene.control.TextField
|
||||||
|
|
||||||
class StringParameter(key: String, initialValue: String? = null, editable: Boolean = true) :
|
class StringParameter(
|
||||||
Parameter<String>(key, initialValue, editable) {
|
key: String,
|
||||||
override val editor = TextField().apply { textProperty().bind(valueProperty) }
|
initialValue: String? = null,
|
||||||
|
editable: Boolean = true,
|
||||||
|
autocommit: Boolean = false
|
||||||
|
) :
|
||||||
|
Parameter<String>(key, initialValue, editable, autocommit) {
|
||||||
|
override val editor = TextField()
|
||||||
|
override val editorValueProperty: Property<String>
|
||||||
|
get() = editor.textProperty()
|
||||||
|
|
||||||
|
init {
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user