Search in sources :

Example 36 with ContextMenu

use of javafx.scene.control.ContextMenu in project SIMVA-SoS by SESoS.

the class ChartViewer method createContextMenu.

/**
 * Creates the context menu.
 *
 * @return The context menu.
 */
private ContextMenu createContextMenu() {
    final ContextMenu menu = new ContextMenu();
    Menu export = new Menu("Export As");
    MenuItem pngItem = new MenuItem("PNG...");
    pngItem.setOnAction((ActionEvent e) -> {
        handleExportToPNG();
    });
    export.getItems().add(pngItem);
    MenuItem jpegItem = new MenuItem("JPEG...");
    jpegItem.setOnAction((ActionEvent e) -> {
        handleExportToJPEG();
    });
    export.getItems().add(jpegItem);
    if (ExportUtils.isOrsonPDFAvailable()) {
        MenuItem pdfItem = new MenuItem("PDF...");
        pdfItem.setOnAction((ActionEvent e) -> {
            handleExportToPDF();
        });
        export.getItems().add(pdfItem);
    }
    if (ExportUtils.isJFreeSVGAvailable()) {
        MenuItem svgItem = new MenuItem("SVG...");
        svgItem.setOnAction((ActionEvent e) -> {
            handleExportToSVG();
        });
        export.getItems().add(svgItem);
    }
    menu.getItems().add(export);
    return menu;
}
Also used : ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) Menu(javafx.scene.control.Menu) ContextMenu(javafx.scene.control.ContextMenu)

Example 37 with ContextMenu

use of javafx.scene.control.ContextMenu in project jabref by JabRef.

the class EditorTextArea method addToContextMenu.

/**
     * Adds the given list of menu items to the context menu.
     */
public void addToContextMenu(List<MenuItem> items) {
    TextAreaSkin customContextSkin = new TextAreaSkin(this) {

        @Override
        public void populateContextMenu(ContextMenu contextMenu) {
            super.populateContextMenu(contextMenu);
            contextMenu.getItems().addAll(0, items);
        }
    };
    setSkin(customContextSkin);
}
Also used : TextAreaSkin(com.sun.javafx.scene.control.skin.TextAreaSkin) ContextMenu(javafx.scene.control.ContextMenu)

Example 38 with ContextMenu

use of javafx.scene.control.ContextMenu in project jabref by JabRef.

the class GroupTreeController method initialize.

@FXML
public void initialize() {
    viewModel = new GroupTreeViewModel(stateManager, dialogService, taskExecutor);
    // Set-up groups tree
    groupTree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    // Set-up bindings
    Consumer<ObservableList<GroupNodeViewModel>> updateSelectedGroups = (newSelectedGroups) -> newSelectedGroups.forEach(this::selectNode);
    Consumer<List<TreeItem<GroupNodeViewModel>>> updateViewModel = (newSelectedGroups) -> {
        if (newSelectedGroups == null) {
            viewModel.selectedGroupsProperty().clear();
        } else {
            viewModel.selectedGroupsProperty().setAll(newSelectedGroups.stream().map(TreeItem::getValue).collect(Collectors.toList()));
        }
    };
    BindingsHelper.bindContentBidirectional(groupTree.getSelectionModel().getSelectedItems(), viewModel.selectedGroupsProperty(), updateSelectedGroups, updateViewModel);
    viewModel.filterTextProperty().bind(searchField.textProperty());
    groupTree.rootProperty().bind(EasyBind.map(viewModel.rootGroupProperty(), group -> new RecursiveTreeItem<>(group, GroupNodeViewModel::getChildren, GroupNodeViewModel::expandedProperty, viewModel.filterPredicateProperty())));
    // Icon and group name
    mainColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty());
    mainColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withText(GroupNodeViewModel::getDisplayName).withIcon(GroupNodeViewModel::getIconCode, GroupNodeViewModel::getColor).withTooltip(GroupNodeViewModel::getDescription));
    // Number of hits
    PseudoClass anySelected = PseudoClass.getPseudoClass("any-selected");
    PseudoClass allSelected = PseudoClass.getPseudoClass("all-selected");
    numberColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withGraphic(group -> {
        final StackPane node = new StackPane();
        node.getStyleClass().setAll("hits");
        if (!group.isRoot()) {
            BindingsHelper.includePseudoClassWhen(node, anySelected, group.anySelectedEntriesMatchedProperty());
            BindingsHelper.includePseudoClassWhen(node, allSelected, group.allSelectedEntriesMatchedProperty());
        }
        Text text = new Text();
        text.textProperty().bind(group.getHits().asString());
        text.getStyleClass().setAll("text");
        node.getChildren().add(text);
        node.setMaxWidth(Control.USE_PREF_SIZE);
        return node;
    }));
    // Arrow indicating expanded status
    disclosureNodeColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty());
    disclosureNodeColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withGraphic(viewModel -> {
        final StackPane disclosureNode = new StackPane();
        disclosureNode.visibleProperty().bind(viewModel.hasChildrenProperty());
        disclosureNode.getStyleClass().setAll("tree-disclosure-node");
        final StackPane disclosureNodeArrow = new StackPane();
        disclosureNodeArrow.getStyleClass().setAll("arrow");
        disclosureNode.getChildren().add(disclosureNodeArrow);
        return disclosureNode;
    }).withOnMouseClickedEvent(group -> event -> group.toggleExpansion()));
    // Set pseudo-classes to indicate if row is root or sub-item ( > 1 deep)
    PseudoClass rootPseudoClass = PseudoClass.getPseudoClass("root");
    PseudoClass subElementPseudoClass = PseudoClass.getPseudoClass("sub");
    // Pseudo-classes for drag and drop
    PseudoClass dragOverBottom = PseudoClass.getPseudoClass("dragOver-bottom");
    PseudoClass dragOverCenter = PseudoClass.getPseudoClass("dragOver-center");
    PseudoClass dragOverTop = PseudoClass.getPseudoClass("dragOver-top");
    groupTree.setRowFactory(treeTable -> {
        TreeTableRow<GroupNodeViewModel> row = new TreeTableRow<>();
        row.treeItemProperty().addListener((ov, oldTreeItem, newTreeItem) -> {
            boolean isRoot = newTreeItem == treeTable.getRoot();
            row.pseudoClassStateChanged(rootPseudoClass, isRoot);
            boolean isFirstLevel = (newTreeItem != null) && (newTreeItem.getParent() == treeTable.getRoot());
            row.pseudoClassStateChanged(subElementPseudoClass, !isRoot && !isFirstLevel);
        });
        row.setDisclosureNode(null);
        row.disclosureNodeProperty().addListener((observable, oldValue, newValue) -> row.setDisclosureNode(null));
        row.contextMenuProperty().bind(EasyBind.monadic(row.itemProperty()).map(this::createContextMenuForGroup).orElse((ContextMenu) null));
        row.setOnDragDetected(event -> {
            TreeItem<GroupNodeViewModel> selectedItem = treeTable.getSelectionModel().getSelectedItem();
            if ((selectedItem != null) && (selectedItem.getValue() != null)) {
                Dragboard dragboard = treeTable.startDragAndDrop(TransferMode.MOVE);
                dragboard.setDragView(row.snapshot(null, null));
                ClipboardContent content = new ClipboardContent();
                content.put(DragAndDropDataFormats.GROUP, selectedItem.getValue().getPath());
                dragboard.setContent(content);
                event.consume();
            }
        });
        row.setOnDragOver(event -> {
            Dragboard dragboard = event.getDragboard();
            if ((event.getGestureSource() != row) && row.getItem().acceptableDrop(dragboard)) {
                event.acceptTransferModes(TransferMode.MOVE, TransferMode.LINK);
                removePseudoClasses(row, dragOverBottom, dragOverCenter, dragOverTop);
                switch(getDroppingMouseLocation(row, event)) {
                    case BOTTOM:
                        row.pseudoClassStateChanged(dragOverBottom, true);
                        break;
                    case CENTER:
                        row.pseudoClassStateChanged(dragOverCenter, true);
                        break;
                    case TOP:
                        row.pseudoClassStateChanged(dragOverTop, true);
                        break;
                }
            }
            event.consume();
        });
        row.setOnDragExited(event -> {
            removePseudoClasses(row, dragOverBottom, dragOverCenter, dragOverTop);
        });
        row.setOnDragDropped(event -> {
            Dragboard dragboard = event.getDragboard();
            boolean success = false;
            if (dragboard.hasContent(DragAndDropDataFormats.GROUP)) {
                String pathToSource = (String) dragboard.getContent(DragAndDropDataFormats.GROUP);
                Optional<GroupNodeViewModel> source = viewModel.rootGroupProperty().get().getChildByPath(pathToSource);
                if (source.isPresent()) {
                    source.get().draggedOn(row.getItem(), getDroppingMouseLocation(row, event));
                    success = true;
                }
            }
            if (dragboard.hasContent(DragAndDropDataFormats.ENTRIES)) {
                TransferableEntrySelection entrySelection = (TransferableEntrySelection) dragboard.getContent(DragAndDropDataFormats.ENTRIES);
                row.getItem().addEntriesToGroup(entrySelection.getSelection());
                success = true;
            }
            event.setDropCompleted(success);
            event.consume();
        });
        return row;
    });
    // Filter text field
    setupClearButtonField(searchField);
}
Also used : PseudoClass(javafx.css.PseudoClass) TreeItem(javafx.scene.control.TreeItem) Control(javafx.scene.control.Control) BindingsHelper(org.jabref.gui.util.BindingsHelper) DialogService(org.jabref.gui.DialogService) StackPane(javafx.scene.layout.StackPane) DragEvent(javafx.scene.input.DragEvent) TreeTableRow(javafx.scene.control.TreeTableRow) TransferMode(javafx.scene.input.TransferMode) Inject(javax.inject.Inject) TextFields(org.controlsfx.control.textfield.TextFields) TreeTableView(javafx.scene.control.TreeTableView) Dragboard(javafx.scene.input.Dragboard) ContextMenu(javafx.scene.control.ContextMenu) Localization(org.jabref.logic.l10n.Localization) Method(java.lang.reflect.Method) RecursiveTreeItem(org.jabref.gui.util.RecursiveTreeItem) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) AbstractController(org.jabref.gui.AbstractController) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(java.util.function.Consumer) FXML(javafx.fxml.FXML) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Text(javafx.scene.text.Text) TreeTableColumn(javafx.scene.control.TreeTableColumn) TaskExecutor(org.jabref.gui.util.TaskExecutor) List(java.util.List) ActionEvent(javafx.event.ActionEvent) StateManager(org.jabref.gui.StateManager) SelectionMode(javafx.scene.control.SelectionMode) DragAndDropDataFormats(org.jabref.gui.DragAndDropDataFormats) EasyBind(org.fxmisc.easybind.EasyBind) ViewModelTreeTableCellFactory(org.jabref.gui.util.ViewModelTreeTableCellFactory) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) ObservableList(javafx.collections.ObservableList) ClipboardContent(javafx.scene.input.ClipboardContent) LogFactory(org.apache.commons.logging.LogFactory) CustomTextField(org.controlsfx.control.textfield.CustomTextField) PseudoClass(javafx.css.PseudoClass) ViewModelTreeTableCellFactory(org.jabref.gui.util.ViewModelTreeTableCellFactory) ClipboardContent(javafx.scene.input.ClipboardContent) Text(javafx.scene.text.Text) ContextMenu(javafx.scene.control.ContextMenu) RecursiveTreeItem(org.jabref.gui.util.RecursiveTreeItem) ObservableList(javafx.collections.ObservableList) List(java.util.List) ObservableList(javafx.collections.ObservableList) TreeTableRow(javafx.scene.control.TreeTableRow) StackPane(javafx.scene.layout.StackPane) Dragboard(javafx.scene.input.Dragboard) FXML(javafx.fxml.FXML)

