Example usage for javafx.scene.control ContextMenu show

List of usage examples for javafx.scene.control ContextMenu show

Introduction

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

Prototype

public void show(Window owner) 

Source Link

Document

Show the popup.

Usage

From source file:org.beryx.viewreka.fxapp.codearea.ViewrekaCodeArea.java

protected void showContextMenu(ContextMenu cm) {
    if (codeTemplates.isEmpty())
        return;/*  w w w.j  a va  2s .c  om*/

    cm.getItems().clear();
    for (CodeTemplate template : codeTemplates) {
        // TODO retrieve context and create MenuItem only if template.isAllowedInContext() returns true
        MenuItem item = new MenuItem(template.getName());
        item.setOnAction(ev -> {
            if (classLoaderManager != null) {
                classLoaderManager.setProjectClassLoader();
            }
            try {
                insertCodeFragment(template);
            } finally {
                classLoaderManager.resetClassLoader();
            }
        });
        cm.getItems().add(item);
    }
    cm.getItems()
            .sort((item1, item2) -> item1.getText().toLowerCase().compareTo(item2.getText().toLowerCase()));
    cm.show(getScene().getWindow());
}