Add DataGrid column visibility controls and action icons
This commit is contained in:
@@ -47,9 +47,22 @@ Drag a column's right boundary to preview a bounded width; release commits that
|
|||||||
column and Escape restores its previous sizing intent. Drag a header label to
|
column and Escape restores its previous sizing intent. Drag a header label to
|
||||||
move a column, or into the grouping area to add a chip. Insertion feedback and
|
move a column, or into the grouping area to add a chip. Insertion feedback and
|
||||||
fixed-position constraints apply; invalid/outside drops cancel without sorting.
|
fixed-position constraints apply; invalid/outside drops cancel without sorting.
|
||||||
Grouped columns remain visible. Drag chips to reorder levels, and use × to remove
|
Drag chips to reorder grouping levels, and use × to remove a grouping level.
|
||||||
a grouping level. A header click still sorts and the separate filter icon opens
|
A header click sorts and the separate filter icon opens its editor. The Grid
|
||||||
its editor. The Grid setup menu offers keyboard-operable Column settings.
|
setup menu offers keyboard-operable Column settings.
|
||||||
|
|
||||||
|
The arrow at the far right of the header opens a checklist of all columns.
|
||||||
|
Select a column to toggle its visibility. A column header's context menu offers
|
||||||
|
ascending and descending sorting, clearing that column's sort, filtering and
|
||||||
|
grouping where configured, resetting the column width, and hiding the column.
|
||||||
|
The arrow remains available when every column is hidden.
|
||||||
|
|
||||||
|
Applications can use `setColumnVisible(id, visible)`, `isColumnVisible(id)`,
|
||||||
|
and `columnVisibilityRevisionProperty()` to observe changes from either the UI or code.
|
||||||
|
Visibility applies to the open grid, including later pages. Hiding a column
|
||||||
|
preserves its order, width, filters, sorting, and grouping, and leaves existing
|
||||||
|
row components and drafts in place. Saved setups currently store the column
|
||||||
|
order and widths.
|
||||||
|
|
||||||
Each group has a disclosure triangle. Expansion follows the typed ordered path,
|
Each group has a disclosure triangle. Expansion follows the typed ordered path,
|
||||||
not its label or page number. Parent collapse preserves child choices. Current
|
not its label or page number. Parent collapse preserves child choices. Current
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package de.neitzel.fx.control;
|
||||||
|
|
||||||
|
import javafx.scene.control.ButtonBase;
|
||||||
|
import javafx.scene.control.ContentDisplay;
|
||||||
|
import javafx.scene.control.Tooltip;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.scene.shape.SVGPath;
|
||||||
|
|
||||||
|
/** A button graphic that follows the control's text color and exposes a tooltip and accessible name. */
|
||||||
|
public final class ActionIcon {
|
||||||
|
private ActionIcon() {}
|
||||||
|
|
||||||
|
/** Installs an outlined icon drawn on a 16 by 16 coordinate grid. */
|
||||||
|
public static void install(ButtonBase button, String description, String path) {
|
||||||
|
var icon = new SVGPath();
|
||||||
|
icon.setContent(path);
|
||||||
|
icon.setFill(null);
|
||||||
|
icon.strokeProperty().bind(button.textFillProperty());
|
||||||
|
icon.setStrokeWidth(1.5);
|
||||||
|
icon.setStrokeLineCap(javafx.scene.shape.StrokeLineCap.ROUND);
|
||||||
|
icon.setStrokeLineJoin(javafx.scene.shape.StrokeLineJoin.ROUND);
|
||||||
|
var graphic = new StackPane(icon);
|
||||||
|
graphic.setMinSize(18, 18);
|
||||||
|
graphic.setPrefSize(18, 18);
|
||||||
|
graphic.setMaxSize(18, 18);
|
||||||
|
graphic.setMouseTransparent(true);
|
||||||
|
button.setGraphic(graphic);
|
||||||
|
button.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
|
||||||
|
button.setAccessibleText(description);
|
||||||
|
button.setTooltip(new Tooltip(description));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,8 +33,8 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
previous = pagingButton("Previous page", "M2 7 L14 0 V14 Z"),
|
previous = pagingButton("Previous page", "M2 7 L14 0 V14 Z"),
|
||||||
next = pagingButton("Next page", "M2 0 L14 7 L2 14 Z"),
|
next = pagingButton("Next page", "M2 0 L14 7 L2 14 Z"),
|
||||||
last = pagingButton("Last page", "M0 0 L12 7 L0 14 Z M14 0 H16 V14 H14 Z"),
|
last = pagingButton("Last page", "M0 0 L12 7 L0 14 Z M14 0 H16 V14 H14 Z"),
|
||||||
retry = new Button("Retry"),
|
retry = actionButton("Retry", "M2 8 A6 6 0 1 1 5 13 M2 3 V8 H7"),
|
||||||
refresh = new Button("Refresh");
|
refresh = actionButton("Refresh", "M14 7 A6 6 0 1 0 13 11 M14 2 V7 H9");
|
||||||
private final ComboBox<String> pageSize = new ComboBox<>();
|
private final ComboBox<String> pageSize = new ComboBox<>();
|
||||||
private GridQuery initial;
|
private GridQuery initial;
|
||||||
private List<ResultColumn> columnDefinitions;
|
private List<ResultColumn> columnDefinitions;
|
||||||
@@ -59,6 +59,8 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
private final Label activeFilters = new Label();
|
private final Label activeFilters = new Label();
|
||||||
private final Label interactionStatus = new Label();
|
private final Label interactionStatus = new Label();
|
||||||
private final MenuButton setupMenu = new MenuButton("Grid setup");
|
private final MenuButton setupMenu = new MenuButton("Grid setup");
|
||||||
|
private final MenuButton columnMenu = new MenuButton();
|
||||||
|
private final ReadOnlyLongWrapper columnVisibilityRevision = new ReadOnlyLongWrapper();
|
||||||
private final ReadOnlyLongWrapper committedRevision = new ReadOnlyLongWrapper();
|
private final ReadOnlyLongWrapper committedRevision = new ReadOnlyLongWrapper();
|
||||||
private List<String> defaultGrouping = List.of();
|
private List<String> defaultGrouping = List.of();
|
||||||
private GridSetup developerDefaults;
|
private GridSetup developerDefaults;
|
||||||
@@ -68,6 +70,12 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
private GridPersistenceAttachment<K, T> attachment;
|
private GridPersistenceAttachment<K, T> attachment;
|
||||||
private GridColumnSettings<K, T> columnSettings;
|
private GridColumnSettings<K, T> columnSettings;
|
||||||
|
|
||||||
|
private static Button actionButton(String description, String path) {
|
||||||
|
var button = new Button();
|
||||||
|
de.neitzel.fx.control.ActionIcon.install(button, description, path);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
private static Button pagingButton(String name, String path) {
|
private static Button pagingButton(String name, String path) {
|
||||||
var button = new Button();
|
var button = new Button();
|
||||||
var icon = new SVGPath();
|
var icon = new SVGPath();
|
||||||
@@ -272,7 +280,12 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
List.of(),
|
List.of(),
|
||||||
new PageRequest.Paged(
|
new PageRequest.Paged(
|
||||||
0, Math.min(50, source.capabilities().maximumPageSize())));
|
0, Math.min(50, source.capabilities().maximumPageSize())));
|
||||||
renderer = table.openResults(columns, rowFactory);
|
renderer = table.openResults(columns, rowFactory, columnMenu);
|
||||||
|
columnMenu.getStyleClass().add("data-grid-column-menu");
|
||||||
|
columnMenu.setAccessibleText("Column visibility");
|
||||||
|
columnMenu.setTooltip(new Tooltip("Column visibility"));
|
||||||
|
columnMenu.setOnShowing(event -> updateColumnMenu());
|
||||||
|
renderer.setHeaderMenuFactory(this::headerMenu);
|
||||||
renderer.setSelectionMode(getSelectionMode());
|
renderer.setSelectionMode(getSelectionMode());
|
||||||
selectedKeys.bind(renderer.selectedKeysProperty());
|
selectedKeys.bind(renderer.selectedKeysProperty());
|
||||||
selectedElements.bind(renderer.selectedElementsProperty());
|
selectedElements.bind(renderer.selectedElementsProperty());
|
||||||
@@ -343,9 +356,12 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
controls.getChildren().add(setupMenu);
|
controls.getChildren().add(setupMenu);
|
||||||
interactionStatus.setWrapText(true);
|
interactionStatus.setWrapText(true);
|
||||||
interactionStatus.getStyleClass().add("data-grid-interaction-status");
|
interactionStatus.getStyleClass().add("data-grid-interaction-status");
|
||||||
|
de.neitzel.fx.control.ActionIcon.install(setupMenu, "Grid setup",
|
||||||
|
"M2 4 H14 M2 8 H14 M2 12 H14 M5 2 V6 M11 6 V10 M7 10 V14");
|
||||||
var css = DataGrid.class.getResource("data-grid.css");
|
var css = DataGrid.class.getResource("data-grid.css");
|
||||||
if (css != null) getStylesheets().add(css.toExternalForm());
|
if (css != null) getStylesheets().add(css.toExternalForm());
|
||||||
Button clearActiveFilters = new Button("Clear filters");
|
Button clearActiveFilters = actionButton("Clear filters",
|
||||||
|
"M1 2 H15 L9 8 V14 L6 12 V8 Z M11 10 L15 14 M15 10 L11 14");
|
||||||
clearActiveFilters.setOnAction(e -> setFilters(List.of()));
|
clearActiveFilters.setOnAction(e -> setFilters(List.of()));
|
||||||
filterSummary.getChildren().addAll(activeFilters, clearActiveFilters);
|
filterSummary.getChildren().addAll(activeFilters, clearActiveFilters);
|
||||||
filterSummary.setVisible(false);
|
filterSummary.setVisible(false);
|
||||||
@@ -417,6 +433,66 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
renderer.setColumnOrder(ids);
|
renderer.setColumnOrder(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns whether this grid currently displays the column. */
|
||||||
|
public boolean isColumnVisible(String id) {
|
||||||
|
check();
|
||||||
|
return renderer.isColumnVisible(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shows or hides a column without fetching rows or changing the saved grid setup. */
|
||||||
|
public void setColumnVisible(String id, boolean visible) {
|
||||||
|
if (visible == isColumnVisible(id)) return;
|
||||||
|
closeFilter();
|
||||||
|
renderer.setColumnVisible(id, visible);
|
||||||
|
columnVisibilityRevision.set(columnVisibilityRevision.get() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Observes effective visibility changes, which are independent of saved grid setups. */
|
||||||
|
public ReadOnlyLongProperty columnVisibilityRevisionProperty() {
|
||||||
|
return columnVisibilityRevision.getReadOnlyProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateColumnMenu() {
|
||||||
|
columnMenu.getItems().setAll(renderer.columnOrder().stream().map(id -> {
|
||||||
|
CheckMenuItem item = new CheckMenuItem(renderer.columnHeader(id));
|
||||||
|
item.setSelected(isColumnVisible(id));
|
||||||
|
item.setOnAction(e -> setColumnVisible(id, item.isSelected()));
|
||||||
|
return item;
|
||||||
|
}).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ContextMenu headerMenu(String id, HBox cell) {
|
||||||
|
var menu = new ContextMenu(
|
||||||
|
menuItem("Sort ascending", () -> setSort(new SortKey(id, SortKey.Direction.ASCENDING))),
|
||||||
|
menuItem("Sort descending", () -> setSort(new SortKey(id, SortKey.Direction.DESCENDING))));
|
||||||
|
if (query().sort().stream().anyMatch(key -> key.columnId().equals(id)))
|
||||||
|
menu.getItems().add(menuItem("Clear sort", () -> setSort(null)));
|
||||||
|
if (filterColumns.containsKey(id)) {
|
||||||
|
var filterButton = cell.lookup(".filter-button");
|
||||||
|
menu.getItems().add(menuItem("Filter…", () -> openFilter(id, filterButton)));
|
||||||
|
}
|
||||||
|
if (renderer.canGroup(id)) {
|
||||||
|
boolean grouped = renderer.groupingColumns().contains(id);
|
||||||
|
menu.getItems().add(menuItem(grouped ? "Remove grouping" : "Group by column", () -> {
|
||||||
|
var nextGroups = new ArrayList<>(renderer.groupingColumns());
|
||||||
|
if (grouped) nextGroups.remove(id);
|
||||||
|
else if (!nextGroups.contains(id)) nextGroups.add(id);
|
||||||
|
setGroupingColumns(nextGroups);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
menu.getItems().addAll(
|
||||||
|
menuItem("Reset column width", () -> setColumnWidth(id, new ColumnWidth.Default())),
|
||||||
|
new SeparatorMenuItem(),
|
||||||
|
menuItem("Hide column", () -> setColumnVisible(id, false)));
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MenuItem menuItem(String text, Runnable action) {
|
||||||
|
var item = new MenuItem(text);
|
||||||
|
item.setOnAction(e -> action.run());
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
public double setColumnWidth(String id, ColumnWidth width) {
|
public double setColumnWidth(String id, ColumnWidth width) {
|
||||||
check();
|
check();
|
||||||
closeFilter();
|
closeFilter();
|
||||||
@@ -1252,6 +1328,7 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
if (attachment != null) attachment.close();
|
if (attachment != null) attachment.close();
|
||||||
closed = true;
|
closed = true;
|
||||||
|
columnMenu.hide();
|
||||||
closeFilter();
|
closeFilter();
|
||||||
declaration.close();
|
declaration.close();
|
||||||
if (coordinator != null) coordinator.close();
|
if (coordinator != null) coordinator.close();
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ final class ResultColumnSeparators extends Group {
|
|||||||
return decoration;
|
return decoration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean matchesColumnCount(int columns) {
|
||||||
|
return getChildren().size() == Math.max(0, columns - 1);
|
||||||
|
}
|
||||||
|
|
||||||
void position(double[] widths) {
|
void position(double[] widths) {
|
||||||
double x = 0;
|
double x = 0;
|
||||||
for (int i = 0; i < getChildren().size(); i++) {
|
for (int i = 0; i < getChildren().size(); i++) {
|
||||||
|
|||||||
@@ -343,13 +343,10 @@ final class ResultHeaderGestures implements AutoCloseable {
|
|||||||
headerViewport = pane;
|
headerViewport = pane;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (scroll == null
|
if (scroll == null || headerViewport == null || Double.isNaN(pointerX))
|
||||||
|| headerViewport == null
|
return;
|
||||||
|| Double.isNaN(pointerX)
|
var bounds = headerViewport.localToScene(headerViewport.getBoundsInLocal());
|
||||||
|| !headerViewport
|
if (!bounds.contains(pointerX, pointerY)) return;
|
||||||
.localToScene(headerViewport.getBoundsInLocal())
|
|
||||||
.contains(pointerX, pointerY)) return;
|
|
||||||
var bounds = scroll.localToScene(scroll.getViewportBounds());
|
|
||||||
double delta =
|
double delta =
|
||||||
pointerX < bounds.getMinX() + 30
|
pointerX < bounds.getMinX() + 30
|
||||||
? -.012
|
? -.012
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package de.neitzel.fx.view;
|
|||||||
|
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.beans.binding.DoubleBinding;
|
import javafx.beans.binding.DoubleBinding;
|
||||||
|
import javafx.beans.binding.ObjectBinding;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
@@ -9,29 +11,43 @@ import javafx.scene.layout.VBox;
|
|||||||
/** Makes equal normalized scroll values represent equal pixel offsets in queried results. */
|
/** Makes equal normalized scroll values represent equal pixel offsets in queried results. */
|
||||||
final class ResultScrollAlignment implements AutoCloseable {
|
final class ResultScrollAlignment implements AutoCloseable {
|
||||||
private final HBox header;
|
private final HBox header;
|
||||||
|
private final VBox body;
|
||||||
private final double originalMinimum;
|
private final double originalMinimum;
|
||||||
|
private final Insets originalPadding;
|
||||||
|
private final ObjectBinding<Insets> bodyPadding;
|
||||||
private final DoubleBinding minimum;
|
private final DoubleBinding minimum;
|
||||||
|
private final DoubleBinding viewportDifference;
|
||||||
|
|
||||||
ResultScrollAlignment(HBox header, VBox body, ScrollPane headerScroll, ScrollPane bodyScroll) {
|
ResultScrollAlignment(
|
||||||
|
HBox header, VBox body, ScrollPane headerScroll, ScrollPane bodyScroll,
|
||||||
|
boolean hasHeaderAccessory) {
|
||||||
this.header = header;
|
this.header = header;
|
||||||
|
this.body = body;
|
||||||
originalMinimum = header.getMinWidth();
|
originalMinimum = header.getMinWidth();
|
||||||
|
originalPadding = body.getPadding();
|
||||||
|
viewportDifference = Bindings.createDoubleBinding(
|
||||||
|
() -> headerScroll.getViewportBounds().getWidth()
|
||||||
|
- bodyScroll.getViewportBounds().getWidth(),
|
||||||
|
headerScroll.viewportBoundsProperty(), bodyScroll.viewportBoundsProperty());
|
||||||
|
// The fixed header menu can make the header viewport narrower. Add trailing body space
|
||||||
|
// so the last column can scroll fully into view in both viewports.
|
||||||
|
bodyPadding = hasHeaderAccessory ? Bindings.createObjectBinding(
|
||||||
|
() -> new Insets(originalPadding.getTop(),
|
||||||
|
originalPadding.getRight() + Math.max(0, -viewportDifference.get()),
|
||||||
|
originalPadding.getBottom(), originalPadding.getLeft()),
|
||||||
|
viewportDifference) : null;
|
||||||
|
if (bodyPadding != null) body.paddingProperty().bind(bodyPadding);
|
||||||
// A vertical body scrollbar narrows its viewport. Trailing row actions can also
|
// A vertical body scrollbar narrows its viewport. Trailing row actions can also
|
||||||
// make its content wider than the column headings. Reserve blank header space
|
// make its content wider than the column headings. Reserve blank header space
|
||||||
// so both scrollable extents match; the existing two-way hvalue binding then
|
// so both scrollable extents match; the existing two-way hvalue binding then
|
||||||
// moves every mapped field and heading by the same number of pixels.
|
// moves every mapped field and heading by the same number of pixels.
|
||||||
minimum =
|
minimum =
|
||||||
Bindings.createDoubleBinding(
|
Bindings.createDoubleBinding(
|
||||||
() ->
|
() -> body.getLayoutBounds().getWidth()
|
||||||
body.getLayoutBounds().getWidth()
|
+ (hasHeaderAccessory
|
||||||
+ Math.max(
|
? viewportDifference.get()
|
||||||
0,
|
: Math.max(0, viewportDifference.get())),
|
||||||
headerScroll.getViewportBounds().getWidth()
|
body.layoutBoundsProperty(), viewportDifference);
|
||||||
- bodyScroll
|
|
||||||
.getViewportBounds()
|
|
||||||
.getWidth()),
|
|
||||||
body.layoutBoundsProperty(),
|
|
||||||
headerScroll.viewportBoundsProperty(),
|
|
||||||
bodyScroll.viewportBoundsProperty());
|
|
||||||
header.minWidthProperty().bind(minimum);
|
header.minWidthProperty().bind(minimum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,5 +56,11 @@ final class ResultScrollAlignment implements AutoCloseable {
|
|||||||
header.minWidthProperty().unbind();
|
header.minWidthProperty().unbind();
|
||||||
header.setMinWidth(originalMinimum);
|
header.setMinWidth(originalMinimum);
|
||||||
minimum.dispose();
|
minimum.dispose();
|
||||||
|
if (bodyPadding != null) {
|
||||||
|
body.paddingProperty().unbind();
|
||||||
|
body.setPadding(originalPadding);
|
||||||
|
bodyPadding.dispose();
|
||||||
|
}
|
||||||
|
viewportDifference.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,13 +246,26 @@ public class Table extends VBox {
|
|||||||
*/
|
*/
|
||||||
public <K, T> TableResults<K, T> openResults(List<ResultColumn> definitions,
|
public <K, T> TableResults<K, T> openResults(List<ResultColumn> definitions,
|
||||||
java.util.function.Function<T, ResultRow> factory) {
|
java.util.function.Function<T, ResultRow> factory) {
|
||||||
|
return openResults(definitions, factory, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
<K, T> TableResults<K, T> openResults(List<ResultColumn> definitions,
|
||||||
|
java.util.function.Function<T, ResultRow> factory, Region headerAccessory) {
|
||||||
if (!javafx.application.Platform.isFxApplicationThread()) {
|
if (!javafx.application.Platform.isFxApplicationThread()) {
|
||||||
throw new IllegalStateException("Use the JavaFX application thread");
|
throw new IllegalStateException("Use the JavaFX application thread");
|
||||||
}
|
}
|
||||||
if (opened || resultMode) {
|
if (opened || resultMode) {
|
||||||
throw new IllegalStateException("Table is already open");
|
throw new IllegalStateException("Table is already open");
|
||||||
}
|
}
|
||||||
TableResults<K, T> renderer = new TableResults<>(header, body, List.copyOf(definitions), factory, headerScroll, scroll);
|
TableResults<K, T> renderer = new TableResults<>(
|
||||||
|
header, body, List.copyOf(definitions), factory, headerScroll, scroll, headerAccessory);
|
||||||
|
if (headerAccessory != null) {
|
||||||
|
getChildren().remove(headerScroll);
|
||||||
|
headerScroll.setMinWidth(0);
|
||||||
|
HBox.setHgrow(headerScroll, Priority.ALWAYS);
|
||||||
|
headerAccessory.setMaxHeight(Double.MAX_VALUE);
|
||||||
|
getChildren().addFirst(new HBox(headerScroll, headerAccessory));
|
||||||
|
}
|
||||||
// DataGrid grows this Table; let its viewport consume that height as well.
|
// DataGrid grows this Table; let its viewport consume that height as well.
|
||||||
VBox.setVgrow(scroll, Priority.ALWAYS);
|
VBox.setVgrow(scroll, Priority.ALWAYS);
|
||||||
resultMode = true;
|
resultMode = true;
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import javafx.collections.*;
|
|||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ContextMenu;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.Tooltip;
|
import javafx.scene.control.Tooltip;
|
||||||
|
import javafx.geometry.Side;
|
||||||
import javafx.scene.input.MouseButton;
|
import javafx.scene.input.MouseButton;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
@@ -20,6 +22,7 @@ import javafx.scene.layout.VBox;
|
|||||||
import javafx.scene.shape.SVGPath;
|
import javafx.scene.shape.SVGPath;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,10 +34,12 @@ import java.util.function.Function;
|
|||||||
public final class TableResults<K, T> implements AutoCloseable {
|
public final class TableResults<K, T> implements AutoCloseable {
|
||||||
private final HBox header;
|
private final HBox header;
|
||||||
private final VBox body;
|
private final VBox body;
|
||||||
|
private final Region headerAccessory;
|
||||||
private final Function<T, ResultRow> factory;
|
private final Function<T, ResultRow> factory;
|
||||||
private final Map<String, ResultColumn> definitions = new LinkedHashMap<>();
|
private final Map<String, ResultColumn> definitions = new LinkedHashMap<>();
|
||||||
private final Map<String, ColumnWidth> widths = new LinkedHashMap<>();
|
private final Map<String, ColumnWidth> widths = new LinkedHashMap<>();
|
||||||
private List<String> order;
|
private List<String> order;
|
||||||
|
private final Set<String> hiddenColumns = new HashSet<>();
|
||||||
private List<Entry<K, T>> entries = List.of();
|
private List<Entry<K, T>> entries = List.of();
|
||||||
private final ReadOnlyObjectWrapper<K> selectedKey = new ReadOnlyObjectWrapper<>();
|
private final ReadOnlyObjectWrapper<K> selectedKey = new ReadOnlyObjectWrapper<>();
|
||||||
private final ReadOnlyObjectWrapper<T> selectedElement = new ReadOnlyObjectWrapper<>();
|
private final ReadOnlyObjectWrapper<T> selectedElement = new ReadOnlyObjectWrapper<>();
|
||||||
@@ -56,6 +61,8 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
private List<SortKey> sortKeys = List.of();
|
private List<SortKey> sortKeys = List.of();
|
||||||
private java.util.function.BiConsumer<String, Node> filterRequest = (id, node) -> {};
|
private java.util.function.BiConsumer<String, Node> filterRequest = (id, node) -> {};
|
||||||
private java.util.function.Consumer<String> sortRequest = id -> {};
|
private java.util.function.Consumer<String> sortRequest = id -> {};
|
||||||
|
private BiFunction<String, HBox, ContextMenu> headerMenuFactory;
|
||||||
|
private ContextMenu headerMenu;
|
||||||
|
|
||||||
private List<GroupColumn<T>> groupColumns = List.of();
|
private List<GroupColumn<T>> groupColumns = List.of();
|
||||||
private List<String> grouping = List.of();
|
private List<String> grouping = List.of();
|
||||||
@@ -79,10 +86,12 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
List<ResultColumn> columns,
|
List<ResultColumn> columns,
|
||||||
Function<T, ResultRow> factory,
|
Function<T, ResultRow> factory,
|
||||||
javafx.scene.control.ScrollPane headerScroll,
|
javafx.scene.control.ScrollPane headerScroll,
|
||||||
javafx.scene.control.ScrollPane bodyScroll) {
|
javafx.scene.control.ScrollPane bodyScroll,
|
||||||
|
Region headerAccessory) {
|
||||||
requireFx();
|
requireFx();
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.body = body;
|
this.body = body;
|
||||||
|
this.headerAccessory = headerAccessory;
|
||||||
this.factory = Objects.requireNonNull(factory);
|
this.factory = Objects.requireNonNull(factory);
|
||||||
gestures = new ResultHeaderGestures(this, header, body);
|
gestures = new ResultHeaderGestures(this, header, body);
|
||||||
if (columns.isEmpty())
|
if (columns.isEmpty())
|
||||||
@@ -94,7 +103,8 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
order = List.copyOf(definitions.keySet());
|
order = List.copyOf(definitions.keySet());
|
||||||
validateOrder(order);
|
validateOrder(order);
|
||||||
scrollAlignment = new ResultScrollAlignment(header, body, headerScroll, bodyScroll);
|
scrollAlignment = new ResultScrollAlignment(
|
||||||
|
header, body, headerScroll, bodyScroll, headerAccessory != null);
|
||||||
drawHeader();
|
drawHeader();
|
||||||
body.setOnMouseClicked(e -> {
|
body.setOnMouseClicked(e -> {
|
||||||
if (e.getTarget() == body && e.getButton() == MouseButton.PRIMARY) select(null);
|
if (e.getTarget() == body && e.getButton() == MouseButton.PRIMARY) select(null);
|
||||||
@@ -105,7 +115,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
checkOpen();
|
checkOpen();
|
||||||
columnSeparators = true;
|
columnSeparators = true;
|
||||||
drawHeader();
|
drawHeader();
|
||||||
entries.forEach(e -> layoutRow(e.view()));
|
applyWidths(widths);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReadOnlyObjectProperty<K> selectedKeyProperty() {
|
public ReadOnlyObjectProperty<K> selectedKeyProperty() {
|
||||||
@@ -143,6 +153,27 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
return Map.copyOf(widths);
|
return Map.copyOf(widths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isColumnVisible(String id) {
|
||||||
|
checkOpen();
|
||||||
|
if (!definitions.containsKey(id)) throw new IllegalArgumentException("Unknown column: " + id);
|
||||||
|
return !hiddenColumns.contains(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setColumnVisible(String id, boolean visible) {
|
||||||
|
if (visible == isColumnVisible(id)) return;
|
||||||
|
Node focus = header.getScene() == null ? null : header.getScene().getFocusOwner();
|
||||||
|
boolean headerFocused = focus != null && descendant(header, focus);
|
||||||
|
if (visible) hiddenColumns.remove(id);
|
||||||
|
else hiddenColumns.add(id);
|
||||||
|
drawHeader();
|
||||||
|
applyWidths(widths);
|
||||||
|
if (headerFocused && headerAccessory != null) headerAccessory.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> visibleOrder(List<String> ordering) {
|
||||||
|
return ordering.stream().filter(id -> !hiddenColumns.contains(id)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
/** Marks retained rows unavailable without disabling header/query controls. */
|
/** Marks retained rows unavailable without disabling header/query controls. */
|
||||||
public void setRowsInteractive(boolean interactive) {
|
public void setRowsInteractive(boolean interactive) {
|
||||||
checkOpen();
|
checkOpen();
|
||||||
@@ -157,6 +188,11 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
sortRequest = Objects.requireNonNull(handler);
|
sortRequest = Objects.requireNonNull(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setHeaderMenuFactory(BiFunction<String, HBox, ContextMenu> factory) {
|
||||||
|
checkOpen();
|
||||||
|
headerMenuFactory = Objects.requireNonNull(factory);
|
||||||
|
}
|
||||||
|
|
||||||
/** Opt-in filter actions; clicking the icon never issues a sort request. */
|
/** Opt-in filter actions; clicking the icon never issues a sort request. */
|
||||||
public void setFilterActions(
|
public void setFilterActions(
|
||||||
Set<String> columns, java.util.function.BiConsumer<String, Node> handler) {
|
Set<String> columns, java.util.function.BiConsumer<String, Node> handler) {
|
||||||
@@ -196,8 +232,12 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String columnHeader(String id) {
|
||||||
|
return definitions.get(id).header();
|
||||||
|
}
|
||||||
|
|
||||||
private String headerText(String id) {
|
private String headerText(String id) {
|
||||||
return definitions.get(id).header()
|
return columnHeader(id)
|
||||||
+ sortKeys.stream()
|
+ sortKeys.stream()
|
||||||
.filter(k -> k.columnId().equals(id))
|
.filter(k -> k.columnId().equals(id))
|
||||||
.map(k -> k.direction() == SortKey.Direction.ASCENDING ? " ↑" : " ↓")
|
.map(k -> k.direction() == SortKey.Direction.ASCENDING ? " ↑" : " ↓")
|
||||||
@@ -337,7 +377,8 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
Math.clamp(e.value(), c.minimumWidth(), c.maximumWidth()))
|
Math.clamp(e.value(), c.minimumWidth(), c.maximumWidth()))
|
||||||
: width);
|
: width);
|
||||||
}
|
}
|
||||||
var nextHeader = headerNodes(nextOrder, preparedWidths);
|
var visibleOrder = visibleOrder(nextOrder);
|
||||||
|
var nextHeader = headerNodes(visibleOrder, preparedWidths);
|
||||||
result = List.copyOf(result);
|
result = List.copyOf(result);
|
||||||
Set<K> keys = new HashSet<>();
|
Set<K> keys = new HashSet<>();
|
||||||
for (var row : result)
|
for (var row : result)
|
||||||
@@ -365,7 +406,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
next.add(new Entry<>(row, view, click, key));
|
next.add(new Entry<>(row, view, click, key));
|
||||||
validateRow(view);
|
validateRow(view);
|
||||||
view.root().getStyleClass().add("result-row");
|
view.root().getStyleClass().add("result-row");
|
||||||
layoutRow(view, nextOrder, preparedWidths);
|
layoutRow(view, visibleOrder, preparedWidths);
|
||||||
view.root().addEventHandler(MouseEvent.MOUSE_CLICKED, click);
|
view.root().addEventHandler(MouseEvent.MOUSE_CLICKED, click);
|
||||||
view.root().setFocusTraversable(true);
|
view.root().setFocusTraversable(true);
|
||||||
view.root().addEventHandler(KeyEvent.KEY_PRESSED, key);
|
view.root().addEventHandler(KeyEvent.KEY_PRESSED, key);
|
||||||
@@ -379,7 +420,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
order = nextOrder;
|
order = nextOrder;
|
||||||
widths.clear();
|
widths.clear();
|
||||||
widths.putAll(preparedWidths);
|
widths.putAll(preparedWidths);
|
||||||
header.getChildren().setAll(nextHeader);
|
replaceHeader(nextHeader);
|
||||||
captured = nextCaptured;
|
captured = nextCaptured;
|
||||||
groupTree = nextTree;
|
groupTree = nextTree;
|
||||||
grouping = nextGrouping.columns();
|
grouping = nextGrouping.columns();
|
||||||
@@ -396,8 +437,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
validateOrder(ids);
|
validateOrder(ids);
|
||||||
order = ids;
|
order = ids;
|
||||||
drawHeader();
|
drawHeader();
|
||||||
entries.forEach(e -> layoutRow(e.view()));
|
applyWidths(widths);
|
||||||
resizeGroupHeadings();
|
|
||||||
layoutCommitted.run();
|
layoutCommitted.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +495,15 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void drawHeader() {
|
private void drawHeader() {
|
||||||
header.getChildren().setAll(headerNodes(order, widths));
|
replaceHeader(headerNodes(visibleOrder(order), widths));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void replaceHeader(List<Node> cells) {
|
||||||
|
if (headerMenu != null) {
|
||||||
|
headerMenu.hide();
|
||||||
|
headerMenu = null;
|
||||||
|
}
|
||||||
|
header.getChildren().setAll(cells);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Node> headerNodes(List<String> ordering, Map<String, ColumnWidth> sizes) {
|
private List<Node> headerNodes(List<String> ordering, Map<String, ColumnWidth> sizes) {
|
||||||
@@ -501,6 +549,14 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
if (columnSeparators && !id.equals(ordering.getLast()))
|
if (columnSeparators && !id.equals(ordering.getLast()))
|
||||||
cell.getChildren().add(ResultColumnSeparators.forHeader(cell));
|
cell.getChildren().add(ResultColumnSeparators.forHeader(cell));
|
||||||
gestures.header(cell, label, handle, id, () -> sortRequest.accept(id));
|
gestures.header(cell, label, handle, id, () -> sortRequest.accept(id));
|
||||||
|
cell.setOnContextMenuRequested(event -> {
|
||||||
|
if (headerMenuFactory == null) return;
|
||||||
|
if (headerMenu != null) headerMenu.hide();
|
||||||
|
headerMenu = headerMenuFactory.apply(id, cell);
|
||||||
|
if (event.isKeyboardTrigger()) headerMenu.show(cell, Side.BOTTOM, 0, 0);
|
||||||
|
else headerMenu.show(cell, event.getScreenX(), event.getScreenY());
|
||||||
|
event.consume();
|
||||||
|
});
|
||||||
size(cell, width(id, sizes));
|
size(cell, width(id, sizes));
|
||||||
nodes.add(cell);
|
nodes.add(cell);
|
||||||
}
|
}
|
||||||
@@ -513,10 +569,6 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
region.setMaxWidth(width);
|
region.setMaxWidth(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void layoutRow(ResultRow view) {
|
|
||||||
layoutRow(view, order, widths);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void layoutRow(ResultRow view, List<String> ordering, Map<String, ColumnWidth> sizes) {
|
private void layoutRow(ResultRow view, List<String> ordering, Map<String, ColumnWidth> sizes) {
|
||||||
Set<Region> fields = Collections.newSetFromMap(new IdentityHashMap<>());
|
Set<Region> fields = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||||
fields.addAll(view.fields().values());
|
fields.addAll(view.fields().values());
|
||||||
@@ -532,7 +584,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
else if (!fields.contains(child)) children.add(child);
|
else if (!fields.contains(child)) children.add(child);
|
||||||
}
|
}
|
||||||
if (columnSeparators) {
|
if (columnSeparators) {
|
||||||
if (separators == null)
|
if (separators == null || !separators.matchesColumnCount(ordering.size()))
|
||||||
separators = new ResultColumnSeparators(view.root(), ordering.size());
|
separators = new ResultColumnSeparators(view.root(), ordering.size());
|
||||||
separators.position(ordering.stream().mapToDouble(id -> width(id, sizes)).toArray());
|
separators.position(ordering.stream().mapToDouble(id -> width(id, sizes)).toArray());
|
||||||
children.add(separators);
|
children.add(separators);
|
||||||
@@ -543,7 +595,10 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
view.root().getScene() == null ? null : view.root().getScene().getFocusOwner();
|
view.root().getScene() == null ? null : view.root().getScene().getFocusOwner();
|
||||||
boolean restore = focus != null && descendant(view.root(), focus);
|
boolean restore = focus != null && descendant(view.root(), focus);
|
||||||
view.root().getChildren().setAll(children);
|
view.root().getChildren().setAll(children);
|
||||||
if (restore) focus.requestFocus();
|
if (restore) {
|
||||||
|
if (descendant(view.root(), focus)) focus.requestFocus();
|
||||||
|
else view.root().requestFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,6 +817,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
.getChildren()
|
.getChildren()
|
||||||
.getFirst()
|
.getFirst()
|
||||||
.requestFocus();
|
.requestFocus();
|
||||||
|
else if (headerAccessory != null) headerAccessory.requestFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resizeGroupHeadings();
|
resizeGroupHeadings();
|
||||||
@@ -862,8 +918,13 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void resizeGroupHeadings() {
|
private void resizeGroupHeadings() {
|
||||||
double total = order.stream().mapToDouble(this::width).sum();
|
resizeGroupHeadings(visibleOrder(order), widths);
|
||||||
disclosure.values().forEach(button -> size(button, total));
|
}
|
||||||
|
|
||||||
|
private void resizeGroupHeadings(List<String> visible, Map<String, ColumnWidth> sizes) {
|
||||||
|
double total = visible.stream().mapToDouble(id -> width(id, sizes)).sum();
|
||||||
|
disclosure.values().forEach(
|
||||||
|
button -> size(button, visible.isEmpty() ? Region.USE_COMPUTED_SIZE : total));
|
||||||
}
|
}
|
||||||
|
|
||||||
void previewWidth(String id, ColumnWidth value) {
|
void previewWidth(String id, ColumnWidth value) {
|
||||||
@@ -875,9 +936,9 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
private void applyWidths(Map<String, ColumnWidth> sizes) {
|
private void applyWidths(Map<String, ColumnWidth> sizes) {
|
||||||
for (Node node : header.getChildren())
|
for (Node node : header.getChildren())
|
||||||
size((Region) node, width((String) node.getUserData(), sizes));
|
size((Region) node, width((String) node.getUserData(), sizes));
|
||||||
entries.forEach(e -> layoutRow(e.view(), order, sizes));
|
var visible = visibleOrder(order);
|
||||||
double total = order.stream().mapToDouble(id -> width(id, sizes)).sum();
|
entries.forEach(e -> layoutRow(e.view(), visible, sizes));
|
||||||
disclosure.values().forEach(button -> size(button, total));
|
resizeGroupHeadings(visible, sizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void release(List<Entry<K, T>> retired) {
|
private void release(List<Entry<K, T>> retired) {
|
||||||
@@ -913,7 +974,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
var old = entries;
|
var old = entries;
|
||||||
entries = List.of();
|
entries = List.of();
|
||||||
body.getChildren().clear();
|
body.getChildren().clear();
|
||||||
header.getChildren().clear();
|
replaceHeader(List.of());
|
||||||
body.setOnMouseClicked(null);
|
body.setOnMouseClicked(null);
|
||||||
selectedKey.set(null);
|
selectedKey.set(null);
|
||||||
selectedElement.set(null);
|
selectedElement.set(null);
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
.grouping-chip { -fx-padding: 4 8; -fx-alignment: center-left; -fx-background-color: #e8eff7; -fx-border-color: #8a9eb5; -fx-cursor: open-hand; }
|
.grouping-chip { -fx-padding: 4 8; -fx-alignment: center-left; -fx-background-color: #e8eff7; -fx-border-color: #8a9eb5; -fx-cursor: open-hand; }
|
||||||
.data-grid .column-cell { -fx-alignment: center-left; -fx-min-height: 32; }
|
.data-grid .column-cell { -fx-alignment: center-left; -fx-min-height: 32; }
|
||||||
.data-grid .column-header { -fx-padding: 5 6; }
|
.data-grid .column-header { -fx-padding: 5 6; }
|
||||||
|
.data-grid .data-grid-column-menu, .data-grid .data-grid-column-menu > .label { -fx-padding: 0; }
|
||||||
|
.data-grid .data-grid-column-menu > .arrow-button { -fx-padding: 0 8; }
|
||||||
|
.neitzel-theme .data-grid .data-grid-column-menu:focused { -fx-border-color: -nl-focus; }
|
||||||
.data-grid .column-resize:hover { -fx-background-color: #3776b6; }
|
.data-grid .column-resize:hover { -fx-background-color: #3776b6; }
|
||||||
.group-heading { -fx-background-color: #e8eff7; -fx-text-fill: #182b3b; -fx-border-color: transparent transparent #b4c4d5 transparent; -fx-background-radius: 0; -fx-alignment: center-left; }
|
.group-heading { -fx-background-color: #e8eff7; -fx-text-fill: #182b3b; -fx-border-color: transparent transparent #b4c4d5 transparent; -fx-background-radius: 0; -fx-alignment: center-left; }
|
||||||
.group-heading:focused { -fx-border-color: #3776b6; -fx-border-width: 2; }
|
.group-heading:focused { -fx-border-color: #3776b6; -fx-border-width: 2; }
|
||||||
|
|||||||
@@ -5,9 +5,13 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
import de.neitzel.grid.*;
|
import de.neitzel.grid.*;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.input.ContextMenuEvent;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.Window;
|
||||||
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
@@ -95,6 +99,137 @@ class DataGridGroupingTest {
|
|||||||
return new GroupPath(List.of(new GroupPath.Segment("type", new FilterValue.Text(type))));
|
return new GroupPath(List.of(new GroupPath.Segment("type", new FilterValue.Text(type))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void headerMenusChangeVisibilityWithoutReplacingRowsOrLosingLayout() throws Exception {
|
||||||
|
var reads = new AtomicInteger();
|
||||||
|
var disposed = new AtomicInteger();
|
||||||
|
Map<Long, TextField> fields = new HashMap<>();
|
||||||
|
var grid = fx(() -> grid(reads, disposed, fields));
|
||||||
|
var stage = fx(Stage::new);
|
||||||
|
try {
|
||||||
|
fx(grid::loadAsync).toCompletableFuture().get(5, TimeUnit.SECONDS);
|
||||||
|
fx(() -> {
|
||||||
|
stage.setScene(grid.getScene());
|
||||||
|
stage.show();
|
||||||
|
grid.setExpanded(path("A"), true);
|
||||||
|
grid.setColumnOrder(List.of("status", "type"));
|
||||||
|
grid.setColumnWidth("type", new ColumnWidth.Explicit(235));
|
||||||
|
var editor = fields.get(1L);
|
||||||
|
editor.setText("unfinished draft");
|
||||||
|
var row = (HBox) editor.getParent();
|
||||||
|
assertSame(editor, row.getChildren().get(1));
|
||||||
|
var menu = (MenuButton) grid.lookup(".data-grid-column-menu");
|
||||||
|
var header = (HBox) grid.lookup(".column-header-row");
|
||||||
|
long visibility = grid.columnVisibilityRevisionProperty().get();
|
||||||
|
var context = showColumnContextMenu(header.getChildren().get(1), false);
|
||||||
|
context.getItems().getLast().fire();
|
||||||
|
assertEquals(++visibility, grid.columnVisibilityRevisionProperty().get());
|
||||||
|
grid.setColumnVisible("type", false);
|
||||||
|
assertEquals(visibility, grid.columnVisibilityRevisionProperty().get());
|
||||||
|
assertFalse(context.isShowing());
|
||||||
|
assertFalse(grid.isColumnVisible("type"));
|
||||||
|
assertNull(editor.getParent());
|
||||||
|
assertEquals(1, header.getChildren().size());
|
||||||
|
assertEquals(List.of("type"), grid.groupingColumns());
|
||||||
|
|
||||||
|
menu.show();
|
||||||
|
assertTrue(menu.isShowing());
|
||||||
|
var status = (CheckMenuItem) menu.getItems().getFirst();
|
||||||
|
var type = (CheckMenuItem) menu.getItems().getLast();
|
||||||
|
assertEquals("Status", status.getText());
|
||||||
|
assertTrue(status.isSelected());
|
||||||
|
assertEquals("Type", type.getText());
|
||||||
|
assertFalse(type.isSelected());
|
||||||
|
status.setSelected(false);
|
||||||
|
status.fire();
|
||||||
|
menu.hide();
|
||||||
|
assertTrue(header.getChildren().isEmpty());
|
||||||
|
assertTrue(menu.isVisible());
|
||||||
|
menu.show();
|
||||||
|
type = (CheckMenuItem) menu.getItems().getLast();
|
||||||
|
type.setSelected(true);
|
||||||
|
type.fire();
|
||||||
|
menu.hide();
|
||||||
|
assertEquals(visibility + 2, grid.columnVisibilityRevisionProperty().get());
|
||||||
|
assertSame(editor, row.getChildren().getFirst());
|
||||||
|
assertEquals(235, editor.getPrefWidth());
|
||||||
|
assertEquals("unfinished draft", editor.getText());
|
||||||
|
assertEquals(0, disposed.get());
|
||||||
|
assertEquals(1, reads.get());
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
fx(() -> {
|
||||||
|
var header = (HBox) grid.lookup(".column-header-row");
|
||||||
|
var context = showColumnContextMenu(header.getChildren().getFirst(), true);
|
||||||
|
context.getItems().stream()
|
||||||
|
.filter(item -> "Sort descending".equals(item.getText()))
|
||||||
|
.findFirst().orElseThrow().fire();
|
||||||
|
context.hide();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
DataGridTest.drain();
|
||||||
|
fx(() -> {
|
||||||
|
assertEquals(List.of(new SortKey("type", SortKey.Direction.DESCENDING)),
|
||||||
|
grid.stateProperty().get().displayed().sort());
|
||||||
|
assertFalse(grid.isColumnVisible("status"));
|
||||||
|
assertTrue(grid.isColumnVisible("type"));
|
||||||
|
assertEquals(1, ((HBox) grid.lookup(".column-header-row")).getChildren().size());
|
||||||
|
assertEquals(2, reads.get());
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
fx(() -> {
|
||||||
|
grid.close();
|
||||||
|
stage.close();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ContextMenu showColumnContextMenu(Node cell, boolean fromKeyboard) {
|
||||||
|
var point = cell.localToScreen(0, 0);
|
||||||
|
cell.fireEvent(new ContextMenuEvent(ContextMenuEvent.CONTEXT_MENU_REQUESTED,
|
||||||
|
0, 0, point.getX(), point.getY(), fromKeyboard, null));
|
||||||
|
return Window.getWindows().stream()
|
||||||
|
.filter(ContextMenu.class::isInstance).map(ContextMenu.class::cast)
|
||||||
|
.filter(ContextMenu::isShowing).findFirst().orElseThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectorStaysFixedAndHeadersAlignAtTheRightScrollEdge() throws Exception {
|
||||||
|
var fields = new HashMap<Long, TextField>();
|
||||||
|
var grid = fx(() -> grid(new AtomicInteger(), new AtomicInteger(), fields));
|
||||||
|
try {
|
||||||
|
fx(grid::loadAsync).toCompletableFuture().get(5, TimeUnit.SECONDS);
|
||||||
|
fx(() -> {
|
||||||
|
grid.setExpanded(path("A"), true);
|
||||||
|
grid.setColumnWidth("type", new ColumnWidth.Explicit(400));
|
||||||
|
grid.setColumnWidth("status", new ColumnWidth.Explicit(400));
|
||||||
|
var root = grid.getScene().getRoot();
|
||||||
|
root.resize(640, 500);
|
||||||
|
root.layout();
|
||||||
|
var menu = grid.lookup(".data-grid-column-menu");
|
||||||
|
double menuX = menu.localToScene(0, 0).getX();
|
||||||
|
var scroll = (ScrollPane) grid.lookup(".table-scroll");
|
||||||
|
var header = (HBox) grid.lookup(".column-header-row");
|
||||||
|
scroll.setHvalue(1);
|
||||||
|
root.layout();
|
||||||
|
assertEquals(menuX, menu.localToScene(0, 0).getX(), .5);
|
||||||
|
var type = fields.get(1L);
|
||||||
|
assertEquals(type.localToScene(0, 0).getX(),
|
||||||
|
header.getChildren().getFirst().localToScene(0, 0).getX(), 1);
|
||||||
|
var last = header.getChildren().getLast();
|
||||||
|
assertEquals(menuX, last.localToScene(last.getBoundsInLocal()).getMaxX(), 1);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
fx(() -> {
|
||||||
|
grid.close();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void presentationChangesPreserveComponentsDraftsAndHiddenSelectionWithoutQueries()
|
void presentationChangesPreserveComponentsDraftsAndHiddenSelectionWithoutQueries()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|||||||
@@ -326,7 +326,10 @@ class DataGridNativeInteractionTest {
|
|||||||
ScrollPane scroll = fx(() -> (ScrollPane) grid.lookup(".table-scroll"));
|
ScrollPane scroll = fx(() -> (ScrollPane) grid.lookup(".table-scroll"));
|
||||||
var original = order();
|
var original = order();
|
||||||
begin(fx(() -> label("name")));
|
begin(fx(() -> label("name")));
|
||||||
Bounds viewport = fx(() -> scroll.localToScreen(scroll.getViewportBounds()));
|
Bounds viewport = fx(() -> {
|
||||||
|
var headerScroll = grid.lookup(".table-header-scroll");
|
||||||
|
return headerScroll.localToScreen(headerScroll.getBoundsInLocal());
|
||||||
|
});
|
||||||
move(new Point2D(viewport.getMaxX() - 10, point(fx(() -> header("type")), .5, .5).getY()));
|
move(new Point2D(viewport.getMaxX() - 10, point(fx(() -> header("type")), .5, .5).getY()));
|
||||||
waitFor(() -> scroll.getHvalue() > .1, "Native edge hover scrolls");
|
waitFor(() -> scroll.getHvalue() > .1, "Native edge hover scrolls");
|
||||||
capture("edge-scroll");
|
capture("edge-scroll");
|
||||||
|
|||||||
Reference in New Issue
Block a user