Commit 6a007bae authored by Alexander Diewald's avatar Alexander Diewald

JFX Tree(Table): Enable the ctx menu for Linux

Issue-Ref: 4004
Issue-Url: https://af3-developer.fortiss.org/issues/4004Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent 3109400f
DynamicTreeContentProviderBase.java 6760a6dc5721175b1dada8f30fd9da05f7bcc4b3 GREEN
DynamicTreeItem.java 75dc5534b119ffdb3c10a65810c2a0f330b7955e GREEN
DynamicTreeTableUIProviderBase.java f4fd20e3d267bc39a33a3bbb18416312779ea886 GREEN
DynamicTreeTableUIProviderBase.java ea7de1e0fd824b61b46010d2317f93422bab6144 YELLOW
DynamicTreeTableViewer.java 431ac62cbd6ad7df25852fce1b5a62a05ba510e3 GREEN
DynamicTreeUIProviderBase.java e9b68607683de279d0cb8712a28dc131c5c33ece GREEN
DynamicTreeViewer.java e9f19d16a2a7e5a1b03b8a8b543453ac7eb6a051 GREEN
DynamicTreeViewer.java 725f41f4fb4b6bfa813f010fb9083ab02eea164a YELLOW
DynamicTreeViewerBase.java a2013538b62d86f6a09efdf2cd78babac2072484 GREEN
IDoubleClickHandler.java 447f7769dead9a106b3ea3139ef0da51eb0b9a89 GREEN
......@@ -13,15 +13,20 @@
*******************************************************************************/
package org.fortiss.tooling.common.ui.javafx.control.treetableview;
import static org.apache.commons.lang3.SystemUtils.IS_OS_LINUX;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableCell;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.cell.TextFieldTreeTableCell;
import javafx.scene.input.Dragboard;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.util.Callback;
import javafx.util.converter.DefaultStringConverter;
......@@ -233,15 +238,44 @@ public abstract class DynamicTreeTableUIProviderBase<T> {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
ContextMenu menu = null;
Node icon = null;
if(!empty && item != null) {
T data = this.getTreeTableRow().getItem();
menu = createContextMenu(data, colIndex);
icon = getIconNode(data, colIndex);
menu = createContextMenu(data, colIndex);
if(IS_OS_LINUX && menu != null) {
// JFX-builtin handling is non-operation in Linux.
addContextMenuHandler(menu, data);
}
}
this.setContextMenu(menu);
this.setGraphic(icon);
this.setContextMenu(menu);
}
/**
* Adds a handler for showing the context menu. Duplicate of the same method in
* {@link DynamicTreeViewer} due to the absence of proper selection interfaces in
* JFX.
*/
private void addContextMenuHandler(ContextMenu menu, T element) {
getTreeTableView().addEventHandler(MouseEvent.MOUSE_RELEASED, e -> {
if(e.getButton() == MouseButton.SECONDARY) {
TreeItem<T> selected =
getTreeTableView().getSelectionModel().getSelectedItem();
// We must check the element since all rows are evaluated.
if(selected != null && selected.getValue() == element) {
menu.show(this, e.getScreenX(), e.getScreenY());
e.consume();
}
} else {
// any other click cause hiding menu
menu.hide();
}
});
}
};
cell.textProperty().bind(cell.itemProperty());
......
......@@ -15,6 +15,8 @@
*******************************************************************************/
package org.fortiss.tooling.common.ui.javafx.control.treetableview;
import static org.apache.commons.lang3.SystemUtils.IS_OS_LINUX;
import javafx.beans.value.ChangeListener;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.TreeCell;
......@@ -23,6 +25,7 @@ import javafx.scene.control.TreeView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
......@@ -127,6 +130,11 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> {
ContextMenu menu = null;
if(!empty && item != null) {
menu = uiProvider.createContextMenu(item);
if(IS_OS_LINUX && menu != null) {
// JFX-builtin handling is non-operation in Linux.
addContextMenuHandler(menu, item);
}
this.setText(uiProvider.getLabel(item));
this.setGraphic(uiProvider.getIconNode(item));
this.setOnDragDetected(evt -> {
......@@ -149,6 +157,28 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> {
});
}
/**
* Adds a handler for showing the context menu. Duplicate of the same method in
* {@link DynamicTreeTableUIProviderBase} due to the absence of proper selection interfaces in
* JFX.
*/
private void addContextMenuHandler(ContextMenu menu, T element) {
view.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> {
if(e.getButton() == MouseButton.SECONDARY) {
TreeItem<T> selected = view.getSelectionModel().getSelectedItem();
// We must check the element since all rows are evaluated.
if(selected != null && selected.getValue() == element) {
menu.show(view, e.getScreenX(), e.getScreenY());
e.consume();
}
} else {
// any other click cause hiding menu
menu.hide();
}
});
}
/** Called when an item in the tree is dragged. */
private void dragDetected(MouseEvent evt, TreeCell<T> cell, T item) {
ClipboardContent cbContent = uiProvider.getDragClipboardContent(item);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment