Separate JavaFX loading from the Neitzel injection container
This commit is contained in:
+23
-19
@@ -8,14 +8,14 @@ NeitzelLib creates that presentation layer at runtime. You can subclass it for a
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
App[Application: Model + ApplicationContext] --> Loader[ViewLoader]
|
||||
App[Application: Model + ViewDependencies] --> Loader[ViewLoader]
|
||||
FXML[FXML: controls and binding declarations] --> Loader
|
||||
Loader --> View[LoadedView: JavaFX root]
|
||||
Loader --> VM[Runtime ViewModel]
|
||||
Model[JavaBean Model] -->|Initial getter read / lazy child resolution| VM
|
||||
VM -->|Property change calls setter| Model
|
||||
View <-->|DirectBinding| VM
|
||||
Context[ApplicationContext] --> Controller[Controller / Computed methods]
|
||||
Context[ViewDependencies] --> Controller[Controller / Computed methods]
|
||||
Context --> Converter[Converters]
|
||||
Context --> Component[Component root and controller]
|
||||
Controller --> View
|
||||
@@ -30,7 +30,7 @@ The [dependency baseline](../README.md#dependencies) distinguishes application r
|
||||
|
||||
## Loading order
|
||||
|
||||
`ViewLoader.load` reads the controller declaration and its ViewModel selection, obtains or creates the Model's ViewModel, then loads FXML. The injection context supplies controllers, Components and Converters. JavaFX performs normal `@FXML` field injection and calls `initialize`. After loading, the library supplies the ViewModel to `HasViewModel` only when the selected object extends `ViewModel` (replacement objects do not receive this callback), applies BindingLists in document order, and opens custom Tables.
|
||||
`ViewLoader.loadWithDependencies` reads the controller declaration and its ViewModel selection, obtains or creates the Model's ViewModel, then loads FXML. The adapter supplies controllers, Components and Converters. JavaFX performs normal `@FXML` field injection and calls `initialize`. After loading, the library supplies the ViewModel to `HasViewModel` only when the selected object extends `ViewModel` (replacement objects do not receive this callback), applies BindingLists in document order, and opens custom Tables.
|
||||
|
||||
Consequently, `initialize` must not assume that `HasViewModel.setViewModel` has already run. A Component's own bindings wait for its first non-null Model. Binding order can matter when an earlier declaration causes a nested Model's ViewModel to be created before a later Component requests a more specific class.
|
||||
|
||||
@@ -40,7 +40,11 @@ Consequently, `initialize` must not assume that `HasViewModel.setViewModel` has
|
||||
|
||||
Attributes are JavaBeans properties with both a getter and setter. Runtime properties are initialized from the bean and changes to them call its setter. Direct calls to a bean setter do not send notifications back to the runtime property. Update the ViewModel on the JavaFX application thread when application logic should update an existing View.
|
||||
|
||||
The runtime holds a **global, strong, identity-based cache** of Model-to-ViewModel associations. The same Model object shares one ViewModel across Views and contexts; equal but distinct beans do not. Registration before traversing children supports cyclic graphs. There is no public eviction or release API. Treat this as an explicit limitation for applications with many short-lived Models.
|
||||
Each managed `ViewModelContext` stores Model-to-ViewModel associations
|
||||
by object identity. Views in the same context can share the ViewModel
|
||||
for the same Model object. Independent contexts have independent
|
||||
registrations. Registration before traversing children supports cyclic graphs.
|
||||
Closing the context releases its registrations and closes the remaining Views.
|
||||
|
||||
Complex Attributes are mapped lazily to nested ViewModels. A null child stays null. A dotted binding resolves intermediate objects when the binding is applied; it does not dynamically reattach after replacing an intermediate child. Bind a Component's `model` to the complex Attribute when you want a subform, but note that the current Component implementation also applies its internal bindings only for its first non-null Model.
|
||||
|
||||
@@ -48,24 +52,24 @@ Lists are shared ObservableLists when possible. A `List` bean setter generally a
|
||||
|
||||
## Context and View lifetime
|
||||
|
||||
The [injection context](../../injection/README.md) caches one instance of every scanned class. This includes controllers and converters. Reusing a controller in multiple live Views overwrites its injected FXML fields. Components reuse the context instance for the first occurrence of a class in a load and create fresh instances for additional occurrences; Repeat and Table explicitly create fresh row roots. Nested Components still need care when the same context is reused across independent loads.
|
||||
Use one adapter for a container and give each logical window or document
|
||||
a Model context. Related Views can share a Model context. Each View
|
||||
receives fresh Controller and Component instances. Share services through
|
||||
the adapter.
|
||||
|
||||
Use a separate context for independent windows unless shared controller/component lifetime is intentional. This does not isolate the global Model identity cache: use separate Model instances if you need independent drafts.
|
||||
|
||||
There is no general `LoadedView.close()`, ViewModel disposal, unbind-all operation, or container shutdown hook. Bindings, collection listeners and MessagePopup listeners can retain objects. Closing a Stage does not constitute a documented cleanup contract for these listeners. Install popup listeners once, keep application lifetimes bounded, and test long-running/repeated-window workloads before depending on this snapshot.
|
||||
Close a `LoadedView` when it leaves the application. Its bindings and
|
||||
listeners are detached, and the adapter's release actions run for its
|
||||
Controller and child Components. Close the Model context when its owner
|
||||
ends. Close the application-owned container after its Views. The optional
|
||||
[Neitzel adapter](../../fx-injection/README.md) uses the existing
|
||||
ApplicationContext lookup for shared services and fresh instances for the UI.
|
||||
|
||||
Run loading, scene changes, observable property updates and message operations on the JavaFX application thread. The context and ViewModel cache are not concurrent services. Perform slow I/O separately and deliver results with `Platform.runLater`; do not perform it inside Computed methods or property listeners.
|
||||
|
||||
## Modules and reflection
|
||||
|
||||
The library artifacts currently act as automatic modules named `fx` and `injection`. An application using JPMS generally needs `requires fx`, `requires injection`, `requires jakarta.inject`, `requires javafx.controls` and `requires javafx.fxml`. The precise requirements depend on its imports.
|
||||
|
||||
Open bean packages to `fx` for reflective Attribute access. FXML controller and Component packages need reflective access for JavaFX and the library/container; an unqualified `opens your.controls;` is a straightforward starting point while diagnosing a modular application. Injection may invoke non-public constructors and members. Generated ViewModel packages also require suitable exports/opens, and a named-module registry uses `provides de.neitzel.fx.view.ViewModelRegistry with ...` rather than only a classpath service file.
|
||||
|
||||
Package scanning depends on the runtime's class/module paths. Verify the real modular launch; success on the classpath does not prove a module configuration is correct. The Designer separately validates classpath and module-path target applications and keeps its Kit runtime distinct from the application's JavaFX runtime.
|
||||
|
||||
## Choosing extensions
|
||||
|
||||
Start with generic runtime properties. Add a ViewModel subclass for derived presentation state and a controller for event handling. Use [generated ViewModels](generated-viewmodels.md) for typed access and shared discovery metadata. Use [Components, Repeat and Table](../README.md#component) to reuse form structure. The Designer is an optional authoring tool: the application remains runnable without it.
|
||||
|
||||
The library is a development snapshot and a personal helper collection. In particular, it is not a transactional form engine, a virtualized table, a dependency-tracking expression language, or a full dependency injection framework. Keep business validation and persistence boundaries explicit in application code.
|
||||
A named application using FX typically declares `requires fx`,
|
||||
`requires javafx.controls` and `requires javafx.fxml`. An application
|
||||
using the optional Neitzel adapter adds `requires de.neitzel.fx.injection`
|
||||
and declares `requires injection` and `requires jakarta.inject` where
|
||||
it uses those types. Each container's own requirements apply to its adapter.
|
||||
@@ -48,7 +48,7 @@ objects, rather than controls to insert in a scene graph.
|
||||
```
|
||||
|
||||
Initialize the model's `List<Person> people` before loading. Bean and Java record
|
||||
rows are supported. After `ViewLoader.load`, call the injected grid's `load()` or
|
||||
rows are supported. After loading with `ViewLoader.loadWithDependencies`, call the grid's `load()` or
|
||||
`loadAsync()` on the FX thread. The data binding shares the model's observable
|
||||
list. Add, remove, replace, permute or use an extractor update on that list to
|
||||
request a refresh immediately, invalidating older pending results. The existing
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# Message catalogs for Java and FXML
|
||||
|
||||
Create one Localizer per application. The initial locale can be null to use the JVM display locale. The second argument specifies the fallback language. Register the service with the same ApplicationContext used by ViewLoader.
|
||||
Create one Localizer per application. The initial locale can be null to use the JVM display locale. The second argument specifies the fallback language. Expose the service through `ViewDependencies.findService(Localizer.class)`. With the Neitzel adapter, register it in the underlying `ApplicationContext`.
|
||||
|
||||
```java
|
||||
var language = new Localizer(initialLocale, Locale.ENGLISH,
|
||||
|
||||
+11
-1
@@ -2,6 +2,10 @@
|
||||
|
||||
This walkthrough creates a complete Maven project with one editable name and a label that follows it. It uses Java 25, JavaFX 27.0.1 and NeitzelLib 1.0.6. The source build below uses the matching release tag.
|
||||
|
||||
For the separated development artifacts and the managed loader, see
|
||||
[FX loading](../README.md#load-a-view) and the
|
||||
[optional Neitzel adapter](../../fx-injection/README.md).
|
||||
|
||||
## Prepare the library
|
||||
|
||||
Install a JDK 25. Use the library's Maven wrapper (3.9.11), or a separate Maven installation version 3.9.11 or newer. Check `java -version` and `./mvnw -version` before building; on macOS, select the JDK with `export JAVA_HOME=$(/usr/libexec/java_home -v 25)` if necessary.
|
||||
@@ -33,7 +37,7 @@ print(f'{len(reports)} test suites passed')
|
||||
PYTHON
|
||||
```
|
||||
|
||||
Use a clean build when qualifying a change so stale reports cannot stand in for tests that did not run.
|
||||
Use a clean build when qualifying a change so stale reports cannot stand in for tests that did not run. The standalone POM below can also resolve the published 1.0.6 artifacts directly.
|
||||
|
||||
## Create the application
|
||||
|
||||
@@ -62,6 +66,12 @@ hello-fx/
|
||||
<maven.compiler.release>25</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gitea-neitzellib</id>
|
||||
<url>https://gitea.neitzel.de/api/packages/konrad/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>de.neitzel.lib</groupId>
|
||||
|
||||
Reference in New Issue
Block a user