Example usage for javafx.scene.control TreeItem TreeItem

List of usage examples for javafx.scene.control TreeItem TreeItem

Introduction

In this page you can find the example usage for javafx.scene.control TreeItem TreeItem.

Prototype

public TreeItem(final T value) 

Source Link

Document

Creates a TreeItem with the value property set to the provided object.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    rootNode.setExpanded(true);//from  ww w.  j  a  v a2s.c  o  m
    System.out.println(rootNode.toString());
    for (Employee employee : employees) {
        TreeItem<String> empLeaf = new TreeItem<String>(employee.getName());
        boolean found = false;
        for (TreeItem<String> depNode : rootNode.getChildren()) {
            if (depNode.getValue().contentEquals(employee.getDepartment())) {
                depNode.getChildren().add(empLeaf);
                found = true;
                break;
            }
        }
        if (!found) {
            TreeItem depNode = new TreeItem(employee.getDepartment());
            rootNode.getChildren().add(depNode);
            depNode.getChildren().add(empLeaf);
        }
    }
    stage.setTitle("Tree View Sample");
    VBox box = new VBox();
    final Scene scene = new Scene(box, 400, 300);
    scene.setFill(Color.LIGHTGRAY);

    TreeView<String> treeView = new TreeView<String>(rootNode);
    treeView.setShowRoot(true);
    treeView.setEditable(true);
    box.getChildren().add(treeView);
    stage.setScene(scene);
    stage.show();
}

From source file:sonicScream.utilities.ScriptParser.java

public static TreeItem<String> parseScript(BufferedReader scriptReader, String fileName) throws IOException {
    if (fileName.contains(".vsndevts_c")) {
        return parseCompiledScript(scriptReader, fileName);
    } else {/*from w w  w. j  av  a 2  s.c  om*/
        _rootItem = new TreeItem<>("root");
        _currentParent = _rootItem;

        String line;
        while ((line = scriptReader.readLine()) != null) {
            parseLine(line);
        }
        return _rootItem;
    }
}

From source file:sonicScream.utilities.ScriptParser.java

private static TreeItem<String> parseCompiledScript(BufferedReader scriptReader, String fileName)
        throws IOException {
    _rootItem = new TreeItem<>("root");
    _currentParent = _rootItem;/*w  w  w  . j  a  va2 s.  c  om*/

    parseHeaderAndFirstTwoLines(scriptReader, StringParsing.getScriptNameFromFileName(fileName));

    String line;
    while ((line = scriptReader.readLine()) != null) {
        if (line.contains("operator_stacks")) {
            parseNameAndOperatorStacks(line);
        } else {
            parseLine(line);
        }

        if (line.contains("{")) {
            _openBraces++;
        }
        if (line.contains("}")) {
            _closeBraces++;
        }

        if (_openBraces == _closeBraces && (_openBraces != 0) && (_closeBraces != 0)) {
            parseLine("}");
            _openBraces = 0;
            _closeBraces = 0;
        }
    }
    return _rootItem;
}

From source file:Main.java

public Main() {
    this.rootNode = new TreeItem<>("MyCompany Human Resources");
}

From source file:Main.java