Example 39 with ContextMenu

use of javafx.scene.control.ContextMenu in project Gargoyle by callakrsos.

the class DatabaseTableView method initialize.

@FXML
void initialize() {
    contextMenuTbModelMst = new ContextMenu();
    txtTableName.setOnKeyReleased(event -> {
        if (KeyCode.ENTER == event.getCode()) {
            String tableName = txtTableName.getText();
            requestTables(tableName);
        }
    });
    btnSearch.setOnMouseClicked(event -> {
        String name = txtTableName.getText();
        String selectedItem = choType.getSelectionModel().getSelectedItem();
        switch(selectedItem) {
            case TYPE_TABLE:
                requestTables(name);
                break;
            case TYPE_VIEW:
                requestViews(name);
        }
    });
    tbMaster.setOnMouseClicked(event -> {
        if (event.getClickCount() == 2) {
            tbModelMst.getItems().clear();
            TableMasterDVO selectedItem = tbMaster.getSelectionModel().getSelectedItem();
            try {
                if (selectedItem == null)
                    return;
                List<TableModelDVO> list = listColumns(selectedItem);
                tbModelMst.getItems().addAll(list);
            } catch (Exception e) {
                DialogUtil.showExceptionDailog(e, "데이터베이스 처리 에러");
            }
        }
    });
    btnSelect.setOnMouseClicked(event -> {
        if (tbMaster.getItems().isEmpty() || tbModelMst.getItems().isEmpty()) {
            return;
        }
        TableMasterDVO selectedItem = tbMaster.getSelectionModel().getSelectedItem();
        ObservableList<TableModelDVO> items = tbModelMst.getItems();
        tableDVO = new TableDVO(selectedItem, items);
        close();
    });
    MenuItem menuDelete = new MenuItem("삭제");
    menuDelete.setOnAction(event -> {
        TableViewSelectionModel<TableModelDVO> selectionModel = tbModelMst.getSelectionModel();
        int selectedIndex = selectionModel.getSelectedIndex();
        if (selectedIndex >= 0) {
            tbModelMst.getItems().remove(selectedIndex);
            selectionModel.clearSelection();
        }
    });
    // MenuItem menuDistinct = new MenuItem("중복제거");
    // menuDistinct.setOnAction(event -> {
    // ObservableList<TableModelDVO> items = tbModelMst.getItems();
    // items.stream().filter(distinctByKey(new Function<TableModelDVO,
    // ObservableList<TableModelDVO>>(){
    //
    // @Override
    // public ObservableList<TableModelDVO> apply(TableModelDVO t) {
    // // TODO Auto-generated method stub
    // return null;
    // }));
    contextMenuTbModelMst.getItems().add(menuDelete);
    tbModelMst.setContextMenu(contextMenuTbModelMst);
}
Also used : TableMasterDVO(kyj.Fx.dao.wizard.core.model.vo.TableMasterDVO) TableDVO(kyj.Fx.dao.wizard.core.model.vo.TableDVO) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) SQLException(java.sql.SQLException) FXML(javafx.fxml.FXML)

