Java Code Examples for javafx.scene.control.Control#setContextMenu()

The following examples show how to use javafx.scene.control.Control#setContextMenu() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisplayEditorInstance.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
DisplayEditorInstance(final DisplayEditorApplication app)
{
    this.app = app;

    final DockPane dock_pane = DockPane.getActiveDockPane();
    JFXRepresentation.setSceneStyle(dock_pane.getScene());
    EditorUtil.setSceneStyle(dock_pane.getScene());

    editor_gui = new EditorGUI();

    extendToolbar();

    dock_item = new DockItemWithInput(this, editor_gui.getParentNode(), null, FilenameSupport.file_extensions, this::doSave);
    dock_pane.addTab(dock_item);

    // Update tab's title when model has been loaded
    editor_gui.setModelListener(this::handleNewModel);

    // Mark 'dirty' whenever there's a change, i.e. something to un-do
    editor_gui.getDisplayEditor()
              .getUndoableActionManager()
              .addListener((to_undo, to_redo) -> dock_item.setDirty(to_undo != null));

    final ContextMenu menu = new ContextMenu();
    final Control menu_node = editor_gui.getDisplayEditor().getContextMenuNode();
    menu_node.setOnContextMenuRequested(event -> handleContextMenu(menu, event));
    menu_node.setContextMenu(menu);

    dock_item.addCloseCheck(this::okToClose);
    dock_item.addClosedNotification(this::dispose);
}
 
Example 2
Source File: EditorGUI.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private void hookWidgetTreeContextMenu(final Control node)
{
    final ContextMenu menu = new ContextMenu(new MenuItem());
    node.setContextMenu(menu);
    menu.setOnShowing(event ->
    {
        // Enable/disable menu entries based on selection
        final List<Widget> widgets = editor.getWidgetSelectionHandler().getSelection();
        final MenuItem delete = new ActionWapper(ActionDescription.DELETE);
        final MenuItem cut = new ActionWapper(ActionDescription.CUT);
        final MenuItem copy = new ActionWapper(ActionDescription.COPY);
        final MenuItem group = new CreateGroupAction(editor, widgets);
        if (widgets.size() < 0)
        {
            delete.setDisable(true);
            cut.setDisable(true);
            copy.setDisable(true);
        }
        final MenuItem ungroup;
        if (widgets.size() == 1  &&  widgets.get(0) instanceof GroupWidget)
            ungroup = new RemoveGroupAction(editor, (GroupWidget)widgets.get(0));
        else
        {
            ungroup = new RemoveGroupAction(editor, null);
            ungroup.setDisable(true);
        }
        if (editor.isReadonly())
            menu.getItems().setAll(copy,
                                   new FindWidgetAction(node, editor),
                                   new ExpandTreeAction(tree),
                                   new CollapseTreeAction(tree),
                                   new SeparatorMenuItem());
        else
            menu.getItems().setAll(delete,
                                   cut,
                                   copy,
                                   new PasteWidgets(this),
                                   new FindWidgetAction(node, editor),
                                   new ExpandTreeAction(tree),
                                   new CollapseTreeAction(tree),
                                   new SeparatorMenuItem(),
                                   group,
                                   ungroup,
                                   new SeparatorMenuItem(),
                                   new ActionWapper(ActionDescription.TO_BACK),
                                   new ActionWapper(ActionDescription.MOVE_UP),
                                   new ActionWapper(ActionDescription.MOVE_DOWN),
                                   new ActionWapper(ActionDescription.TO_FRONT));
    });
}