Files
NeitzelFXDesigner/docs/user-guide/projects.md
T

189 lines
10 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Connect an application
Start with an application that builds and runs without the editor. The [Person desk quick start](quick-start.md) is the complete executable example. For a new JavaFX application, use NeitzelLib's library quick start first; add Designer integration afterward. Neither a host dependency nor the Scene Builder Kit belongs on the application's runtime path.
## Shared project configuration
Commit `neitzel-fx-designer.json` at the Maven reactor root. This example selects a test-source preview provider:
```json
{
"schemaVersion": "1.0",
"contexts": {
"person-desk": {
"applicationModule": "fx-example",
"mavenProfiles": ["designer-preview"],
"launchMode": "classpath",
"buildRuntime": "java25",
"targetRuntime": "java25",
"buildJava": 25,
"targetJava": 25,
"preview": {
"sourceSet": "test",
"provider": "de.neitzel.fx.example.preview.DeskPreviewProvider",
"defaultExample": "desk"
}
}
}
}
```
A context identifies one application module, profile set, launch mode and runtime pair. Select explicitly when the file contains multiple contexts. Paths and module selections must stay inside the reactor. Unknown properties and unsupported schema versions are errors, not ignored settings. The authoritative [configuration schema](../../designer-contracts/src/main/resources/schema/configuration-1.0.json) lists limits and required fields.
| Setting | Meaning |
| --- | --- |
| `applicationModule` | Application module relative to the reactor root |
| `mavenProfiles` | Explicit Maven profiles used for this snapshot |
| `launchMode` | `classpath` or `module-path` |
| `buildRuntime`, `targetRuntime` | Logical names resolved from local settings |
| `buildJava`, `targetJava` | Optional required Java feature versions |
| `requiredCapabilities` | Explicit worker/runtime capabilities required by the context |
| `preview.sourceSet` | `test`, or `module` with a required `preview.module` |
| `preview.provider` | Qualified provider class; general example discovery is filtered to it |
| `preview.defaultExample`, `preview.examples` | Default/sample selection constraints |
| `preview.requestTimeoutSeconds` | Request timeout, 1–300 seconds |
| `preview.readinessTimeoutSeconds` | Asynchronous readiness timeout, 1–300 seconds |
| `modulePath` | Required only for module-path mode: `entryModule`, optional `addReads` and `addOpens` |
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
Keep machine paths out of the committed context. An ignored `.neitzel-fx-designer/runtimes.json` maps names independently for build and target roles:
```json
{
"schemaVersion": "1.0",
"runtimes": {
"java25": {
"build": "/absolute/path/to/jdk-25",
"target": "/absolute/path/to/jdk-25"
}
}
}
```
The [local settings schema](../../designer-contracts/src/main/resources/schema/local-settings-1.0.json) is authoritative. Both entries refer to full JDK installations. The host's bundled Java runtime is a separate role. Configure local `host.properties` with `configuration`, `context`, `settings`, `maven` and `tools`; paths resolve relative to that properties file. `tools` contains the target-tools, contracts and preview-api JARs separated by the platform path separator. The [quick-start helper](quick-start.md#4-create-local-runtime-and-launch-settings) writes these files for the reference example. There is no graphical project-setup wizard.
## Typed sample providers
Add `de.neitzel.fxdesigner:designer-preview-api` with test scope, preferably
in an opt-in profile. Use `0.1.1` with Designer 0.1.1 or use the tools and API built from your checkout.
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.
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
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, 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 ViewDependencies context() { return dependencies; }
public void close() { /* release resources owned by this sample */ }
};
}
}
```
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 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`:
```properties
format=1
count=1
example.0.id=person
example.0.label=Person sample
example.0.modelType=com.example.Person
example.0.providerClass=com.example.PersonPreview
example.0.viewResource=com/example/Person.fxml
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 FX 1.0.7 | `ViewDependencies` |
The worker selects the loader in the captured application runtime. The
[historical snapshot qualification](../runtime/neitzellib-baseline.md#separated-fx-development-qualification)
records both development builds that preceded 1.0.7. 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 published NeitzelLib `1.0.7` runtime. 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:
```xml
<?neitzel-model com.example.Person?>
```
This is the editor's explicit Model declaration; it does not create a Model or replace the runtime Controller/ViewModel selection. Use `xmlns:fx="http://javafx.com/fxml/1"`. Discovery reads compiled signatures or optional generated metadata, follows nested Attributes and collection element types, and selects the explicit Controller/Component ViewModel contract. Rebuild after Java/configuration changes. See [generation](generation.md) for processor setup.