Search in sources :

Example 1 with FilterableTreeItem

use of edu.csus.yaam.test.TreeViewDemo.FilterableTreeItem in project S4T1TM2 by CSUS-CSC-131-Spring2018.

the class ProjectsScene method getScene.

@Override
public Pane getScene() {
    Pane scene = new StackPane();
    scene.setOpaqueInsets(new Insets(10));
    Pane taskNav = new Pane();
    taskNav.prefHeightProperty().bind(scene.heightProperty());
    taskNav.prefWidthProperty().bind(DoubleConstant.valueOf(150));
    // taskNav.setBackground(new Background(new BackgroundFill(Color.GREEN, null, null)));
    scene.getChildren().add(taskNav);
    TextField filterField = new JFXTextField();
    filterField.layoutXProperty().bind(DoubleConstant.valueOf(0));
    filterField.layoutYProperty().bind(DoubleConstant.valueOf(0));
    filterField.prefWidthProperty().bind(DoubleConstant.valueOf(200));
    filterField.setPromptText("Search");
    taskNav.getChildren().add(filterField);
    FilterableTreeItem<String> rootNode = new FilterableTreeItem<>("SAFsaf");
    JFXTreeView<String> treeView = new JFXTreeView<>(rootNode);
    treeView.setEditable(true);
    treeView.setShowRoot(false);
    rootNode.getInternalChildren().add(new FilterableTreeItem<String>("Sprint 1") {

        {
            this.getInternalChildren().add(new FilterableTreeItem<String>("Task A") {

                {
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task A") {

                        {
                        }
                    });
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task B") {

                        {
                        }
                    });
                }
            });
            this.getInternalChildren().add(new FilterableTreeItem<String>("Task B") {

                {
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task A") {

                        {
                        }
                    });
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task B") {

                        {
                        }
                    });
                }
            });
        }
    });
    rootNode.getInternalChildren().add(new FilterableTreeItem<String>("Sprint 2") {

        {
            this.getInternalChildren().add(new FilterableTreeItem<String>("Task A") {

                {
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task A") {

                        {
                        }
                    });
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task B") {

                        {
                        }
                    });
                }
            });
            this.getInternalChildren().add(new FilterableTreeItem<String>("Task B") {

                {
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task A") {

                        {
                        }
                    });
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task B") {

                        {
                        }
                    });
                }
            });
        }
    });
    rootNode.getInternalChildren().add(new FilterableTreeItem<String>("Sprint 2") {

        {
            this.getInternalChildren().add(new FilterableTreeItem<String>("Task A") {

                {
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task A") {

                        {
                        }
                    });
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task B") {

                        {
                        }
                    });
                }
            });
            this.getInternalChildren().add(new FilterableTreeItem<String>("Task B") {

                {
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task A") {

                        {
                        }
                    });
                    this.getInternalChildren().add(new FilterableTreeItem<String>("Sub-Task B") {

                        {
                        }
                    });
                }
            });
        }
    });
    // treeView.prefWidthProperty().bind(DoubleConstant.valueOf(200));
    treeView.layoutYProperty().bind(filterField.layoutYProperty().add(filterField.heightProperty()));
    treeView.layoutXProperty().bind(DoubleConstant.valueOf(0));
    treeView.prefWidthProperty().bind(DoubleConstant.valueOf(200));
    treeView.prefHeightProperty().bind(taskNav.heightProperty().subtract(filterField.heightProperty()));
    taskNav.getChildren().add(treeView);
    // define search predicate
    rootNode.predicateProperty().bind(Bindings.createObjectBinding(() -> {
        // predicate is reevaluated when filterfield is modified
        if (filterField.getText() == null || filterField.getText().isEmpty()) {
            return null;
        }
        return TreeViewDemo.TreeItemPredicate.create(actor -> actor.toLowerCase().contains(filterField.getText().toLowerCase()));
    }, filterField.textProperty()));
    return scene;
}
Also used : TextField(javafx.scene.control.TextField) StackPane(javafx.scene.layout.StackPane) TreeViewDemo(edu.csus.yaam.test.TreeViewDemo) Bindings(javafx.beans.binding.Bindings) Insets(javafx.geometry.Insets) DoubleConstant(com.sun.javafx.binding.DoubleConstant) NavAction(edu.csus.yaam.client.gui.nav.NavAction) FontAwesomeIcon(de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon) FilterableTreeItem(edu.csus.yaam.test.TreeViewDemo.FilterableTreeItem) ProjectScene(edu.csus.yaam.client.gui.nav.ProjectScene) JFXTreeView(com.jfoenix.controls.JFXTreeView) JFXTextField(com.jfoenix.controls.JFXTextField) Pane(javafx.scene.layout.Pane) Insets(javafx.geometry.Insets) JFXTextField(com.jfoenix.controls.JFXTextField) FilterableTreeItem(edu.csus.yaam.test.TreeViewDemo.FilterableTreeItem) TextField(javafx.scene.control.TextField) JFXTextField(com.jfoenix.controls.JFXTextField) StackPane(javafx.scene.layout.StackPane) Pane(javafx.scene.layout.Pane) StackPane(javafx.scene.layout.StackPane) JFXTreeView(com.jfoenix.controls.JFXTreeView)

Aggregations

JFXTextField (com.jfoenix.controls.JFXTextField)1 JFXTreeView (com.jfoenix.controls.JFXTreeView)1 DoubleConstant (com.sun.javafx.binding.DoubleConstant)1 FontAwesomeIcon (de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon)1 NavAction (edu.csus.yaam.client.gui.nav.NavAction)1 ProjectScene (edu.csus.yaam.client.gui.nav.ProjectScene)1 TreeViewDemo (edu.csus.yaam.test.TreeViewDemo)1 FilterableTreeItem (edu.csus.yaam.test.TreeViewDemo.FilterableTreeItem)1 Bindings (javafx.beans.binding.Bindings)1 Insets (javafx.geometry.Insets)1 TextField (javafx.scene.control.TextField)1 Pane (javafx.scene.layout.Pane)1 StackPane (javafx.scene.layout.StackPane)1