forked from edvin/tornadofx
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request edvin#1338 from yamert89/master
optional converter in extensions: useComboBox() and useChoiceBox()
- Loading branch information
Showing
2 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package tornadofx.testapps | ||
|
||
import javafx.beans.property.SimpleIntegerProperty | ||
import javafx.util.StringConverter | ||
import tornadofx.* | ||
|
||
class UseComboBox: App(UseComboBoxView::class) | ||
|
||
class UseComboBoxView: View() { | ||
override val root = anchorpane{ | ||
val data = listOf(DataItem(1), DataItem(2), DataItem(3)).asObservable() | ||
tableview(data) { | ||
isEditable = true | ||
column("1", DataItem::a).useComboBox(listOf(1, 2, 3).asObservable(), IntegerConverter()) | ||
column("2", DataItem::a).useChoiceBox(listOf(1, 2, 3).asObservable(), IntegerConverter()) | ||
column("3", DataItem::a).useComboBox(listOf(1, 2, 3).asObservable()) | ||
} | ||
} | ||
} | ||
|
||
class DataItem(a: Int){ | ||
private val aProperty = SimpleIntegerProperty(a) | ||
var a: Int? by aProperty | ||
} | ||
|
||
class IntegerConverter: StringConverter<Int>() { | ||
override fun toString(`object`: Int): String { | ||
return when(`object`){ | ||
1 -> "first" | ||
2 -> "second" | ||
3 -> "third" | ||
else -> `object`.toString() | ||
} | ||
|
||
} | ||
|
||
override fun fromString(string: String): Int { | ||
return when(string){ | ||
"first" -> 1 | ||
"second" -> 2 | ||
"third" -> 3 | ||
else -> throw IllegalArgumentException("unsupported value") | ||
} | ||
} | ||
} |