Run Designer previews with application-owned DI adapters

This commit is contained in:
2026-11-26 16:01:19 +01:00
parent e49d586916
commit 6126967fdc
56 changed files with 2131 additions and 50 deletions
+4 -1
View File
@@ -31,7 +31,10 @@ Start with the German contact-book guide or use the [Person desk quick start](qu
The tested host baseline is macOS arm64, Java 25 and JavaFX/Kit 26. The reference application uses Java 25 and JavaFX 27.0.1. IntelliJ is qualified against build **263.7307.200**. These are tested combinations, not a claim that arbitrary JavaFX, JDK, IDE or OS versions work.
Install the Designer tooling `0.1.1-SNAPSHOT` from this checkout. Published Designer versions are available from the [Gitea Maven registry](https://gitea.neitzel.de/api/packages/konrad/maven), which Maven can use as both a dependency and plugin repository. The target applications and examples use the [NeitzelLib `1.0.6` release baseline](../runtime/neitzellib-baseline.md).
Install the Designer tooling `0.1.1-SNAPSHOT` from this checkout. Published Designer versions are available from the [Gitea Maven registry](https://gitea.neitzel.de/api/packages/konrad/maven), which Maven can use as both a dependency and plugin repository. The target tools compile against the [NeitzelLib `1.0.6` release baseline](../runtime/neitzellib-baseline.md).
The contact-book tutorial uses that release. The Person Desk source checkout
and the Spring fixture can exercise the separated development runtime.
See [provider setup and compatibility](projects.md#use-the-separated-fx-runtime-with-neitzel-di).
## Scope and conventions
+10 -3
View File
@@ -1,6 +1,6 @@
# Architecture, development and troubleshooting
The host owns editing; the target owns application execution. This separation lets a JavaFX 26 editor design applications using the qualified JavaFX 21 runtime without importing their classes or native toolkit into the host.
The host owns editing; the target owns application execution. The JavaFX 26 editor can preview an application running JavaFX 27.0.1 in its own process, with its own classes and native toolkit.
```mermaid
flowchart TD
@@ -12,7 +12,8 @@ flowchart TD
BUILD --> STORE[Immutable snapshot and leases]
CORE --> WORKER[Authenticated target JVM]
STORE --> WORKER
WORKER --> LIB[NeitzelLib ViewLoader and injection]
WORKER --> LIB[Application's NeitzelLib ViewLoader]
LIB --> DI[Application-chosen View dependencies]
LIB --> MODEL[Fresh sample Model and ViewModel graph]
LIB --> VIEW[Real FXML Components and bindings]
WORKER --> PIXELS[Images and sizing metadata]
@@ -34,7 +35,12 @@ flowchart TD
| `designer-maven-plugin` | Captures Maven's effective application runtime for immutable snapshots |
| `designer-model-processor` | Optional Java 25 compile-time Model metadata and ViewModel generation |
The application depends on NeitzelLib FX/core/injection and its own JavaFX runtime, not the host. Preview providers depend on the small API; annotation processing depends on the processor. The target tool JARs are supplied by the host. The shared UI uses a narrow patched Kit source with recorded provenance; see [third-party notices](../../THIRD-PARTY-NOTICES.md). The Kit patch retains its BSD-3-Clause notice. The original Designer code currently has no assigned license, as the notices state; a public repository alone does not establish reuse permission. Retain the applicable third-party licenses and notices when redistributing those components. See [module boundaries](../module-host-boundaries.md) for extension points.
The application supplies its FX and JavaFX artifacts. With separated FX, it
can use `fx-injection` or supply its own `ViewDependencies`. The host supplies
the target tool JARs. The worker chooses the loader from the captured FX
runtime according to the provider's context. Providers use the small preview
API, and projects that generate Model metadata use the optional processor.
See [provider setup and compatibility](projects.md#use-the-separated-fx-runtime-with-neitzel-di). The shared UI uses a narrow patched Kit source with recorded provenance; see [third-party notices](../../THIRD-PARTY-NOTICES.md). The Kit patch retains its BSD-3-Clause notice. The original Designer code currently has no assigned license, as the notices state; a public repository alone does not establish reuse permission. Retain the applicable third-party licenses and notices when redistributing those components. See [module boundaries](../module-host-boundaries.md) for extension points.
## Trust and lifecycle
@@ -61,6 +67,7 @@ The [real fx-example qualification](quick-start.md#verify-this-reference-integra
| Blank/stale Component image | Successful Build and Refresh, matching sample descriptor, Model PI, captured resource mapping and target logs |
| New preview refused after Java/POM change | Build again, or explicitly select last successful build with its outdated state |
| Child View has no sample | Add a descriptor matching that resource and a compatible fresh provider; rebuild |
| Preview reports missing DI contract or legacy loader | Match the provider's context type to the captured FX runtime, then rebuild and refresh |
| Preview fails loading a class/property | Verify the original application first, correct FXML/imports/JPMS access, inspect target logs; no broad opens are injected |
| Converter warning | Declare/test capabilities when supported; an unverified warning is distinct from a known incompatible binding |
| Metadata stale or duplicate | Clean build after processor/Model changes; ensure one owning source compilation emits it |
+2
View File
@@ -4,6 +4,8 @@
## 1. App ohne Plugin starten
Dieser Kurzstart bleibt auf FX 1.0.6 und dessen `ApplicationContext`-Vorschau abgestimmt. Für den getrennten FX-Entwicklungsstand gibt es eine [Provider-Migration](projects.md#use-the-separated-fx-runtime-with-neitzel-di).
Du brauchst einen vollständigen **JDK 25**, Maven **3.9.11 oder neuer** und NeitzelLib `fx` und `fx-test` in Version `1.0.6`. Die Beispiel-POM lädt sie aus der Gitea Maven-Registry. Die JavaFX-Version **27.0.1** bringt Maven mit. Das Projekt läuft auf dem Classpath; du musst kein `module-info.java` schreiben und kein JavaFX-SDK in IntelliJ eintragen.
Öffne `examples/contact-book` als eigenes Projekt in IntelliJ. Falls IntelliJ es nicht als Maven-Projekt erkennt, verknüpfe die `pom.xml` als Maven-Projekt. Wähle JDK 25 als Project SDK und für Maven; aktiviere **nicht** das Profil `designer-preview`. Führe im Beispielordner aus:
+2
View File
@@ -19,6 +19,8 @@ Die überprüfte Ausgangskombination für dieses Beispiel ist:
Die JDK-/JavaFX-Version der Anwendung ist unabhängig vom JavaFX-Toolkit des IntelliJ-Prozesses. Anwendungs- und Vorschau-Code läuft im Zielprozess. Die Kombination wurde mit dem aufgeführten IntelliJ SDK auf macOS geprüft. Die zugehörigen Quellstände und Artefaktgrenzen stehen in der [NeitzelLib-Baseline](../runtime/neitzellib-baseline.md).
Dieses Tutorial nutzt die FX-1.0.6-Loader mit `ApplicationContext`. Für eine eigene Anwendung auf dem getrennten Entwicklungsstand gilt die [Provider-Migration](projects.md#use-the-separated-fx-runtime-with-neitzel-di).
Die Beispiel-POM bezieht `fx` und das Testmodul `fx-test` in Version `1.0.6` aus der Gitea Maven-Registry. Falls du dafür ein separates Maven-Repository verwendest, müssen Maven, Gradle und der aus IntelliJ gestartete Maven-Build auf dasselbe Repository zugreifen. Starte IntelliJ dann aus der Shell mit dem dort gesetzten `MAVEN_OPTS`. Das Beispiel kopiert keine Bibliotheksquellen und enthält keinen Designer-Host als Laufzeitabhängigkeit.
## 2. Die Anwendung separat starten
+1 -1
View File
@@ -18,7 +18,7 @@ The canvas is a design surface, not the running application. Use interactive pre
## Interactive preview
**Interactive preview** starts a separate target JVM with its own Model/context and the current View plus known open Component drafts. It does not share the canvas Model. **Restart** creates fresh sample state; **Stop preview** closes only the owned preview. Closing its editor closes its preview while other editors remain open.
**Interactive preview** starts a separate target JVM with fresh sample data and services from the provider. It uses the captured application FX runtime and the current View plus known open Component drafts. See [supported provider context types](projects.md#use-the-separated-fx-runtime-with-neitzel-di). It does not share the canvas Model. **Restart** creates fresh sample state; **Stop preview** closes only the owned preview. Closing its editor closes its preview while other editors remain open.
Typing later FXML drafts does not destroy interactive state immediately: the preview remains open and indicates earlier drafts. Saving an affected document restarts the preview with fresh sample state. Explicit restart also captures current drafts and clears that indication. Build changes require the normal successful-snapshot selection. Invalid bindings block new previews while leaving source editing/saving available.
+81 -10
View File
@@ -45,7 +45,7 @@ A context identifies one application module, profile set, launch mode and runtim
| `preview.readinessTimeoutSeconds` | Asynchronous readiness timeout, 1–300 seconds |
| `modulePath` | Required only for module-path mode: `entryModule`, optional `addReads` and `addOpens` |
Named-module applications need their ordinary FXMLLoader/injection reflective access as well as explicit preview access. Use the real module names from your dependencies. The Designer does not automatically add broad `--add-opens` workarounds. Consult the [qualified classpath/module-path fixtures](../preview-target-fixtures.md) and existing `designer-target-tools/src/test` examples before adapting a JPMS application.
Named-module applications need reflective access for FXMLLoader, FX and their chosen DI framework as well as explicit preview access. Use the real module names from your dependencies. The Designer does not automatically add broad `--add-opens` workarounds. Consult the [qualified classpath/module-path fixtures](../preview-target-fixtures.md) and existing `designer-target-tools/src/test` examples before adapting a JPMS application.
## Local runtime settings
@@ -67,20 +67,32 @@ The [local settings schema](../../designer-contracts/src/main/resources/schema/l
## Typed sample providers
Add `de.neitzel.fxdesigner:designer-preview-api:0.1.1-SNAPSHOT` with test scope, preferably in an opt-in profile. A provider implements `PreviewProvider<Model, ApplicationContext>`; its public no-argument constructor and `open(exampleId)` execute only in the target JVM, after selection. `modelType()` declares the Model contract.
Add `de.neitzel.fxdesigner:designer-preview-api` with test scope, preferably
in an opt-in profile. Use `0.1.1-SNAPSHOT` with locally built Designer tools.
The version of the preview API is separate from the FX version. The public
no-argument constructor and `open(exampleId)` run in the target JVM after
selection. `modelType()` declares the Model contract.
The following is an illustrative fragment: `Person`, `MyApplication` and `createSamplePerson()` belong to your application. Import `PreviewProvider` and `PreviewSession` from `de.neitzel.fxdesigner.preview` and `ApplicationContext` from `de.neitzel.injection`. The complete compiling providers are in NeitzelLib’s `fx-example/src/designer/java/de/neitzel/fx/example/preview`.
On separated FX, return `ViewDependencies` from the preview session.
This is the outline of a Person Desk provider. It shares the application's
adapter setup and uses a fresh sample Model. A new project supplies its own
equivalents of `Person` and `DeskApp`.
```java
public final class PersonPreview implements PreviewProvider<Person, ApplicationContext> {
import de.neitzel.fx.view.ViewDependencies;
import de.neitzel.fxdesigner.preview.PreviewProvider;
import de.neitzel.fxdesigner.preview.PreviewSession;
public final class PersonPreview implements PreviewProvider<Person, ViewDependencies> {
public Class<Person> modelType() { return Person.class; }
public PreviewSession<Person, ApplicationContext> open(String id) {
if (!id.equals("person")) throw new IllegalArgumentException(id);
Person model = createSamplePerson();
ApplicationContext context = new ApplicationContext(MyApplication.class);
public PreviewSession<Person, ViewDependencies> open(String id) {
if (!"person".equals(id)) throw new IllegalArgumentException(id);
Person model = DeskApp.sample();
ViewDependencies dependencies = DeskApp.dependencies(model);
return new PreviewSession<>() {
public Person model() { return model; }
public ApplicationContext context() { return context; }
public ViewDependencies context() { return dependencies; }
public void close() { /* release resources owned by this sample */ }
};
}
@@ -89,7 +101,11 @@ public final class PersonPreview implements PreviewProvider<Person, ApplicationC
Use fresh Models and services on every call. Do not reuse production singletons, real accounts or external data unintentionally. `open` must clean partial allocations if it throws. `ready()` is called after View load/CSS/layout on the FX thread; return a completion stage for asynchronous work and never block that thread. `close()` runs once on FX after normal close or load/readiness failure. Forced process death cannot guarantee cooperative cleanup.
The actual example uses `DeskPreviewProvider`, `AddressPreviewProvider` and `NotePreviewProvider`. Independent Row previews prepare their parent Controller state explicitly; a Row cannot assume that a separately edited parent View has already run. Sample setup avoids the application's message popup.
The Person Desk's `DeskPreviewProvider`, `AddressPreviewProvider` and
`NotePreviewProvider` are under
`fx-example/src/designer/java/de/neitzel/fx/example/preview`. The standalone
Row preview configures a sample Person and the shared `VisitActions` service
before loading the row. The sample setup skips the application's message popup.
Register non-executing descriptors in `META-INF/neitzel-fx-designer/examples.properties`:
@@ -106,6 +122,61 @@ example.0.componentPackage=com.example
Descriptors are discovered without constructing providers. Per-document selection matches the FXML resource, including independent Components. Inspect the reference example's real five-entry descriptor when adding another View; a new generated FXML file needs its own descriptor before it has an interactive sample.
## Use the separated FX runtime with Neitzel DI
| Captured application FX | Type returned by `PreviewSession.context()` |
| --- | --- |
| Published 1.0.6, including the contact-book tutorial | `ApplicationContext` |
| Earlier DI adapter qualification snapshot | `ApplicationContext` or `ViewDependencies` |
| Separated 1.0.7-SNAPSHOT | `ViewDependencies` |
The worker selects the loader in the captured application runtime. The
[two snapshot variants](../runtime/neitzellib-baseline.md#separated-fx-development-qualification)
use the same Maven coordinates. If a provider still returns a raw
`ApplicationContext` after upgrading to separated FX, change the provider's
context type and return the configured adapter. Install
`de.neitzel.lib:fx-injection` and register the application's concrete FXML
Components, including those used by Repeat and Table. For example:
```java
var services = new ApplicationContext(MyApplication.class);
var dependencies = new NeitzelViewDependencies(services,
Set.of(AddressForm.class, VisitRow.class));
```
Use `PreviewProvider<Model, ViewDependencies>` and
`PreviewSession<Model, ViewDependencies>` with that adapter. Ordinary
application loads pass the adapter to `ViewLoader.loadWithDependencies`
with a window- or document-owned `ViewModelContext`. When two Views
need the same data or action, share an application service through DI.
Each View receives its own Controller.
## Run a Preview with Spring
The target worker also accepts `PreviewSession<Model, ViewDependencies>`
when the captured application uses NeitzelLib FX with the DI adapter API.
The [Spring fixture](../../integration-fixtures/spring-di/README.md) uses
the separated NeitzelLib `1.0.7-SNAPSHOT` development runtime from an isolated Maven repository. Both application and preview run without Neitzel's injection JAR and Reflections.
Register concrete Controller and Component classes as Spring prototype beans.
The fixture looks up shared services by class, checks Component membership
in an explicit set, and returns a `ViewObject` that calls Spring's
`destroyBean(name, instance)` when the View releases that object. The
[Spring adapter](../../integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringViews.java)
is used both by the application and by the sample providers.
A Preview provider opens its own Spring context with sample data. Its
`context()` method returns the FX adapter. Its `close()` method closes the
Spring context after the worker closes the Views. Keep the existing
`META-INF/neitzel-fx-designer/examples.properties` format. For a named module, expose the provider
to the worker and configure FXML resource and reflective access for JavaFX,
FX and Spring. The descriptor's `componentPackage` key remains required. The worker uses
it for its legacy `ApplicationContext` package-scan access check. A new
adapter supplies Component types independently of that key. An application
using `fx-injection` still needs module access for its own Neitzel package
scan. Spring needs the module access declared by its own application and
provider modules.
## Declare the View's Model
Use a processing instruction, ignored by normal FXMLLoader:
+5 -1
View File
@@ -14,7 +14,11 @@ mvn -pl fx-example javafx:run
Surefire fails the build on test failures. The XML reports record which tests ran.
The first command builds/installs the required reactor modules. The second launches only the application module; do not add `-am` to `javafx:run`, because the parent and library modules have no application entry point. The `Main` launcher calls `Application.launch(DeskApp.class, args)`. `DeskApp` creates the sample Person and injection context, then loads `view/Desk.fxml` through NeitzelLib's `ViewLoader`.
The first command builds/installs the required reactor modules. The second launches only the application module; do not add `-am` to `javafx:run`, because the parent and library modules have no application entry point. The `Main` launcher calls `Application.launch(DeskApp.class, args)`. On the separated development checkout, `DeskApp` creates the sample Person
and a `NeitzelViewDependencies` adapter through `DeskApp.dependencies(person)`.
It passes both to the managed loader with its own `ViewModelContext`. For the
preview, build the reference example from the same checkout and use the current
Designer tools. See [runtime compatibility](projects.md#use-the-separated-fx-runtime-with-neitzel-di).
Edit the name and home address, add a visit or tag, and select a visit. The same visit list feeds both the Table and repeated forms. Close the application before continuing. The library's [`fx-example` README](https://gitea.neitzel.de/konrad/NeitzelLib/src/branch/main/fx-example/README.md) explains the individual controls and binding behavior.