Example usage for javafx.scene.control TreeView setOnMouseClicked

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

Introduction

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

Prototype

public final void setOnMouseClicked(EventHandler<? super MouseEvent> value) 

Source Link

Usage

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

/**
 * Creates the viewer control//  ww w.  ja  va2s.c  om
 *
 * @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;
}