3.0 KiB
MVVM content and local/global bars
The docking API accepts an ordinary Node. This example passes the root of one
LoadedView to a Dockable; the manager never loads that View again. Its Note
JavaBean, ViewModel, TextArea, local toolbar and local status bar remain the same
objects when the tab moves, floats or returns. A second editor uses a plain
TextArea without a ViewModel.
Build from the repository root with Java 25, without replacing installed runtime artifacts used by the Designer:
./mvnw -pl fx-example -am package
java --enable-native-access=ALL-UNNAMED \
-cp 'fx-example/target/classes:fx/target/classes:fx-example/target/libs/*' \
de.neitzel.fx.example.docking.mvvm.MvvmDockingMain
In the example:
- Edit Notes. Its tab title gains an asterisk and the local character count changes.
- Choose Move Notes to tools, Float Notes, then Return Notes. The local Clear note button and status bar travel with the editor; the global command and status bars stay in the main window.
- While Notes is floating, click Checkpoint active in the main window. Notes keeps its command target when focus enters that toolbar. The command records a checkpoint in memory and clears the asterisk; it does not save a file.
- Select Plain editor. The checkpoint command is disabled for this content, and the global status identifies the newly active Dockable.
- Close Notes with its tab close button to run the application's close hook.
MvvmEditor.fxml declares a bidirectional DirectBinding between the TextArea and
the Note's text attribute. Application updates use LoadedView.property("text");
calling a JavaBean setter directly does not notify an already loaded ViewModel.
MvvmEditor binds the Dockable title and local status to presentation properties.
MvvmDockingWorkspace binds the global command availability and status to
activeDockableProperty(). These are application bindings, not a docking-specific
MVVM service.
The application adapter owns its change listener and derived bindings. Its
onClosed and onDiscarded hooks release those resources explicitly. Moves,
collapse and veto do not run those hooks. A rejected factory-created editor is
discarded; rejection of a directly supplied Dockable leaves cleanup to its caller.
This does not dispose the LoadedView or evict the runtime's strong Model-to-ViewModel
identity cache. See the MVVM lifetime contract.
MvvmDockingTest loads the actual example FXML and checks model/property/control
edits before and after moves, object identity, bar ownership, global toolbar
focus and resource hooks. Its Scene-focus assertions complement the separately
qualified native keyboard transfer tests;
this integration test does not claim to inject native keystrokes.
For entirely independent docking and bars without initializing MVVM or injection, use the plain docking example and standalone bars example.