Example 40 with ContextMenu

use of javafx.scene.control.ContextMenu in project Gargoyle by callakrsos.

the class ProxyServerController method initRemote.

private void initRemote() {
    MenuItem miClear = new MenuItem("Clear All");
    lvRemoteData.setContextMenu(new ContextMenu(miClear));
    miClear.setOnAction(ev -> {
        lvRemoteData.getItems().clear();
    });
}
Also used : MenuItem(javafx.scene.control.MenuItem) ContextMenu(javafx.scene.control.ContextMenu)

Aggregations

ContextMenu (javafx.scene.control.ContextMenu)81 MenuItem (javafx.scene.control.MenuItem)69 ActionEvent (javafx.event.ActionEvent)21 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)20 Menu (javafx.scene.control.Menu)18 Label (javafx.scene.control.Label)15 List (java.util.List)13 Collectors (java.util.stream.Collectors)13 File (java.io.File)12 VBox (javafx.scene.layout.VBox)11 ObservableList (javafx.collections.ObservableList)9 ArrayList (java.util.ArrayList)8 EventHandler (javafx.event.EventHandler)8 FXCollections (javafx.collections.FXCollections)7 Optional (java.util.Optional)6 Node (javafx.scene.Node)6 Scene (javafx.scene.Scene)6 Text (javafx.scene.text.Text)6 IOException (java.io.IOException)5 Arrays (java.util.Arrays)5