edvin / tornadofx-idea-plugin

TornadoFX Plugin for IntelliJ IDEA
Apache License 2.0
73 stars 20 forks source link

TableView column generations are incorrecrt. #12

Closed thomasnield closed 7 years ago

thomasnield commented 7 years ago

Hey Edvin,

I'm adding some documentation to the guide on the plugin regarding TableView column generation. However, I think the generators are using getXXXProperty() conventions rather than xxxProperty().

This is what I get when I generate columns for the TableView.

package org.nield

import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import tornadofx.*
import java.time.LocalDate
import java.time.Period

class MyApp: App(MyView::class)

class MyView : View("My View") {

    override val root = tableview<Person> {
        isEditable = true
        items = listOf(Person(1,"Thomas Nield", LocalDate.of(1989,1,18))).observable()
        column("Get Id", Person::getIdProperty)
        column("Get Name", Person::getNameProperty)
        column("Get Birthday", Person::getBirthdayProperty)
    }
}

class Person(id: Int, name: String, birthday: LocalDate) {
    var id by property<Int>(id)
    fun idProperty() = getProperty(Person::id)

    val nameProperty = SimpleStringProperty(name)
    var name by nameProperty

    val birthdayProperty = SimpleObjectProperty(birthday)
    var birthday by birthdayProperty

    val age: Int get() = Period.between(birthday, LocalDate.now()).years
}

Also, I noticed that POKO's do not seem to be supported.

class Person(val id: Int, val name: String, val birthday: LocalDate) {
    val age: Int get() = Period.between(birthday, LocalDate.now()).years
}
edvin commented 7 years ago

When I run the example above it works correct for the idProperty, and generates:

    column("Id", Person::idProperty)

It fails for the others though. Looking at it now, but can you confirm the behavior for the id column? It's defined differently in your Person object as well (old style, which probably is the only property style we supported when I created this plugin feature).

edvin commented 7 years ago

Hmm... var name by nameProperty actually causes the Kotlin PSI structure to include getNameProperty() and setNameProperty()` functions. I just need to strip them out and add support for public fields as well.

edvin commented 7 years ago

tornadofx-idea-plugin.zip Can you try with the attached version of the plugin?

thomasnield commented 7 years ago

That seemed to work!

thomasnield commented 7 years ago

The POKO structure still does not seem to be supported. But I'm okay with that if you are.

thomasnield commented 7 years ago

Just updated documentation.

edvin commented 7 years ago

Ah, sorry I forgot :) Now it supports POKOs as well :)

edvin commented 7 years ago

tornadofx-idea-plugin.zip