Tolga ÇAĞLAYAN
10/29/2022, 4:34 PMmodel.searchTextProperty().addListener((obs, old, val) -> {
var empty = val == null || val.isBlank();
pseudoClassStateChanged(FILTERED, !empty);
navMenu.setPredicate(empty ? PREDICATE_ANY : region -> region instanceof NavLink link && link.matches(val));
});
public void setPredicate(Predicate<Region> predicate) {
content.setPredicate(predicate);
}
I have such a code block, how can I translate it to kotlin language?Stephan Schroeder
10/29/2022, 10:25 PMTolga ÇAĞLAYAN
10/30/2022, 3:28 PMStephan Schroeder
10/31/2022, 8:43 AMval
and that's a keyword in Kotlin??
It should look something like this:
• first code snippet
model.searchTextProperty().addListener( Listener { obs, old, value -> // you might need to add the types!? Also I assume the the type of the Listener that addListener takes is "Listener", adapt if different
val isEmpty = value.isNullOrBlank()
pseudoClasStateChanged(FILTERED, !isEmpty)
navMenu.predicate = if(isEmpty) {
PREDICATE_ANY
} else {
Predicate { region: Region -> region is NavLink && region.matches(value) } // region is smart-casted to NavLink for the second part of the expression
}
})
• second part, the setter
var predicate: Predicate<Region>
set(regionPredicate) {
content.predicate = regionPredicate
}
Tolga ÇAĞLAYAN
10/31/2022, 2:21 PM