@Override
public void start(Stage stage) {
    rootNode.setExpanded(true);/*from  w  ww.ja va2 s.c om*/
    for (Employee employee : employees) {
        TreeItem<String> empLeaf = new TreeItem<>(employee.getName());
        boolean found = false;
        for (TreeItem<String> depNode : rootNode.getChildren()) {
            if (depNode.getValue().contentEquals(employee.getDepartment())) {
                depNode.getChildren().add(empLeaf);
                found = true;
                break;
            }
        }
        if (!found) {
            TreeItem depNode = new TreeItem(employee.getDepartment());
            rootNode.getChildren().add(depNode);
            depNode.getChildren().add(empLeaf);
        }
    }

    stage.setTitle("Tree View Sample");
    VBox box = new VBox();
    final Scene scene = new Scene(box, 400, 300);
    scene.setFill(Color.LIGHTGRAY);

    TreeView<String> treeView = new TreeView<>(rootNode);
    treeView.setEditable(true);
    treeView.setCellFactory((TreeView<String> p) -> new TextFieldTreeCellImpl());

    box.getChildren().add(treeView);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    root.setExpanded(true);/*from ww w. ja v  a  2s  .c  o  m*/
    employees.stream().forEach((employee) -> {
        root.getChildren().add(new TreeItem<>(employee));
    });
    Scene scene = new Scene(new Group(), 400, 400);
    Group sceneRoot = (Group) scene.getRoot();

    TreeTableColumn<Employee, String> empColumn = new TreeTableColumn<>("Employee");
    empColumn.setPrefWidth(150);
    empColumn.setCellValueFactory(
            (TreeTableColumn.CellDataFeatures<Employee, String> param) -> new ReadOnlyStringWrapper(
                    param.getValue().getValue().getName()));

    TreeTableColumn<Employee, String> emailColumn = new TreeTableColumn<>("Email");
    emailColumn.setPrefWidth(190);
    emailColumn.setCellValueFactory(
            (TreeTableColumn.CellDataFeatures<Employee, String> param) -> new ReadOnlyStringWrapper(
                    param.getValue().getValue().getEmail()));

    TreeTableView<Employee> treeTableView = new TreeTableView<>(root);
    treeTableView.getColumns().setAll(empColumn, emailColumn);

    treeTableView.setTableMenuButtonVisible(true);

    sceneRoot.getChildren().add(treeTableView);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    rootNode.setExpanded(true);/*from  w  w  w  .  j a va  2 s.c o  m*/
    for (Employee employee : employees) {
        TreeItem<String> empLeaf = new TreeItem<>(employee.getName());
        boolean found = false;
        for (TreeItem<String> depNode : rootNode.getChildren()) {
            if (depNode.getValue().contentEquals(employee.getDepartment())) {
                depNode.getChildren().add(empLeaf);
                found = true;
                break;
            }
        }
        if (!found) {
            TreeItem<String> depNode = new TreeItem<>(employee.getDepartment());
            rootNode.getChildren().add(depNode);
            depNode.getChildren().add(empLeaf);
        }
    }

    stage.setTitle("Tree View Sample");
    VBox box = new VBox();
    final Scene scene = new Scene(box, 400, 300);
    scene.setFill(Color.LIGHTGRAY);

    TreeView<String> treeView = new TreeView<>(rootNode);
    treeView.setEditable(true);
    treeView.setCellFactory((TreeView<String> p) -> new TextFieldTreeCellImpl());

    box.getChildren().add(treeView);
    stage.setScene(scene);
    stage.show();
}

From source file:com.cdd.bao.editor.endpoint.BrowseEndpoint.java

public BrowseEndpoint(Stage stage) {
    this.stage = stage;

    stage.setTitle("BioAssay Schema Browser");

    treeRoot = new TreeItem<>(new Branch(this));
    treeView = new TreeView<>(treeRoot);
    treeView.setEditable(true);/*from  w ww .j a  v  a2s .co  m*/
    treeView.setCellFactory(p -> new BrowseTreeCell());
    treeView.getSelectionModel().selectedItemProperty().addListener((observable, oldval, newval) -> {
        changeValue(newval.getValue());
    });

    display = new DisplaySchema();

    StackPane sp1 = new StackPane(), sp2 = new StackPane();
    sp1.getChildren().add(treeView);
    sp2.getChildren().add(display);

    splitter = new SplitPane();
    splitter.setOrientation(Orientation.HORIZONTAL);
    splitter.getItems().addAll(sp1, sp2);
    splitter.setDividerPositions(0.4, 1.0);

    root = new BorderPane();
    root.setTop(menuBar);
    root.setCenter(splitter);

    Scene scene = new Scene(root, 700, 600, Color.WHITE);

    stage.setScene(scene);

    treeView.setShowRoot(false);

    rebuildTree();

    Platform.runLater(() -> treeView.getFocusModel().focus(treeView.getSelectionModel().getSelectedIndex())); // for some reason it defaults to not the first item

    new Thread(() -> backgroundLoadTemplates()).start();
}

