Example usage for javafx.scene.control TreeCell TreeCell

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

Introduction

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

Prototype

public TreeCell() 

Source Link

Document

Creates a default TreeCell instance.

Usage

From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java

public void displayTreeView() {
    TreeItem<Path> root = new OverlayTreeItem(AppConstants.OVERLAY_DIR);
    root.setExpanded(true);//from w w w .jav  a2  s  .  co  m
    overlayTreeView.setRoot(root);

    overlayTreeView.setCellFactory(treeView -> new TreeCell<Path>() {
        @Override
        public void updateItem(Path path, boolean empty) {
            super.updateItem(path, empty);
            if (empty) {
                setText(null);
            } else {
                setText(path.getFileName().toString());
            }
        }
    });
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.OrganizerImpl.java

private void initializeFilesTree() {
    folderTree.setOnMouseClicked(event -> handleFolderChange());
    folderTree.setCellFactory(treeView -> {
        HBox hbox = new HBox();
        hbox.setMaxWidth(200);/*w  w w .  j a va 2 s  .  c  o m*/
        hbox.setPrefWidth(200);
        hbox.setSpacing(7);

        FontAwesomeIconView openFolderIcon = new FontAwesomeIconView(FontAwesomeIcon.FOLDER_OPEN_ALT);
        openFolderIcon.setTranslateY(7);
        FontAwesomeIconView closedFolderIcon = new FontAwesomeIconView(FontAwesomeIcon.FOLDER_ALT);
        closedFolderIcon.setTranslateY(7);

        Label dirName = new Label();
        dirName.setMaxWidth(150);

        FontAwesomeIconView removeIcon = new FontAwesomeIconView(FontAwesomeIcon.REMOVE);

        Tooltip deleteToolTip = new Tooltip();
        deleteToolTip.setText("Verzeichnis aus Workspace entfernen");

        Button button = new Button(null, removeIcon);
        button.setTooltip(deleteToolTip);
        button.setTranslateX(8);

        return new TreeCell<String>() {
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (item == null || empty) {
                    setGraphic(null);
                    setText(null);
                } else if (getTreeItem() instanceof FilePathTreeItem) {
                    hbox.getChildren().clear();
                    dirName.setText(item);
                    if (getTreeItem().isExpanded()) {
                        hbox.getChildren().add(openFolderIcon);
                    } else {
                        hbox.getChildren().add(closedFolderIcon);
                    }
                    hbox.getChildren().add(dirName);
                    TreeItem<String> treeItem = getTreeItem();
                    TreeItem<String> parent = treeItem != null ? treeItem.getParent() : null;
                    if (parent != null && parent.equals(folderTree.getRoot())) {
                        String path = ((FilePathTreeItem) getTreeItem()).getFullPath();
                        button.setOnAction(event -> handleDeleteDirectory(Paths.get(path)));
                        hbox.getChildren().add(button);
                    }
                    setGraphic(hbox);
                }
            }
        };
    });
}

From source file:net.rptools.tokentool.controller.TokenTool_Controller.java

private void addPseudoClassToLeafs(TreeView<Path> tree) {
    PseudoClass leaf = PseudoClass.getPseudoClass("leaf");

    tree.setCellFactory(tv -> {/*from w w w .  j a va2s  . c  o  m*/
        TreeCell<Path> cell = new TreeCell<>();
        cell.itemProperty().addListener((obs, oldValue, newValue) -> {
            if (newValue == null) {
                cell.setText("");
                cell.setGraphic(null);
            } else {
                cell.setText(newValue.toFile().getName());
                cell.setGraphic(cell.getTreeItem().getGraphic());
            }
        });
        cell.treeItemProperty().addListener((obs, oldTreeItem, newTreeItem) -> cell
                .pseudoClassStateChanged(leaf, newTreeItem != null && newTreeItem.isLeaf()));
        return cell;
    });
}

From source file:org.jevis.jeconfig.plugin.classes.ClassTree.java

public ClassTree(JEVisDataSource ds) {
    super();// w w w .  jav a  2 s .c o m
    try {
        _ds = ds;

        _itemCache = new HashMap<>();
        _graphicCache = new HashMap<>();
        _itemChildren = new HashMap<>();

        JEVisClass root = new JEVisRootClass(ds);
        TreeItem<JEVisClass> rootItem = buildItem(root);

        setShowRoot(true);
        rootItem.setExpanded(true);

        getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        _editor.setTreeView(this);

        setCellFactory(new Callback<TreeView<JEVisClass>, TreeCell<JEVisClass>>() {

            //                @Override
            //                public TreeCell<JEVisClass> call(TreeView<JEVisClass> p) {
            //                    return new ClassCell();
            //                }
            @Override
            public TreeCell<JEVisClass> call(TreeView<JEVisClass> param) {
                return new TreeCell<JEVisClass>() {
                    //                        private ImageView imageView = new ImageView();

                    @Override
                    protected void updateItem(JEVisClass item, boolean empty) {
                        super.updateItem(item, empty);

                        if (!empty) {
                            ClassGraphic gc = getClassGraphic(item);

                            setContextMenu(gc.getContexMenu());
                            //                                setText(item);
                            setGraphic(gc.getGraphic());
                        } else {
                            setText(null);
                            setGraphic(null);
                        }
                    }
                };
            }
        });

        getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<JEVisClass>>() {

            @Override
            public void changed(ObservableValue<? extends TreeItem<JEVisClass>> ov, TreeItem<JEVisClass> t,
                    TreeItem<JEVisClass> t1) {
                try {
                    if (t1 != null) {
                        _editor.setJEVisClass(t1.getValue());
                    }
                } catch (Exception ex) {
                    System.out.println("Error while changing editor: " + ex);
                }

            }
        });

        addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {

            @Override
            public void handle(KeyEvent t) {
                if (t.getCode() == KeyCode.F2) {
                    System.out.println("F2 rename event");
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            fireEventRename();
                        }
                    });

                } else if (t.getCode() == KeyCode.DELETE) {

                    fireDelete(getSelectionModel().getSelectedItem().getValue());
                }
            }

        });

        setId("objecttree");

        getStylesheets().add("/styles/Styles.css");
        setPrefWidth(500);

        setRoot(rootItem);
        setEditable(true);

    } catch (Exception ex) {
        //            Logger.getLogger(ObjectTree.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
    }

}