Complete multiwindow restore, coordinated shutdown and keyboard docking

This commit is contained in:
2026-11-16 00:54:10 +01:00
parent 853c6c0115
commit 485451de26
55 changed files with 3624 additions and 178 deletions
+3 -2
View File
@@ -95,5 +95,6 @@ Append `fxml` to the launch command for the FXML screen. The classpath separator
shown is for macOS/Linux; use `;` on Windows. A graphical desktop session is
required. The launch class is ordinary Java and delegates to the Application.
Dockable-owned bars and optional MVVM bindings are a later integration step;
the standalone controls already support ordinary JavaFX property bindings.
The [MVVM docking editor](../../fx-example/docs/docking-mvvm.md) demonstrates
Dockable-owned bars and optional MVVM bindings alongside a plain JavaFX editor.
The standalone controls also support ordinary JavaFX property bindings.
+151
View File
@@ -0,0 +1,151 @@
# Accessible names and translated docking actions
A Dockable with a visible title uses that title as its accessible tab name.
For an icon-only tab, supply an application name:
```java
Dockable project = new Dockable(new DockableId("project"), projectView);
project.setIcon(projectIcon);
project.setAccessibleName("Project files");
```
`accessibleNameProperty()` is bindable. It names an icon-only tab, whose title
is empty or blank; it does not replace the spoken name of a visibly titled tab.
The application title and original icon remain unchanged when the tab moves or
floats. JavaFX exposes the accessible name as the header's text attribute while
the default stylesheet displays only its graphic. An application supplying an
icon-only tab must supply a meaningful name; an unnamed icon has no useful
spoken label.
## Translations and placement failures
Set `DockingOptions.resourceBundle` before attaching the manager. Its String
entries are captured at attachment, so replacing the options bundle afterward
does not alter an existing manager. Unspecified built-in keys use the library's
English defaults. The tab header's close button also uses `dock.action.close`
as its accessible action name, including after a transfer into a floating window.
Action keys include `dock.action.move`, `split`, `close`,
`float`, `return`, and `pin` with the same `dock.action.` prefix. Direction keys
are `dock.side.TOP`, `RIGHT`, `BOTTOM`, and `LEFT` with `dock.side.` as the prefix.
Placement rules can attach an application message key without losing technical
diagnostics:
```java
DockFailure failure = new DockFailure(DockFailure.Code.PLACEMENT_REJECTED,
dockableId, "Workspace policy prohibits this destination", cause,
"workspace.destination.locked");
String visibleText = manager.describeFailure(failure);
```
The built-in context menus use the same `describeFailure` method as application
commands. An available application key wins. A missing application key falls
back to the failure code's default text (`dock.failure.` followed by the enum
name), not the technical diagnostic string. Code, key, diagnostic message and
cause remain available unchanged on the failure. Existing failures without a
key retain their supplied message unless the bundle overrides the code text.
`dock.action.unavailable` and `dock.action.noChange` are MessageFormat patterns.
The former accepts the action name and reason; the latter accepts the action
name. Keep those placeholders in translations.
## Application styles
A DockPane installs the library's scoped `docking.css` before existing Scene
stylesheets. Add your application theme to the Scene as usual. Configure a
floating window's stylesheets through `floatingWindowCustomizer` when the same
theme should apply there. The floating drag-preview popup inherits its owner's
Scene styles; it does not open a separate unthemed application window.
The tab-header hook is `.dock-tab-header`. An icon-only header additionally has
`.dock-icon-only`; keep its graphic-only content display if the visible header
should remain an icon. `.dock-drop-indicator` styles the in-window preview;
its `:no-change` pseudo-class identifies a drop which retains the placement.
The outside-window preview uses `.dock-floating-preview-frame` for fill/stroke
and `.dock-floating-preview-label` for the action label.
```css
.dock-tab-header { -fx-background-color: #dce8f1; }
.dock-drop-indicator { -fx-fill: rgba(30, 100, 180, 0.2); -fx-stroke: #1e64b4; }
.dock-floating-preview-frame { -fx-fill: rgba(30, 100, 180, 0.2); -fx-stroke: #1e64b4; }
```
The application retains control over color contrast and focus visibility when
replacing JavaFX's control styles.
`.dock-divider` styles split dividers from their first layout, and
`.dock-area-divider` styles the draggable boundary of an outer area.
`.dock-edge-area` is the outer area container. `.dock-group` is its TabPane;
`.dock-group:collapsed` identifies a closed rail. `.dock-group-surface` is the
space reserved for a group, and `.dock-overlay-layer` contains overlay groups.
These hooks are available in both main and floating DockPanes. Default divider
colors use JavaFX's looked-up theme colors, so replacing the application's base
palette also affects them.
## Keyboard commands
Focus the group's TabPane or one of its tab headers, then press **Shift+F10**
or the keyboard's **Context Menu** key. Arrow keys select actions and navigate
Move/Split submenus; Enter executes the highlighted enabled action. Move,
Split, Float, Return, Pin and Close use the manager's normal placement rules and
close consent. A successful transfer restores the content focus and keeps its
selection. Pinning and a vetoed Close return focus to the surviving content.
If the user activates another Dockable while asynchronous consent is pending,
a later veto preserves that newer focus choice.
An editor's own keyboard context menu remains the editor's responsibility.
## Runnable exercise
Launch `de.neitzel.fx.example.docking.KeyboardThemeDockingMain` from `fx-example`.
It provides a shared application theme, a named icon-only Project tab and
German docking action labels. **Focus active tab strip** places focus at the
keyboard entry point; then use Shift+F10, arrows and Enter.
- Float Notes and immediately type over the selected `cd` in `abcdef`.
Return it through the same menu and continue typing at its caret.
- Toggle **Block floating**. Compare **Check Float** with the disabled Float
menu item. Toggle **Missing translation key** to see the failure-code fallback.
- Close Notes with **Allow Notes to close** unchecked to exercise a veto, then
enable it and repeat to close the tab.
- Use the Project menu to pin/unpin its whole group. Its main-window-only flag
keeps Float unavailable. Drag another tab to inspect the themed preview and
split/outer dividers in both window types.
The native keyboard qualification uses the public `javafx.scene.robot.Robot`
for the real Shift+F10 chord and `java.awt.Robot` for arrow navigation, Enter
and typing. It selects actions
by their focused accessible names, then types `1` and `2` without repairing
content focus: `abcdef` with
`cd` selected becomes `ab1ef`, then `ab12ef`. Qualification on **2026-11-16**
used **macOS 27.2, Java 25 (25.0.5.0.3), and JavaFX 27.0.1**. The menu closes
before its workflow transfers focus, so a
later popup auto-hide cannot restore focus to a retired floating owner.
`NativeKeyboardDockingTest` permanently uses `@RepeatedTest(3)`: all three
independent executions must pass. Run this opt-in test from the NeitzelLib root
only with an exclusive desktop; other JavaFX tests or
manual app switching can take native focus:
```sh
./mvnw -pl fx -am -DskipVersions=true -Dversions.skip=true \
-Dtest=NativeKeyboardDockingTest \
-Dneitzellib.nativeKeyboardTest=true \
-Dsurefire.failIfNoSpecifiedTests=false test
```
`KeyboardDockActionsTest`, `AccessibleDockTabsTest`, `DockingLocalizationTest`
and `DockingThemeTest` exercise the public controls/API without native input.
The accessible-attribute checks verify JavaFX's exposed names, not a complete
screen-reader audit on every operating system.
During qualification, AWT sometimes delivered F10 without the held Shift flag
on this macOS/JDK combination; the public JavaFX event trace exposed that
missing modifier before the framework handled it. The test uses the public
[JavaFX Robot](https://openjfx.io/javadoc/27/javafx.graphics/javafx/scene/robot/Robot.html)
for the chord. Its [macOS backend](https://raw.githubusercontent.com/openjdk/jfx/jfx27/modules/javafx.graphics/src/main/native-glass/mac/GlassRobot.m)
posts native accessibility keyboard events, whereas the
[JDK 25 AWT backend](https://raw.githubusercontent.com/openjdk/jdk/jdk-25-ga/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m)
creates CoreGraphics keyboard events from HID source state. This changes only
the test driver; the framework still requires an actual Shift+F10 event. Three
independent repetitions must each complete both transfers and exact text
assertions. They are not retries after a failure.
+8 -5
View File
@@ -25,8 +25,9 @@ The `CloseDockingMain` launcher in the example module shows a pending close
without a nested event loop. Choose Close Notes, then Keep open and continue
editing. Request close again and choose Allow close. Until that decision, Notes
remains open; after approval its resource callback runs. The same demonstration
works through the tab's close control. Main-window shutdown is added by the
later lifecycle slices; this example demonstrates individual tab consent.
works through the tab's close control. This example demonstrates individual tab
consent; [main-window shutdown](docking-shutdown.md) adds complete-workspace
consent, pre-close saving and manager replacement.
## Closing a floating window
@@ -48,8 +49,9 @@ layout is published once. Then every `onClosed` callback runs, even if an earlie
cleanup fails. `Closed.cleanupFailures()` reports those failures. The scope stays
observable until cleanup finishes. Unknown/already closed floating IDs return
`NoChange`; the main-window ID is rejected by this floating-only entry point.
Main-window and manager shutdown, including the shutdown snapshot callback,
belong to the later shutdown slices.
Main-window and manager shutdown use the same consent and cleanup guarantees;
the [shutdown guide](docking-shutdown.md) describes their snapshot callback and
ownership modes.
The example launcher is
`de.neitzel.fx.example.docking.FloatingCloseDockingMain`. It creates First and
@@ -68,4 +70,5 @@ are in-memory demonstration snapshots in the log, not filesystem writes.
The floating window's native close control follows the same sequence.
The demo's main Stage is only a control panel; closing it hides its demonstration
windows. This is separate from the future application-wide shutdown protocol.
windows. For an application-wide Quit command, use the
[shutdown workflow](docking-shutdown.md).
+140
View File
@@ -0,0 +1,140 @@
# Quit, save and replace a docking workspace
`requestMainWindowClose()` asks every Dockable in the manager, including contents
in floating windows and collapsed groups. Every close check runs even if an
earlier one vetoes. Nothing closes until all checks allow the operation. A veto
returns `CloseResult.Vetoed` and skips the shutdown-save callback.
Configure `DockingOptions.beforeShutdown` before attaching the manager. After
unanimous consent, the callback receives a `ShutdownRequest` with the complete
immutable pre-close `LayoutSnapshot` and a `ShutdownReason`: `MAIN_WINDOW` or
`MANAGER_ONLY`. Application document saving still belongs to the application and
its close checks; the snapshot contains arrangement data, not editor text.
```java
DockingOptions options = new DockingOptions();
options.setBeforeShutdown(request -> saveLayoutWithRetry(request.snapshot()));
DockingManager manager = DockingManager.attach(stage, pane, options);
```
Here `saveLayoutWithRetry` is an application function returning a
`CompletionStage<ShutdownDecision>`. Keep that stage pending while saving or
retrying. The manager leaves all contents and windows open and holds the close
scope throughout that wait. Complete with `PROCEED` after a successful save, or
`CANCEL` to keep the workspace open. Throwing from the callback or completing its
stage exceptionally returns `Rejected` with `SHUTDOWN_CALLBACK_FAILED` and the
original cause; it does not close contents. The callback runs on the JavaFX
thread, and the returned stage may complete on a worker thread.
After `PROCEED`, the manager detaches contents and calls every `onClosed` callback.
Cleanup failures are reported in `Closed.cleanupFailures()` and do not turn an
already completed close into a rollback. The close scope remains active through
resource cleanup.
## Main-window ownership
The default `MainWindowCloseMode.AUTOMATIC` connects the Stage's close control to
the manager and hides the main Stage only after a successful main-window close.
Route an application's Quit command through `requestMainWindowClose()` as well.
With `APPLICATION_COORDINATED`, the application owns its close-request handler
and decides when to hide the main Stage after `Closed`. Consume the close event
while consent and saving are pending:
```java
stage.setOnCloseRequest(event -> {
event.consume();
manager.requestMainWindowClose().thenAccept(result -> {
if (result instanceof CloseResult.Closed) stage.hide();
});
});
```
Choose the mode before `attach`; changing the original options afterward does
not change the attached manager.
## Replacing the embedded workspace
`requestManagerClose()` uses the same checks and save workflow with reason
`MANAGER_ONLY`. On success it closes Dockables and floating windows, removes the
manager's handlers and releases the pane and Stage for another attachment. The
main Stage stays open. A veto, cancellation or failed save leaves the current
manager usable.
```java
manager.requestManagerClose().thenAccept(result -> {
if (result instanceof CloseResult.Closed) {
DockingManager replacement = DockingManager.attach(stage, pane, nextOptions);
openNewWorkspaceContents(replacement);
}
});
```
The replacement application creates or loads new contents. Use
[`resetLayout()`](../../fx-example/docs/docking-reset.md) when the intention is to
rearrange existing editors while retaining their Nodes and unsaved text.
## Quit during an existing floating-window close
A main-window request waits behind an already running floating-window close.
If the floating close succeeds, Quit asks only the remaining Dockables and then
captures their full pre-close snapshot. If it vetoes or fails, the waiting Quit
adopts that result without starting new checks or saving. A later explicit Quit
starts fresh checks. Repeated requests for the same running workflow share its
answer rather than invoking another application prompt.
The example makes this sequence visible:
1. Select **Delay Preview window consent** and click **Close Preview window**.
Preview stays open while its one consent answer is pending.
2. Click **Quit workspace**. The status shows that Quit is waiting; Notes and
Project have not been asked and no snapshot has been saved.
3. **Allow Preview** closes that independently approved window, then Quit asks
Notes and Project and waits at the normal save controls. The snapshot now
contains their one remaining main window.
4. Alternatively, **Veto Preview** leaves all three contents open and ends the
waiting Quit with the same veto. Clicking **Quit workspace** again performs
fresh checks and reaches the two-window save workflow.
The asynchronous consent controls remain usable while Quit waits. The public
scope property continues to describe the running floating close until the queue
can advance; a pending global save then owns the manager-wide scope.
## Runnable Quit/Replace example
`ShutdownDockingMain` loads `ShutdownDocking.fxml`: Notes occupies the center,
Project starts collapsed on the left, and Preview is floating. The example uses
ordinary JavaFX without MVVM.
1. Select **Preview vetoes last**, then **Replace workspace**. The log shows all
three checks, no snapshot callback and no released contents.
2. Clear the veto and request **Quit workspace** or **Replace workspace**. The
application displays the pre-close reason and the two-window snapshot.
3. **Retry save** fails while **Simulate save failure** is selected. The same
pending request retains every editor. Clear that checkbox and retry, or use
**Save successfully**, to complete with `PROCEED`.
4. **Cancel shutdown**, **Fail asynchronously** and **Throw before saving** show
the distinct canceled and rejected paths without losing the current editors.
5. **Replace workspace** followed by successful saving attaches fresh contents
to the same DockPane. **Next workspace** selects the ownership mode captured
by that new attachment. In application-owned mode, a successful Quit leaves
**Close application window** available for the caller's final action.
The example stores the saved snapshot in application-owned memory and deliberately
simulates failures; it performs no disk I/O. Connect the same callback to your
storage implementation for a real application.
After building local artifacts, launch from the NeitzelLib root:
```bash
java -cp 'fx-example/target/classes:fx-example/target/libs/*' \
de.neitzel.fx.example.docking.ShutdownDockingMain
```
The public workflow tests exercise consent and save ordering, pending saves,
both ownership modes, cleanup, captured options and reattachment. Four example
integration cases drive the actual Java/FXML controls through veto, retry,
cancellation, failures, replacement, both main-close ownership modes and queued
Quit after delayed floating consent. The queue cases use ordinary JavaFX turns
to verify callback counts, retained editor identity and fresh checks after a
veto. All four example scenarios pass without failures, errors or skips.
+52 -4
View File
@@ -50,10 +50,27 @@ adopts it. Contents belonging to this or another live manager receive neither
`onDiscarded` nor `onClosed` on that rejection. Fresh, unused prepared contents
remain subject to the discard contract.
This milestone restores snapshots containing the main window. Floating-window
data is captured, but restoring floating hosts currently returns
`UNSUPPORTED_SNAPSHOT_FEATURE` before invoking the resolver; ticket 14 adds that
capability. Partial restoration for missing IDs is supplied by ticket 13.
Restore includes the main window and floating hosts with their saved return
destinations. The same window customizer configures new and restored hosts.
Prepared floating windows remain hidden until the main Stage is shown; failed
preparation never shows them. Customizers and placement checks finish before the
layout is installed.
Floating bounds outside the available displays are fitted to a current screen,
preserving the saved size as far as it fits. Return uses the saved main-window
destination, including persistent groups hidden while empty.
`DockableResolution.Missing` skips that identity and reports it in
`RestoreResult.Applied.missingIds()`. Empty split branches dissolve while stable
area aliases remain available; configured persistent empty side groups survive.
Available contents are checked against the application's current placement rule.
If a saved destination is rejected, restore tries the explicitly configured
`DockingOptions.fallbackTarget`, such as `DockTarget.area("primary")`. It does not
silently choose an arbitrary group. If any available content has no eligible
destination, the entire restore is rejected with that ID and all freshly prepared
contents are discarded; the live fallback layout remains unchanged.
An available Dockable that has become `mainWindowOnly` uses an explicitly
configured main-window fallback. Floating hosts emptied by Missing or fallback
are omitted entirely, including their customizer calls.
Use [live reset](../../fx-example/docs/docking-reset.md) to rearrange already open
contents without replacing their Nodes or losing their unsaved state.
@@ -82,6 +99,37 @@ java --enable-native-access=ALL-UNNAMED \
prepared and discarded content counts, and separate cleanup diagnostics.
5. Enable **Simulate cleanup failure** and repeat the failed load to see cleanup
diagnostics alongside the unchanged primary failure.
6. Choose **Restore without Preview/Project**. The status names both missing IDs;
the nested Preview split dissolves and the persistent empty Project side target
remains. The original workspace and its unsaved text remain open.
7. Choose **Restore with changed rule**. In the supplied starting arrangement,
Project is no longer permitted in the tools group and joins Notes in the
configured editor fallback, `primary`. The status names that fallback.
8. Choose **Reject Project placement**. Project is rejected at both its saved
destination and the fallback. The new window retains its empty starting layout;
the status identifies Project and reports all four freshly prepared contents
discarded. The original workspace remains untouched.
9. Choose **Prepare floating snapshot**. Preview and Project become two floating
windows; Project's persistent side target hides while empty. The captured
snapshot includes their return destinations.
10. Choose **Restore saved layout**. A fresh main window and two floating hosts
appear. The status reports zero floating windows visible before main-window
display and two afterward. Source and restored hosts use the same custom title.
11. Choose **Restore off-screen windows**. This changes only the saved floating
positions to simulate unavailable monitors. The new hosts fit the available
displays. In the new main window, **Return Project** brings the same content
back to its preserved target and removes its empty floating host.
12. Choose **Restore partial floating**. Preview is missing; Project now requires
the main window and uses the configured editor fallback. Only the new main
window appears, with three contents. No empty floating hosts are created.
13. Choose **Abort floating customizer**. The second floating-window customizer
throws. Neither prepared floating host appears, the new main window retains
its empty fallback, and all four prepared contents are discarded.
The display and startup checks run against actual JavaFX windows on the current
macOS desktop. Off-screen saved bounds simulate monitor changes; physically
disconnecting monitors and Windows/Linux desktop startup have not been qualified
by these example tests.
The example's **Capture layout** command saves layout data only. Reloaded document
text comes from its application source; document persistence is a separate concern.
+5 -2
View File
@@ -41,8 +41,11 @@ The content instance remains owned by the application. A supplied
the previously focused descendant. See [split groups](docking-splits.md) for
nested layouts and resizing, [group presentation](docking-groups.md) for collapse
and atomic configuration, [overlay groups](docking-overlays.md) for pinning,
and [close consent](docking-close.md) for
asynchronous close checks. Restoration is supplied by a later slice.
and [close consent](docking-close.md) for asynchronous close checks.
[Snapshot restoration](docking-snapshots.md) prepares fresh contents for an empty
manager; [live reset](../../fx-example/docs/docking-reset.md) retains existing
editors. [Shutdown and replacement](docking-shutdown.md) cover saving before
Quit and attaching a new manager to the same host.
## Move and check placement