Advertisement
heshm

import tornadofx.App import tornadofx.ItemViewModel import t

Feb 20th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import tornadofx.App
  2. import tornadofx.ItemViewModel
  3. import tornadofx.View
  4. import tornadofx.action
  5. import tornadofx.bind
  6. import tornadofx.button
  7. import tornadofx.checkbox
  8. import tornadofx.enableWhen
  9. import tornadofx.field
  10. import tornadofx.fieldset
  11. import tornadofx.form
  12. import tornadofx.getProperty
  13. import tornadofx.property
  14. import tornadofx.select
  15. import tornadofx.textfield
  16.  
  17. class Options(first: Double, second: Boolean) {
  18. var first by property(first)
  19. fun firstProperty() = getProperty(Options::first)
  20.  
  21. var second by property(second)
  22. fun secondProperty() = getProperty(Options::second)
  23. }
  24.  
  25. class OptionsModel : ItemViewModel<Options>() {
  26. val first = bind { item?.firstProperty() }
  27. val second = bind { item?.secondProperty() }
  28. }
  29.  
  30. class Job(name: String, options: Options) {
  31. var name by property(name)
  32. fun nameProperty() = getProperty(Job::name)
  33.  
  34. var options by property(options)
  35. fun optionsProperty() = getProperty(Job::options)
  36. }
  37.  
  38. class JobModel : ItemViewModel<Job>() {
  39. val name = bind { item?.nameProperty() }
  40. val options = bind { item?.optionsProperty() }
  41. }
  42.  
  43. class JobView : View() {
  44.  
  45. val jobModel: JobModel by inject()
  46.  
  47. override val root = form {
  48. fieldset("Basic") {
  49. field("Name") {
  50. textfield(jobModel.name)
  51. }
  52. }
  53.  
  54. fieldset("Options") {
  55. field("First") {
  56. textfield {
  57. bind(jobModel.options.select { it.firstProperty() })
  58. }
  59. }
  60.  
  61. field("Second") {
  62. checkbox(property = jobModel.options.select { it.secondProperty() })
  63. }
  64. }
  65.  
  66. button("Save") {
  67. enableWhen(jobModel.valid.and(jobModel.dirty))
  68. action {
  69. jobModel.commit {
  70. println("Created: ${jobModel.item}")
  71. }
  72. }
  73. }
  74.  
  75. button("Revert") {
  76. enableWhen(jobModel.dirty)
  77. action {
  78. jobModel.rollback()
  79. }
  80. }
  81. }
  82. }
  83.  
  84. class Main : App(JobView::class)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement