Skip to main content
summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorChristoph Keimel2015-05-15 04:17:14 -0400
committerChristoph Keimel2015-05-15 04:18:00 -0400
commit5128c5a95a5f71e320e1e65ca2fbfac56a8b9c44 (patch)
tree32e3193989fd4e1ea955d228711507f01b2b8003 /demos
parent0dd9ce135081d388b1565d4737a708c797409757 (diff)
downloadorg.eclipse.efxclipse-5128c5a95a5f71e320e1e65ca2fbfac56a8b9c44.tar.gz
org.eclipse.efxclipse-5128c5a95a5f71e320e1e65ca2fbfac56a8b9c44.tar.xz
org.eclipse.efxclipse-5128c5a95a5f71e320e1e65ca2fbfac56a8b9c44.zip
Bug 467380 - [sample] Create sample for FilterableTreeItem
Signed-off-by: Christoph Keimel <c.keimel@emsw.de> Change-Id: I8007a7dc22b13d99490f011ef4a17f8d5a87724e
Diffstat (limited to 'demos')
-rw-r--r--demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/FilterableTreeItemSample.java150
1 files changed, 150 insertions, 0 deletions
diff --git a/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/FilterableTreeItemSample.java b/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/FilterableTreeItemSample.java
new file mode 100644
index 000000000..3b3e7068e
--- /dev/null
+++ b/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/FilterableTreeItemSample.java
@@ -0,0 +1,150 @@
+package org.eclipse.fx.ui.controls.sample;
+
+import javafx.application.Application;
+import javafx.beans.binding.Bindings;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.scene.Node;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.scene.control.TextField;
+import javafx.scene.control.TitledPane;
+import javafx.scene.control.TreeView;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Priority;
+import javafx.scene.layout.VBox;
+import javafx.stage.Stage;
+
+import org.eclipse.fx.ui.controls.tree.FilterableTreeItem;
+import org.eclipse.fx.ui.controls.tree.TreeItemPredicate;
+
+public class FilterableTreeItemSample extends Application {
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+ private TextField filterField;
+
+ @Override
+ public void start(Stage stage) throws Exception {
+ try {
+ Parent root = createContents();
+ Scene scene = new Scene(root, 800, 600);
+ stage.setScene(scene);
+ stage.show();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private Parent createContents() {
+ VBox vbox = new VBox(6);
+ vbox.getChildren().add(createFilterPane());
+ Node demoPane = createDemoPane();
+ VBox.setVgrow(demoPane, Priority.ALWAYS);
+ vbox.getChildren().add(demoPane);
+ return new BorderPane(vbox);
+ }
+
+ private Node createFilterPane() {
+ filterField = new TextField();
+ filterField.setPromptText("Enter filter text ...");
+
+ TitledPane pane = new TitledPane("Filter", filterField);
+ pane.setCollapsible(false);
+ return pane;
+ }
+
+ private Node createDemoPane() {
+ HBox hbox = new HBox(6);
+ Node filteredTree = createFilteredTree();
+ HBox.setHgrow(filteredTree, Priority.ALWAYS);
+ hbox.getChildren().add(filteredTree);
+ return hbox;
+ }
+
+ private Node createFilteredTree() {
+ FilterableTreeItem<Actor> root = getTreeModel();
+ root.predicateProperty().bind(Bindings.createObjectBinding(() -> {
+ if (filterField.getText() == null || filterField.getText().isEmpty())
+ return null;
+ return TreeItemPredicate.create(actor -> actor.toString().contains(filterField.getText()));
+ }, filterField.textProperty()));
+
+ TreeView<Actor> treeView = new TreeView<>(root);
+ treeView.setShowRoot(false);
+
+ TitledPane pane = new TitledPane("Filtered TreeView", treeView);
+ pane.setCollapsible(false);
+ pane.setMaxHeight(Double.MAX_VALUE);
+ return pane;
+ }
+
+ private FilterableTreeItem<Actor> getTreeModel() {
+ FilterableTreeItem<Actor> root = new FilterableTreeItem<>(new Actor("Root"));
+ FilterableTreeItem<Actor> folder1 = createFolder("Folder 1");
+ folder1.setExpanded(true);
+ root.getInternalChildren().add(folder1);
+ root.getInternalChildren().add(createFolder("Folder 2"));
+ root.getInternalChildren().add(createFolder("Folder 3"));
+ return root;
+ }
+
+ private FilterableTreeItem<Actor> createFolder(String name) {
+ FilterableTreeItem<Actor> folder = new FilterableTreeItem<>(new Actor(name));
+ getActorList().forEach(actor -> folder.getInternalChildren().add(new FilterableTreeItem<>(actor)));
+ return folder;
+ }
+
+ private Iterable<Actor> getActorList() {
+ ObservableList<Actor> actorList = FXCollections.observableArrayList(
+ new Actor("Jack", "Nicholson"),
+ new Actor("Marlon", "Brando"),
+ new Actor("Robert", "De Niro"),
+ new Actor("Al", "Pacino"),
+ new Actor("Daniel","Day-Lewis"),
+ new Actor("Dustin", "Hoffman"),
+ new Actor("Tom", "Hanks"),
+ new Actor("Anthony", "Hopkins"),
+ new Actor("Paul", "Newman"),
+ new Actor("Denzel", "Washington"),
+ new Actor("Spencer", "Tracy"),
+ new Actor("Laurence", "Olivier"),
+ new Actor("Jack", "Lemmon"),
+ new Actor("Jeff", "Bridges"),
+ new Actor("James", "Stewart"),
+ new Actor("Sean", "Penn"),
+ new Actor("Michael", "Caine"),
+ new Actor("Morgan", "Freeman"),
+ new Actor("Robert", "Duvall"),
+ new Actor("Gene", "Hackman"),
+ new Actor("Clint", "Eastwood"),
+ new Actor("Gregory", "Peck"),
+ new Actor("Robin", "Williams"),
+ new Actor("Ben", "Kingsley"),
+ new Actor("Philip", "Seymour Hoffman"));
+ return actorList;
+ }
+
+ private static class Actor {
+ public String firstname;
+ public String lastname;
+
+ public Actor(String string) {
+ this.lastname = string;
+ }
+
+ public Actor(String firstname, String lastname) {
+ this.firstname = firstname;
+ this.lastname = lastname;
+ }
+
+ @Override
+ public String toString() {
+ return firstname == null ? lastname : firstname + " " + lastname;
+ }
+ }
+
+}

Back to the top