Example usage for javafx.scene.control TreeView getContextMenu

List of usage examples for javafx.scene.control TreeView getContextMenu

Introduction

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

Prototype

public final ContextMenu getContextMenu() 

Source Link

Usage

From source file:be.makercafe.apps.makerbench.Main.java

/**
 * Creates the viewer control/*from w ww .  j a  v  a 2  s .c  o  m*/
 *
 * @return
 */
private TreeView<String> createViewer() {
    TreeView<String> viewer = new TreeView<String>(setRootFolder(new File(this.pathMakerbenchHome)));
    viewer.setMinWidth(200.0);
    viewer.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    viewer.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {

            if (mouseEvent.getClickCount() == 2) {
                ResourceTreeItem<String> item = (ResourceTreeItem<String>) viewer.getSelectionModel()
                        .getSelectedItem();
                //               System.out.println("Selected Text : " + item.getValue());

                createEditor(item.getValue(), item.getPath(), null);
            } else if (mouseEvent.getButton() == MouseButton.SECONDARY) {
                ResourceTreeItem<String> item = (ResourceTreeItem<String>) viewer.getSelectionModel()
                        .getSelectedItem();
                if (item.getPath().toFile().isFile()) {
                    viewer.getContextMenu().getItems().get(0).setDisable(true);
                    viewer.getContextMenu().getItems().get(1).setDisable(true);
                    viewer.getContextMenu().getItems().get(2).setDisable(true);
                } else {
                    viewer.getContextMenu().getItems().get(0).setDisable(false);
                    viewer.getContextMenu().getItems().get(1).setDisable(false);
                    viewer.getContextMenu().getItems().get(2).setDisable(false);
                }
            }

        }
    });
    viewer.setContextMenu(rootContextMenu);
    viewer.setEditable(false);
    viewer.setShowRoot(false);

    return viewer;
}