use of javafx.scene.control.ContextMenu in project Gargoyle by callakrsos.
the class MacroSqlComposite method post.
@FxPostInitialize
public void post() {
MenuItem menuAddItem = new MenuItem("Add");
menuAddItem.setAccelerator(new KeyCodeCombination(KeyCode.INSERT, KeyCharacterCombination.CONTROL_DOWN));
menuAddItem.setOnAction(e -> {
addOnAction();
});
MenuItem menuDeleteItem = new MenuItem("Delete");
menuDeleteItem.setAccelerator(new KeyCodeCombination(KeyCode.DELETE, KeyCharacterCombination.CONTROL_DOWN));
menuDeleteItem.setOnAction(e -> {
addOnAction();
});
tvFavorite.setContextMenu(new ContextMenu(menuAddItem, menuDeleteItem));
borContent.setCenter(new MacroControl(connectionSupplier, initText));
MacroFavorTreeItemCreator macroFavorTreeItem = new MacroFavorTreeItemCreator(connectionSupplier);
MacroItemVO f = new MacroItemVO();
tvFavorite.setRoot(macroFavorTreeItem.createRoot(f));
tvFavorite.setShowRoot(false);
}
use of javafx.scene.control.ContextMenu in project jgnash by ccavanaugh.
the class AboutDialogController method getSystemPropertiesTab.
private Tab getSystemPropertiesTab() {
final ObservableList<SystemProperty> propertiesList = FXCollections.observableArrayList();
final Properties properties = System.getProperties();
propertiesList.addAll(properties.stringPropertyNames().stream().map(prop -> new SystemProperty(prop, properties.getProperty(prop))).collect(Collectors.toList()));
FXCollections.sort(propertiesList);
final TableColumn<SystemProperty, String> keyCol = new TableColumn<>(resources.getString("Column.PropName"));
keyCol.setCellValueFactory(param -> param.getValue().keyProperty());
final TableColumn<SystemProperty, String> valueCol = new TableColumn<>(resources.getString("Column.PropVal"));
valueCol.setCellValueFactory(param -> param.getValue().valueProperty());
final TableView<SystemProperty> tableView = new TableView<>(propertiesList);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
final ObservableList<TableColumn<SystemProperty, ?>> tableViewColumns = tableView.getColumns();
tableViewColumns.add(keyCol);
tableViewColumns.add(valueCol);
tableView.getStylesheets().addAll(MainView.DEFAULT_CSS);
final ContextMenu menu = new ContextMenu();
final MenuItem copyMenuItem = new MenuItem(resources.getString("Menu.Copy.Name"));
copyMenuItem.setOnAction(event -> dumpPropertiesToClipboard(tableView));
menu.getItems().add(copyMenuItem);
tableView.setContextMenu(menu);
return new Tab(ResourceUtils.getString("Tab.SysInfo"), tableView);
}
use of javafx.scene.control.ContextMenu in project JFoenix by jfoenixadmin.
the class JFXTreeTableColumn method init.
private void init() {
this.setCellFactory(new Callback<TreeTableColumn<S, T>, TreeTableCell<S, T>>() {
@Override
public TreeTableCell<S, T> call(TreeTableColumn<S, T> param) {
return new JFXTreeTableCell<S, T>() {
@Override
protected void updateItem(T item, boolean empty) {
if (item == getItem())
return;
super.updateItem(item, empty);
if (item == null) {
super.setText(null);
super.setGraphic(null);
} else if (item instanceof Node) {
super.setText(null);
super.setGraphic((Node) item);
} else {
super.setText(item.toString());
super.setGraphic(null);
}
}
};
}
});
Platform.runLater(() -> {
final ContextMenu contextMenu = new ContextMenu();
// contextMenu.setOnShowing((showing)->{
// System.out.println("showing");
// });
// contextMenu.setOnShown((shown)->{
// System.out.println("shown");
// });
MenuItem item1 = new MenuItem("Group");
item1.setOnAction((action) -> {
((JFXTreeTableView) getTreeTableView()).group(this);
});
MenuItem item2 = new MenuItem("UnGroup");
item2.setOnAction((action) -> {
((JFXTreeTableView) getTreeTableView()).unGroup(this);
});
contextMenu.getItems().addAll(item1, item2);
setContextMenu(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);
}
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);
}
Aggregations