I am learning how to use kotlin and have started using tornadoFX. I am going through the guide in an attempt to learn it, however I cannot figure out what is meant in the 'TreeView with Differing Types'. It seems to say that I should use star projection, which as I know it when you use a * in the call.
However as soon as I do that, the treeview says that 'Projections are not allowed on type arguments of functions and properties'
This is my code:
class MainView : View("") {
override val root = treeview<*> {
root = TreeItem(Person("Departments", ""))
cellFormat {
text = when (it) {
is String -> it
is Department -> it.name
is Person -> it.name
else -> throw IllegalArgumentException("Invalid Data Type")
}
}
populate { parent ->
val value = parent.value
if (parent == root) departments
else if (value is Department) persons.filter { it.department == value.name }
else null
} }
}
I'm honestly stumped, I don't know what I am meant to be doing.
Also if anyone else could provide me with some useful links for learning both Kotlin and tornadoFX it would be much appreciated :)
It seems the guide is actually incorrect. I got it working using treeview<Any>
:
data class Department(val name: String)
data class Person(val name: String, val department: String)
val persons = listOf(
Person("Mary Hanes", "Marketing"),
Person("Steve Folley", "Customer Service"),
Person("John Ramsy", "IT Help Desk"),
Person("Erlick Foyes", "Customer Service"),
Person("Erin James", "Marketing"),
Person("Jacob Mays", "IT Help Desk"),
Person("Larry Cable", "Customer Service")
)
val departments = persons.groupBy { Department(it.department) }
override val root = treeview<Any> {
root = TreeItem("Departments")
cellFormat {
text = when (it) {
is String -> it
is Department -> it.name
is Person -> it.name
else -> kotlin.error("Invalid value type")
}
}
populate { parent ->
val value = parent.value
when {
parent == root -> departments.keys
value is Department -> departments[value]
else -> null
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With