From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java

@FXML
public void initialize() {
    this.rootItem = new TreeItem<>(new TreeNode("[root]"));
    this.root.setRoot(this.rootItem);
    this.root.setCellFactory(new TreeCellFactory<>(node -> {
        if (node.getParent() == null) {
            ContextMenu export = new ContextMenu();

            MenuItem exportItem = new MenuItem("Export");

            export.setOnAction(e -> {
                File file = messageHandler.chooseFile().withInitialDirectory(new File("."))
                        .withTitle(Message.GENERIC_CHOOSE_EXPORT_LOCATION_JAR.format())
                        .withExtensionFilter(new FileFilter(Message.FILETYPE_JAVA_ARCHIVE.format(), "*.jar"),
                                true)// w  ww  .ja  v  a  2 s .  c  o m
                        .promptSave();

                OpenedFile openedFile = (OpenedFile) node.getMetadata().get(OpenedFile.OPENED_FILE);

                Map<String, byte[]> clone = new HashMap<>(openedFile.getContents());

                backgroundTaskHelper.submit(
                        new BackgroundTask(Message.TASK_SAVING_FILE.format(node.getDisplayName()), true, () -> {
                            try {
                                if (!file.exists()) {
                                    if (!file.createNewFile()) {
                                        throw new IOException("Could not create export file");
                                    }
                                }

                                try (ZipOutputStream zipOutputStream = new ZipOutputStream(
                                        new FileOutputStream(file))) {
                                    for (Map.Entry<String, byte[]> ent : clone.entrySet()) {
                                        ZipEntry zipEntry = new ZipEntry(ent.getKey());
                                        zipOutputStream.putNextEntry(zipEntry);
                                        zipOutputStream.write(ent.getValue());
                                        zipOutputStream.closeEntry();
                                    }
                                }

                                messageHandler.handleMessage(Message.GENERIC_EXPORTED.format());
                            } catch (IOException ex) {
                                messageHandler.handleException(Message.ERROR_IOEXCEPTION_OCCURRED.format(), ex);
                            }
                        }));
            });

            export.getItems().add(exportItem);
            return export;
        }
        return null;
    }));

    root.addEventHandler(KeyEvent.KEY_RELEASED, event -> {
        if (event.getCode() == KeyCode.ENTER) {
            TreeItem<TreeNode> selected = this.root.getSelectionModel().getSelectedItem();
            if (selected != null) {
                if (selected.getChildren().size() != 0) {
                    selected.setExpanded(!selected.isExpanded());
                } else {
                    getParentController().getAllFilesViewerController().handleClick(selected.getValue());
                }
            }
        }
    });

    Tooltip tooltip = new Tooltip();
    StringBuilder search = new StringBuilder();

    List<TreeItem<TreeNode>> searchContext = new ArrayList<>();
    AtomicInteger searchIndex = new AtomicInteger();

    root.focusedProperty().addListener((observable, oldValue, newValue) -> {
        if (!newValue) {
            tooltip.hide();
            search.setLength(0);
        }
    });

    root.boundsInLocalProperty().addListener((observable, oldValue, newValue) -> {
        Bounds bounds = root.localToScreen(newValue);
        tooltip.setAnchorX(bounds.getMinX());
        tooltip.setAnchorY(bounds.getMinY());
    });

    root.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
        if (tooltip.isShowing() && event.getCode() == KeyCode.UP) {
            if (searchIndex.decrementAndGet() < 0) {
                searchIndex.set(searchContext.size() - 1);
            }
        } else if (tooltip.isShowing() && event.getCode() == KeyCode.DOWN) {
            if (searchIndex.incrementAndGet() >= searchContext.size()) {
                searchIndex.set(0);
            }
        } else {
            return;
        }
        event.consume();

        root.scrollTo(root.getRow(searchContext.get(searchIndex.get())));
        root.getSelectionModel().select(searchContext.get(searchIndex.get()));
    });

    root.addEventHandler(KeyEvent.KEY_TYPED, event -> {
        if (event.getCharacter().charAt(0) == '\b') {
            if (search.length() > 0) {
                search.setLength(search.length() - 1);
            }
        } else if (event.getCharacter().charAt(0) == '\u001B') { //esc
            tooltip.hide();
            search.setLength(0);
            return;
        } else if (search.length() > 0
                || (search.length() == 0 && StringUtils.isAlphanumeric(event.getCharacter()))) {
            search.append(event.getCharacter());
            if (!tooltip.isShowing()) {
                tooltip.show(root.getScene().getWindow());
            }
        }

        if (!tooltip.isShowing())
            return;

        String str = search.toString();
        tooltip.setText("Search for: " + str);

        searchContext.clear();

        ArrayDeque<TreeItem<TreeNode>> deque = new ArrayDeque<>();
        deque.addAll(rootItem.getChildren());

        while (!deque.isEmpty()) {
            TreeItem<TreeNode> item = deque.poll();
            if (item.getValue().getDisplayName().contains(str)) {
                searchContext.add(item);
            }
            if (item.isExpanded() && item.getChildren().size() > 0)
                deque.addAll(item.getChildren());
        }

        searchIndex.set(0);
        if (searchContext.size() > 0) {
            root.scrollTo(root.getRow(searchContext.get(0)));
            root.getSelectionModel().select(searchContext.get(0));
        }
    });

    openedFileController.loadedFiles().addListener((MapChangeListener<String, OpenedFile>) change -> {
        if (change.getValueAdded() != null) {
            updateTree(change.getValueAdded());
        }
        if (change.getValueRemoved() != null) {
            this.rootItem.getChildren()
                    .removeIf(ti -> ti.getValue().equals(change.getValueRemoved().getRoot()));
        }
    });
}

