Example usage for javafx.scene.control ContextMenu setId

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

Introduction

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

Prototype

public final void setId(String value) 

Source Link

Document

Sets the id of this PopupControl .

Usage

From source file:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java

private void initialiseAutoCompletion() {

    EventStream<Integer> changesEventStream = xpathExpressionArea.plainTextChanges().map(characterChanges -> {
        if (characterChanges.getRemoved().length() > 0) {
            return characterChanges.getRemovalEnd() - 1;
        }/*from   w ww .j a v  a 2 s  .  co  m*/
        return characterChanges.getInsertionEnd();
    });

    EventStream<Integer> keyCombo = EventStreams.eventsOf(xpathExpressionArea, KeyEvent.KEY_PRESSED)
            .filter(key -> key.isControlDown() && key.getCode().equals(KeyCode.SPACE))
            .map(searchPoint -> xpathExpressionArea.getCaretPosition());

    // captured in the closure
    final ContextMenu autoCompletePopup = new ContextMenuWithNoArrows();
    autoCompletePopup.setId("xpathAutocomplete");
    autoCompletePopup.setHideOnEscape(true);

    EventStreams.merge(keyCombo, changesEventStream).map(searchPoint -> {
        int indexOfSlash = xpathExpressionArea.getText().lastIndexOf("/", searchPoint - 1) + 1;
        String input = xpathExpressionArea.getText();
        if (searchPoint > input.length()) {
            searchPoint = input.length();
        }
        input = input.substring(indexOfSlash, searchPoint);

        return Tuples.t(indexOfSlash, input);
    }).filter(t -> StringUtils.isAlpha(t._2)).subscribe(s -> autoComplete(s._1, s._2, autoCompletePopup));

}