Run Designer previews with application-owned DI adapters
This commit is contained in:
+81
-10
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user