edvin / tornadofx-controlsfx

ControlsFX Builder extensions and utilities for TornadoFX
Apache License 2.0
71 stars 10 forks source link

TableFilter Implementation #1

Closed thomasnield closed 7 years ago

thomasnield commented 8 years ago

I'm going to look at implementing the TableFilter since I use it daily, as well as some simpler controls that aren't as difficult.

A problem is the TableFilter is not stored onto the TableView since the TableView has no such property to hold it.

val tableView = ...
TableFilter.forTable(tableView).apply()

I suppose we can create a map somewhere that maintains an associating between a TableFilter and the TableView it is applied on. That way we can create extension functions on TableView and TableColumn.

tableview(persons) {
        createFilter()
        column("ID", Person::id)
        column("Name", Person::name)
        column("Birthday", Person::birthday)
        column("Age", Person::age) {   
            unselectAllFilterValues()
            selectFilterValue("18")
            executeFilter()
        }
}

Sorry if this is somewhat involved from an API planning standpoint. Let's take our time on this and keep it on low priority with everything else going on.

thomasnield commented 8 years ago

Hmmm... dang it. This could be problematic on initial construction. The createFilter() would have to be called last unless I put in a fix to account for new columns being added. The column() block might not work with TableFilter manipulation either, as the TableFilter would not be initialized yet. This undertaking might take a bit longer. I'll probably stick with my Java factory for now and focus on simpler controls until I make some tweaks to TableFilter in ControlsFX.

edvin commented 8 years ago

I haven't completely understood how the TableFilter works yet (haven't tried it or looked at the source code yet) but could you store the instance as a property on the TableView? I use that trick sometimes. Also, you can listen for new columns being added, since the columns property is an ObservableList. Does that help?

thomasnield commented 8 years ago

How do you physically add a new property on a type you don't own? Do you just use extension properties but store the instance elsewhere?

Also yes the column listeners need to be added. I still have a few things I need to do with the TableFilter, and that would fix the problem.

edvin commented 8 years ago

Every Node has a Map called properties where you can add arbitrary data:

TableView<String>().apply {
    properties["tornadofx.customValue"] = "Hello world"
}
thomasnield commented 8 years ago

Oh wow, I did not know such sorcery existed. Perfect!

edvin commented 8 years ago

Haha :) I use it a lot in my apps as well to keep state. I've also put a property map directly on View by the way!

thomasnield commented 8 years ago

That is very good to know... I think I saw it once and it slightly puzzled me. But now I am aware if its needed. Properties[] all the things!!!