Search in sources :

Example 1 with TreeItemPredicate

use of com.kyj.fx.voeditor.visual.component.tree.TreeItemPredicate in project Gargoyle by callakrsos.

the class FilteredTreeItemExam method start.

@Override
public void start(Stage primaryStage) throws Exception {
    FilterableTreeItem<String> filterableTreeItem = new FilterableTreeItem<>("");
    filterableTreeItem.setExpanded(true);
    TreeView<String> treeView = new TreeView<>(filterableTreeItem);
    treeView.setShowRoot(false);
    treeView.setRoot(filterableTreeItem);
    BorderPane borderPane = new BorderPane(treeView);
    TextField value = new TextField();
    value.textProperty().addListener((oba, oldval, newval) -> {
        Callable<TreeItemPredicate<String>> func = () -> {
            Predicate<String> predicate = str -> str.indexOf(newval) >= 0;
            return TreeItemPredicate.<String>create(predicate);
        };
        ObjectBinding<TreeItemPredicate<String>> createObjectBinding = Bindings.createObjectBinding(func, hide);
        filterableTreeItem.predicateProperty().bind(createObjectBinding);
    });
    borderPane.setTop(value);
    Scene scene = new Scene(borderPane);
    primaryStage.setScene(scene);
    primaryStage.show();
    FilterableTreeItem<String> e = new FilterableTreeItem<>("ABC");
    //		e.getChildren().add(new FilterableTreeItem<>("DEF"));
    //		e.getChildren().add(new FilterableTreeItem<>("김aa"));
    //		e.getChildren().add(new FilterableTreeItem<>("김bb"));
    //		e.getChildren().add(new FilterableTreeItem<>("김cc"));
    //		filterableTreeItem.getChildren().add(e);
    //		filterableTreeItem.getChildren().add(new FilterableTreeItem<>("DEF"));
    //		filterableTreeItem.getChildren().add(new FilterableTreeItem<>("김DD"));
    //
    e.getSourceChildren().add(new FilterableTreeItem<>("DEF"));
    e.getSourceChildren().add(new FilterableTreeItem<>("김aa"));
    e.getSourceChildren().add(new FilterableTreeItem<>("김bb"));
    e.getSourceChildren().add(new FilterableTreeItem<>("김cc"));
    filterableTreeItem.getSourceChildren().add(e);
    filterableTreeItem.getSourceChildren().add(new FilterableTreeItem<>("DEF"));
    filterableTreeItem.getSourceChildren().add(new FilterableTreeItem<>("김DD"));
// filterableTreeItem.predicateProperty()
// .bind(Bindings.createObjectBinding(() ->
// TreeItemPredicate<String>.create(str -> str.indexOf("김") >= 0),
// hide));
}
Also used : BorderPane(javafx.scene.layout.BorderPane) FilterableTreeItem(com.kyj.fx.voeditor.visual.component.tree.FilterableTreeItem) Scene(javafx.scene.Scene) Predicate(java.util.function.Predicate) TreeItemPredicate(com.kyj.fx.voeditor.visual.component.tree.TreeItemPredicate) TreeItemPredicate(com.kyj.fx.voeditor.visual.component.tree.TreeItemPredicate) TreeView(javafx.scene.control.TreeView) TextField(javafx.scene.control.TextField)

Aggregations

FilterableTreeItem (com.kyj.fx.voeditor.visual.component.tree.FilterableTreeItem)1 TreeItemPredicate (com.kyj.fx.voeditor.visual.component.tree.TreeItemPredicate)1 Predicate (java.util.function.Predicate)1 Scene (javafx.scene.Scene)1 TextField (javafx.scene.control.TextField)1 TreeView (javafx.scene.control.TreeView)1 BorderPane (javafx.scene.layout.BorderPane)1