Comments (6)
It seems to work great, though it is one of the very few wrapper classes in TornadoFX. I liked the idea of just extending existing API's, but that's not always possible :)
from tornadofx.
I've created a TransformatedListContext
[1] in Groovy a while ago (the gist includes an implementation, main
method and specification tests). It allows to have a masterList
and a targetList
. Maybe this gives some hints on how to implement this for TornodoFX, maybe my approach is suboptimal, I had to be very careful with weak references in the observable list.
Example:
def setup() {
listContext = new TransformatedListContext()
targetList_integers = FXCollections.observableArrayList(1, 2, 3, 4, 5)
}
def "setSort() and setFilter()"() {
given:
def masterList = listContext.register(targetList_integers)
when:
listContext.sort = { int a, int b -> b <=> a } as Comparator
listContext.filter = { int a -> a > 3 } as Predicate
then:
targetList_integers == [5, 4]
masterList == [1, 2, 3, 4, 5]
}
[1] https://gist.github.com/hastebrot/efe0a4d39e054730f8090ef9facfe050
from tornadofx.
Thanks! I'm working on an implementation right now, I'll see if I can glean some ideas from your list :)
from tornadofx.
I commited SortedFilteredList
now. It is a delegate for an ObservableList<T>
, and wraps the data in the way described in the top of this issue. You can connect it to a TableView
or ListView
like this:
val table = TableView<Person>()
val data = SortedFilteredList(persons).bindTo(table)
It can also be used ad hoc. Filter the data by updating the predicate:
data.predicate = { it.age > 18 }
Special support is added to update the predicate based on an Observable
. This is extremely handy for TextField
based filtering. Let's pretend that Person
has a matches(query: String): Boolean
function. With this, you can perform live filtering very easily:
textfield {
promptText = "Filter query"
data.filterWhen(textProperty(), { query, item -> item.matches(query) } )
}
The same technique can be used for selection based on a ComboBox
or similar.
from tornadofx.
Added a simple test:
data class Person(val name: String, val age: Int)
val persons = FXCollections.observableArrayList(
Person("Samantha Stuart", 34),
Person("Tom Marks", 42),
Person("Stuart Gills", 17),
Person("Nicole Williams", 27))
@Test
fun filterTest() {
val data = SortedFilteredList(persons)
data.predicate = { it.name.contains("Stu")}
Assert.assertEquals(2, data.size)
}
from tornadofx.
This is pretty convenient. It always felt odd doing all that work to created sorted and filtered lists.
from tornadofx.
Related Issues (20)
- TornadoFx ClassCastException HOT 1
- Accessing nodes with less code HOT 4
- Advanced Data Controls Guide Clarification HOT 1
- Unbind TextField text property from non-String property HOT 2
- Font not loading HOT 1
- AsyncKt cannot access class com.sun.glass.ui.Application HOT 5
- EventBus.fire does not check for listeners of superclass types HOT 1
- Set window icons for Alerts
- Hot reload doesn't work with openjdk
- a bug with toggleClass HOT 2
- TornadoFx stackpane overlapping with menubar
- How can i build a native image using tornadofx HOT 1
- Localization of german Double values
- Data Driven TreeView HOT 1
- how to use field()? | and why field() cant' be used without form()? HOT 2
- Tornadofx with Spring security
- Is this not longer maintained? HOT 8
- Looking for maintainers HOT 1
- Guilde is not available HOT 1
- Documentation does not work HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tornadofx.