From source file:com.getqube.store.BrowseCategoryController.java

public void initialize() {
    new Thread(new Runnable() {
        @Override//from   w ww.  ja v a2 s  .  co m
        public void run() {
            Category c = ApplicationContext.getInstance().getRegisteredObject(Category.class);

            try {
                App[] apps = AppService.allForCategory(String.valueOf(c.getId()));

                // Show the app detail page now that the data has been loaded from the Web.
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {

                        for (App app : apps) {
                            CategoryButtonControl button = new CategoryButtonControl();
                            button.setLink(app.getName());

                            button.setImage(new Image(app.getThumbnail()));

                            button.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
                                public void handle(final MouseEvent mouseEvent) {
                                    ApplicationContext.getInstance().register(app);

                                    TreeItem<String> appItem = new TreeItem<String>(app.getName());
                                    CategoriesController.BREADCRUMBS.getSelectedCrumb().getChildren()
                                            .add(appItem);
                                    CategoriesController.BREADCRUMBS.setSelectedCrumb(appItem);

                                    Navigator.loadVista(Navigator.APP_DETAIL);
                                }
                            });

                            paneApps.getChildren().add(button);
                        }

                        paneLoading.setVisible(false);
                        paneEverything.setVisible(true);
                    }
                });
            } catch (ProcessingException processingException) {
                logger.log(Level.WARNING, processingException.getMessage(), processingException);
                reportConnectionProblem();
            } catch (IOException ioException) {
                logger.log(Level.WARNING, ioException.getMessage(), ioException);
                reportConnectionProblem();
            }
        }
    }).start();
}