Skip to content

Commit

Permalink
Merge pull request #37 from pavlus/bugfix-tornadofx-1217
Browse files Browse the repository at this point in the history
 Do not try to force accessibility on `Parent.getChildren` via reflection
  • Loading branch information
edvin authored May 26, 2021
2 parents 5052fef + a92b4dd commit 20f3a36
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main/java/tornadofx/FX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,11 @@ fun EventTarget.getChildList(): MutableList<Node>? = when (this) {
}

@Suppress("UNCHECKED_CAST", "PLATFORM_CLASS_MAPPED_TO_KOTLIN")
private fun Parent.getChildrenReflectively(): MutableList<Node>? {
val getter = this.javaClass.findMethodByName("getChildren")
if (getter != null && java.util.List::class.java.isAssignableFrom(getter.returnType)) {
getter.isAccessible = true
return getter.invoke(this) as MutableList<Node>
}
return null
}
private fun Parent.getChildrenReflectively(): MutableList<Node>? = this.javaClass
.findMethodByName("getChildren")
?.takeIf { java.util.List::class.java.isAssignableFrom(it.returnType) }
?.takeIf { getter -> getter.canAccess(this) || getter.trySetAccessible() }
?.let { getter -> getter.invoke(this) as MutableList<Node> }

var Window.aboutToBeShown: Boolean
get() = properties["tornadofx.aboutToBeShown"] == true
Expand Down
19 changes: 19 additions & 0 deletions src/test/kotlin/tornadofx/testapps/TableViewCheckboxReflection.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tornadofx.testapps

import javafx.beans.property.SimpleBooleanProperty
import tornadofx.*

class TableViewCheckboxApp : App(TableViewCheckbox::class)

class Model {
val booleanProperty = SimpleBooleanProperty()
}

class TableViewCheckbox : View() {
val items = observableListOf(Model())

override val root = tableview(items) {
column("Checkbox", Model::booleanProperty)
.useCheckbox()
}
}

0 comments on commit 20f3a36

Please sign in to comment.