From 6126967fdc76614be2357da9ab2dc6ffb5c002dd Mon Sep 17 00:00:00 2001 From: Konrad Neitzel Date: Thu, 26 Nov 2026 16:01:19 +0100 Subject: [PATCH 1/2] Run Designer previews with application-owned DI adapters --- README.md | 7 +- designer-kit-ui/pom.xml | 5 +- .../kit/SpringPreviewHostChecks.java | 97 +++++++ .../fxdesigner/preview/PreviewSession.java | 5 +- .../standalone/SpringPreviewHostSmoke.java | 52 ++++ designer-target-tools/pom.xml | 2 + .../fxdesigner/target/PreviewViewLoader.java | 78 ++++++ .../fxdesigner/target/TargetPreview.java | 82 ++++-- docs/preview-target-fixtures.md | 33 ++- docs/runtime/neitzellib-baseline.json | 192 +++++++++++++- docs/runtime/neitzellib-baseline.md | 32 ++- docs/user-guide/README.md | 5 +- docs/user-guide/architecture.md | 13 +- docs/user-guide/kontakt-kurzstart.md | 2 + docs/user-guide/kontakt-tutorial.md | 2 + docs/user-guide/previews.md | 2 +- docs/user-guide/projects.md | 91 ++++++- docs/user-guide/quick-start.md | 6 +- examples/contact-book/README.md | 2 + integration-fixtures/spring-di/README.md | 79 ++++++ integration-fixtures/spring-di/app/pom.xml | 45 ++++ .../fixture/spring/app/FixtureService.java | 40 +++ .../java/fixture/spring/app/SpringBook.java | 35 +++ .../fixture/spring/app/SpringBookContext.java | 46 ++++ .../fixture/spring/app/SpringRuntime.java | 35 +++ .../java/fixture/spring/app/SpringViews.java | 36 +++ .../main/java/fixture/spring/model/Book.java | 33 +++ .../main/java/fixture/spring/model/Entry.java | 18 ++ .../fixture/spring/ui/BookController.java | 31 +++ .../java/fixture/spring/ui/EntryCard.java | 29 +++ .../java/fixture/spring/ui/EntryPanel.java | 29 +++ .../app/src/main/java/module-info.java | 16 ++ .../resources/fixture/spring/app/Closed.fxml | 2 + .../resources/fixture/spring/ui/Book.fxml | 30 +++ .../fixture/spring/ui/EntryCard.fxml | 14 + .../fixture/spring/ui/EntryPanel.fxml | 14 + .../resources/fixture/spring/ui/Invalid.fxml | 8 + .../spring-di/checks/CapabilityCheck.java | 54 ++++ .../spring-di/checks/SpringChecks.java | 246 ++++++++++++++++++ .../spring-di/checks/legacy/pom.xml | 23 ++ .../spring-di/neitzel-fx-designer.json | 22 ++ integration-fixtures/spring-di/pom.xml | 38 +++ .../spring-di/preview/pom.xml | 21 ++ .../fixture/spring/preview/BookExamples.java | 44 ++++ .../fixture/spring/preview/CardExamples.java | 29 +++ .../preview/src/main/java/module-info.java | 7 + .../neitzel-fx-designer/examples.properties | 14 + .../NeitzelAdapterPreviewCheck.java | 101 +++++++ integration-tests/idea/SpringTargetProbe.java | 66 +++++ .../idea/SpringWorkflowProbe.java | 44 ++++ scripts/check-bootstrap.py | 2 +- scripts/check-neitzel-adapter-preview.py | 33 +++ scripts/check-preview-fixtures.py | 13 +- scripts/check-spring-hosts.py | 64 +++++ scripts/check-spring-preview.py | 84 ++++++ scripts/run-fixture-host.py | 28 ++ 56 files changed, 2131 insertions(+), 50 deletions(-) create mode 100644 designer-kit-ui/src/test/java/de/neitzel/fxdesigner/kit/SpringPreviewHostChecks.java create mode 100644 designer-standalone/src/test/java/de/neitzel/fxdesigner/standalone/SpringPreviewHostSmoke.java create mode 100644 designer-target-tools/src/main/java/de/neitzel/fxdesigner/target/PreviewViewLoader.java create mode 100644 integration-fixtures/spring-di/README.md create mode 100644 integration-fixtures/spring-di/app/pom.xml create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/FixtureService.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringBook.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringBookContext.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringRuntime.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringViews.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/model/Book.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/model/Entry.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/BookController.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/EntryCard.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/EntryPanel.java create mode 100644 integration-fixtures/spring-di/app/src/main/java/module-info.java create mode 100644 integration-fixtures/spring-di/app/src/main/resources/fixture/spring/app/Closed.fxml create mode 100644 integration-fixtures/spring-di/app/src/main/resources/fixture/spring/ui/Book.fxml create mode 100644 integration-fixtures/spring-di/app/src/main/resources/fixture/spring/ui/EntryCard.fxml create mode 100644 integration-fixtures/spring-di/app/src/main/resources/fixture/spring/ui/EntryPanel.fxml create mode 100644 integration-fixtures/spring-di/app/src/main/resources/fixture/spring/ui/Invalid.fxml create mode 100644 integration-fixtures/spring-di/checks/CapabilityCheck.java create mode 100644 integration-fixtures/spring-di/checks/SpringChecks.java create mode 100644 integration-fixtures/spring-di/checks/legacy/pom.xml create mode 100644 integration-fixtures/spring-di/neitzel-fx-designer.json create mode 100644 integration-fixtures/spring-di/pom.xml create mode 100644 integration-fixtures/spring-di/preview/pom.xml create mode 100644 integration-fixtures/spring-di/preview/src/main/java/fixture/spring/preview/BookExamples.java create mode 100644 integration-fixtures/spring-di/preview/src/main/java/fixture/spring/preview/CardExamples.java create mode 100644 integration-fixtures/spring-di/preview/src/main/java/module-info.java create mode 100644 integration-fixtures/spring-di/preview/src/main/resources/META-INF/neitzel-fx-designer/examples.properties create mode 100644 integration-tests/fx-example/NeitzelAdapterPreviewCheck.java create mode 100644 integration-tests/idea/SpringTargetProbe.java create mode 100644 integration-tests/idea/SpringWorkflowProbe.java create mode 100755 scripts/check-neitzel-adapter-preview.py create mode 100755 scripts/check-spring-hosts.py create mode 100755 scripts/check-spring-preview.py diff --git a/README.md b/README.md index 3d28f83..4234a30 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,11 @@ On macOS `IDEA_HOME` points to the IDE application's `Contents` directory. The c Maven is pinned to **3.9.11** (Wrapper **3.3.4**); the separate IntelliJ build uses **Gradle 9.1.0** and IntelliJ Platform Gradle Plugin **2.20.1**. Wrapper distributions have pinned checksums. Shared-module-only validation is `./mvnw -B -ntp clean verify`; it does not qualify IntelliJ packaging. Plugin output is under `designer-intellij/build/distributions/`. +The [Spring DI fixture](integration-fixtures/spring-di/README.md) qualifies +application-owned dependency injection with the development FX API. It has +an independent JavaFX launcher and checks for target previews, Standalone +and the registered IntelliJ editor. + ## Java source conventions Use focused Lombok annotations for mechanical constructors/accessors/logging, @@ -68,7 +73,7 @@ python3 scripts/check-ide-host.py --java-home "$JAVA_HOME" --target-java-home "$ ### Archiver in IntelliJ -Build the Designer modules and plugin with the bootstrap command above. It verifies the [NeitzelLib release baseline](docs/runtime/neitzellib-baseline.md). Use the NeitzelLib version declared by Archiver for its application build. Archiver includes its preview examples in the `designer-preview` Maven profile. To open an isolated IntelliJ instance with a project copy and the built plugin, run from this checkout with the same Maven environment: +Build the Designer modules and plugin with the bootstrap command above. It verifies the [NeitzelLib release baseline](docs/runtime/neitzellib-baseline.md). Install the FX snapshot declared by Archiver for its application build. Its README records the compatible source revision and its legacy `ApplicationContext` provider setup. Archiver includes its preview examples in the `designer-preview` Maven profile. To open an isolated IntelliJ instance with a project copy and the built plugin, run from this checkout with the same Maven environment: ```sh python3 scripts/run-fixture-host.py intellij --archiver ../Archiver \ diff --git a/designer-kit-ui/pom.xml b/designer-kit-ui/pom.xml index 99a5c1e..ddab756 100644 --- a/designer-kit-ui/pom.xml +++ b/designer-kit-ui/pom.xml @@ -39,7 +39,10 @@ test-jar - **/ProjectionHostChecks*.class + + **/ProjectionHostChecks*.class + **/SpringPreviewHostChecks.class + diff --git a/designer-kit-ui/src/test/java/de/neitzel/fxdesigner/kit/SpringPreviewHostChecks.java b/designer-kit-ui/src/test/java/de/neitzel/fxdesigner/kit/SpringPreviewHostChecks.java new file mode 100644 index 0000000..b75de65 --- /dev/null +++ b/designer-kit-ui/src/test/java/de/neitzel/fxdesigner/kit/SpringPreviewHostChecks.java @@ -0,0 +1,97 @@ +package de.neitzel.fxdesigner.kit; + +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMFxIdIndex; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.Callable; +import java.util.stream.Stream; +import java.util.concurrent.FutureTask; +import java.util.concurrent.TimeUnit; +import javafx.application.Platform; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextArea; +import javafx.scene.image.ImageView; + +/** Runs the same UI actions in the standalone and the registered IntelliJ editor. */ +public final class SpringPreviewHostChecks { + private SpringPreviewHostChecks() {} + + public static void verify(DesignerPane pane, String label, boolean book, Path output) throws Exception { + try { + await(() -> pane.kit().editor().getFxomDocument() != null, "canvas"); + click(pane, "Build and Refresh"); + if (book) { + await(() -> { + var component = new FXOMFxIdIndex(pane.kit().editor().getFxomDocument()).lookup("featured"); + return component instanceof FXOMInstance instance + && instance.getSceneGraphObject() instanceof SnapshotRegion region + && region.image() != null && region.statusText().equals("Target runtime"); + }, "Spring Component canvas pixels"); + } + click(pane, "Form preview"); + await(() -> pane.lookup("#full-preview-image") instanceof ImageView view && view.getImage() != null + && ((Label) pane.lookup("#preview-state")).getText().startsWith(label + " · "), + label + " form preview"); + for (int run = 1; run <= 2; run++) { + String attempt = (book ? "book-" : "card-") + run; + System.out.println(label + " interactive preview " + run); + Files.writeString(output.resolve("spring-attempt"), attempt); + click(pane, "Interactive preview"); + await(() -> { + var error = output.resolve("target-error.txt"); + if (Files.exists(error)) throw new AssertionError(Files.readString(error)); + if (hasLabel(pane, "Interactive preview failed; use Interactive preview to retry")) + throw new AssertionError("Interactive preview failed"); + var result = output.resolve(attempt + ".txt"); + return Files.exists(result) && Files.readString(result) + .equals(book ? "Preview contact book" : "Preview entry"); + }, label + " interactive preview " + run); + click(pane, "Stop preview"); + } + } catch (Exception | AssertionError failure) { + var details = fx(() -> Stream.concat(pane.lookupAll(".label").stream(), pane.lookupAll(".text-area").stream()) + .map(node -> switch (node) { + case Label control -> control.getText(); + case TextArea control -> control.getText(); + default -> ""; + }) + .filter(text -> text != null && !text.isBlank()) + .distinct().toList()); + throw new AssertionError(details.toString(), failure); + } + } + + private static boolean hasLabel(DesignerPane pane, String text) { + return pane.lookupAll(".label").stream().anyMatch(node -> + node instanceof Label label && text.equals(label.getText())); + } + + private static void click(DesignerPane pane, String text) throws Exception { + fx(() -> { + var button = pane.lookupAll(".button").stream() + .filter(node -> node instanceof Button control && text.equals(control.getText())) + .map(Button.class::cast) + .findFirst().orElseThrow(); + button.fire(); + return null; + }); + } + + private static void await(Callable condition, String description) throws Exception { + long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(100); + while (System.nanoTime() < deadline) { + if (fx(condition)) return; + Thread.sleep(100); + } + throw new AssertionError("Timed out waiting for " + description); + } + + public static T fx(Callable action) throws Exception { + var task = new FutureTask(action); + Platform.runLater(task); + return task.get(15, TimeUnit.SECONDS); + } +} diff --git a/designer-preview-api/src/main/java/de/neitzel/fxdesigner/preview/PreviewSession.java b/designer-preview-api/src/main/java/de/neitzel/fxdesigner/preview/PreviewSession.java index 9265e7d..3320aae 100644 --- a/designer-preview-api/src/main/java/de/neitzel/fxdesigner/preview/PreviewSession.java +++ b/designer-preview-api/src/main/java/de/neitzel/fxdesigner/preview/PreviewSession.java @@ -2,7 +2,10 @@ package de.neitzel.fxdesigner.preview; import java.util.concurrent.*; -/** Owned example state. The NeitzelLib adapter requires C to be an ApplicationContext. */ +/** + * Owned example state. Return ViewDependencies on FX runtimes with the DI adapter API. + * An ApplicationContext is supported on runtimes that provide the legacy loaders. + */ public interface PreviewSession extends AutoCloseable { M model(); diff --git a/designer-standalone/src/test/java/de/neitzel/fxdesigner/standalone/SpringPreviewHostSmoke.java b/designer-standalone/src/test/java/de/neitzel/fxdesigner/standalone/SpringPreviewHostSmoke.java new file mode 100644 index 0000000..78ce85f --- /dev/null +++ b/designer-standalone/src/test/java/de/neitzel/fxdesigner/standalone/SpringPreviewHostSmoke.java @@ -0,0 +1,52 @@ +package de.neitzel.fxdesigner.standalone; + +import de.neitzel.fxdesigner.kit.DesignerPane; +import de.neitzel.fxdesigner.workflow.HostLaunch; +import de.neitzel.fxdesigner.kit.SpringPreviewHostChecks; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.CompletableFuture; +import javafx.application.Platform; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import static de.neitzel.fxdesigner.kit.SpringPreviewHostChecks.fx; + +public final class SpringPreviewHostSmoke { + public static void main(String[] args) throws Exception { + var launch = HostLaunch.load(Path.of(args[0])); + Platform.startup(() -> Platform.setImplicitExit(false)); + var book = Path.of(args[1]); + var output = Path.of(args[2]); + try (var host = new StandaloneHost(launch.runtimes(), + location -> CompletableFuture.completedFuture(null), + diagnostic -> System.out.println(diagnostic.message()))) { + verify(host, launch, book, "Spring contact book", true, output); + verify(host, launch, book.resolveSibling("EntryCard.fxml"), "Spring entry", false, output); + Files.writeString(output.resolve("SUCCESS.txt"), + "PASS Spring canvas, form and interactive previews in standalone"); + } finally { + Platform.exit(); + } + } + + private static void verify(StandaloneHost host, HostLaunch launch, Path file, String label, boolean book, Path output) + throws Exception { + var stage = fx(Stage::new); + var pane = fx(() -> { + var editor = new DesignerPane(host.services(), launch, file); + stage.setScene(new Scene(editor, 1300, 850)); + stage.show(); + return editor; + }); + try { + SpringPreviewHostChecks.verify(pane, label, book, output); + } finally { + fx(() -> { + pane.close(); + stage.close(); + return null; + }); + } + } +} diff --git a/designer-target-tools/pom.xml b/designer-target-tools/pom.xml index a08ec2d..7dc7247 100644 --- a/designer-target-tools/pom.xml +++ b/designer-target-tools/pom.xml @@ -25,6 +25,8 @@ de.neitzel.lib fx ${neitzellib.version} + + provided org.junit.jupiter diff --git a/designer-target-tools/src/main/java/de/neitzel/fxdesigner/target/PreviewViewLoader.java b/designer-target-tools/src/main/java/de/neitzel/fxdesigner/target/PreviewViewLoader.java new file mode 100644 index 0000000..cad6c1a --- /dev/null +++ b/designer-target-tools/src/main/java/de/neitzel/fxdesigner/target/PreviewViewLoader.java @@ -0,0 +1,78 @@ +package de.neitzel.fxdesigner.target; + +import de.neitzel.fx.view.LoadedView; +import de.neitzel.fx.view.ViewLoader; +import de.neitzel.fx.view.ViewModelContext; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import javafx.scene.Parent; + +/** Resolves the appropriate loader signature in the captured application's FX runtime. */ +record PreviewViewLoader(Class contract, boolean legacy) { + private static final String CONTRACT = "de.neitzel.fx.view.ViewDependencies"; + private static final String VIEW_OBJECT = "de.neitzel.fx.view.ViewObject"; + private static final String LEGACY_CONTEXT = "de.neitzel.injection.ApplicationContext"; + + static PreviewViewLoader forContext(Object context) { + for (Class type = context.getClass(); type != null; type = type.getSuperclass()) { + if (LEGACY_CONTEXT.equals(type.getName())) return new PreviewViewLoader(type, true); + } + Class contract; + try { + contract = Class.forName(CONTRACT, false, ViewLoader.class.getClassLoader()); + } catch (ClassNotFoundException unavailable) { + throw new PreviewFailure( + PreviewFailure.Code.CONTEXT_TYPE, + "Preview context must be an ApplicationContext or use NeitzelLib FX with the ViewDependencies API", + unavailable); + } + if (!contract.isInstance(context)) { + throw new PreviewFailure( + PreviewFailure.Code.CONTEXT_TYPE, + "Preview context must be an ApplicationContext or ViewDependencies", + null); + } + return new PreviewViewLoader(contract, false); + } + + LoadedView load( + URL resource, Class component, Object model, Object context, + ViewModelContext models) throws Throwable { + try { + var method = + component == null + ? ViewLoader.class.getMethod( + legacy ? "load" : "loadWithDependencies", URL.class, Object.class, contract, ViewModelContext.class) + : ViewLoader.class.getMethod( + legacy ? "loadComponent" : "loadComponentWithDependencies", + Class.class, Object.class, contract, ViewModelContext.class); + return (LoadedView) method.invoke( + null, component == null ? resource : component, model, context, models); + } catch (NoSuchMethodException unavailable) { + if (legacy) { + throw new PreviewFailure( + PreviewFailure.Code.CONTEXT_TYPE, + "This FX runtime needs the preview provider to return ViewDependencies. " + + "Use fx-injection for ApplicationContext or use the previous FX baseline.", + unavailable); + } + throw missingCapability(unavailable); + } catch (InvocationTargetException failed) { + throw failed.getCause(); + } + } + + static boolean missingContract(Throwable failure) { + if (!(failure instanceof ClassNotFoundException || failure instanceof NoClassDefFoundError) + || failure.getMessage() == null) return false; + var name = failure.getMessage().replace('/', '.'); + return name.equals(CONTRACT) || name.equals(VIEW_OBJECT); + } + + static PreviewFailure missingCapability(Throwable cause) { + return new PreviewFailure( + PreviewFailure.Code.CONTEXT_TYPE, + "ViewDependencies preview needs NeitzelLib FX with the DI adapter API (1.0.7 or its development snapshot)", + cause); + } +} diff --git a/designer-target-tools/src/main/java/de/neitzel/fxdesigner/target/TargetPreview.java b/designer-target-tools/src/main/java/de/neitzel/fxdesigner/target/TargetPreview.java index 53e70a9..dde7561 100644 --- a/designer-target-tools/src/main/java/de/neitzel/fxdesigner/target/TargetPreview.java +++ b/designer-target-tools/src/main/java/de/neitzel/fxdesigner/target/TargetPreview.java @@ -2,7 +2,6 @@ package de.neitzel.fxdesigner.target; import de.neitzel.fx.view.*; import de.neitzel.fxdesigner.preview.*; -import de.neitzel.injection.ApplicationContext; import java.time.Duration; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -84,14 +83,6 @@ public final class TargetPreview implements AutoCloseable { var previous = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(loader); try { - // Named modules need this one package open for Reflections' ClassLoader resource enumeration. - for (Module module : ModuleLayer.boot().modules()) - if (module.getPackages().contains(d.componentPackage()) - && !module.isOpen(d.componentPackage())) - throw failure( - PreviewFailure.Code.MODULE_ACCESS, - "Open component package " + d.componentPackage() + " for NeitzelLib scanning", - null); Class type = Class.forName(d.providerClass(), false, loader); if (!PreviewProvider.class.isAssignableFrom(type)) throw failure( @@ -103,21 +94,37 @@ public final class TargetPreview implements AutoCloseable { if (provider.modelType() != modelType) throw failure( PreviewFailure.Code.MODEL_TYPE, "Descriptor/provider Model types differ", null); - session = provider.open(d.id()); - if (session == null || session.model() == null || !modelType.isInstance(session.model())) + try { + session = provider.open(d.id()); + } catch (Throwable error) { + if (closedModulePackage(d.componentPackage()) && failedNeitzelLookup(error)) + throw scanAccess(d, error); + throw error; + } + Object model = session == null ? null : session.model(); + if (!modelType.isInstance(model)) throw failure( PreviewFailure.Code.MODEL_TYPE, "Provider returned an incompatible Model", null); - if (!(session.context() instanceof ApplicationContext context)) - throw failure( - PreviewFailure.Code.CONTEXT_TYPE, - "NeitzelLib preview requires an ApplicationContext", - null); + Object context = session.context(); + if (context == null) + throw failure(PreviewFailure.Code.CONTEXT_TYPE, "Preview session returned no context", null); + var viewLoader = PreviewViewLoader.forContext(context); + if (viewLoader.legacy() && closedModulePackage(d.componentPackage())) + throw scanAccess(d, null); var resource = loader.getResource(d.viewResource()); - if (resource == null) + if (resource == null) { + int slash = d.viewResource().lastIndexOf('/'); + if (slash > 0) { + String resourcePackage = d.viewResource().substring(0, slash).replace('/', '.'); + if (closedModulePackage(resourcePackage)) + throw failure( + PreviewFailure.Code.MODULE_ACCESS, + "Open FXML resource package " + resourcePackage + " to load " + d.viewResource(), + null); + } throw failure( - PreviewFailure.Code.RESOURCE, - "View resource unavailable: " + d.viewResource() + "; check module resource openness", - null); + PreviewFailure.Code.RESOURCE, "View resource unavailable: " + d.viewResource(), null); + } var xml = javax.xml.parsers.DocumentBuilderFactory.newInstance(); xml.setNamespaceAware(true); xml.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); @@ -128,12 +135,13 @@ public final class TargetPreview implements AutoCloseable { "http://javafx.com/fxml/1".equals(element.getNamespaceURI()) && "root".equals(element.getLocalName()); } + Class componentType = null; if (component) { String name = d.viewResource().substring(0, d.viewResource().length() - 5).replace('/', '.'); - var componentType = Class.forName(name, false, loader).asSubclass(Parent.class); - view = ViewLoader.loadComponent(componentType, session.model(), context, models); - } else view = ViewLoader.load(resource, session.model(), context, models); + componentType = Class.forName(name, false, loader).asSubclass(Parent.class); + } + view = viewLoader.load(resource, componentType, model, context, models); scene = new Scene(view.getRoot(), 420, 240); interactive = new javafx.stage.Stage(); interactive.setScene(scene); @@ -166,13 +174,38 @@ public final class TargetPreview implements AutoCloseable { } } + private static boolean closedModulePackage(String name) { + return ModuleLayer.boot().modules().stream() + .anyMatch(module -> module.getPackages().contains(name) && !module.isOpen(name)); + } + + private static boolean failedNeitzelLookup(Throwable error) { + for (Throwable cause = error; cause != null; cause = cause.getCause()) { + for (var frame : cause.getStackTrace()) { + String owner = frame.getClassName(); + if (owner.equals("de.neitzel.injection.ApplicationContext") + || owner.equals("de.neitzel.injection.ComponentScanner")) return true; + } + } + return false; + } + + private static PreviewFailure scanAccess(ExampleDescriptor descriptor, Throwable cause) { + return failure( + PreviewFailure.Code.MODULE_ACCESS, + "Open component package " + descriptor.componentPackage() + " for NeitzelLib scanning", + cause); + } + private static PreviewFailure failure(PreviewFailure.Code code, String text, Throwable e) { return new PreviewFailure(code, text, e); } private static PreviewFailure classify(Throwable e) { if (e instanceof PreviewFailure f) return f; - for (Throwable t = e; t != null; t = t.getCause()) + for (Throwable t = e; t != null; t = t.getCause()) { + if (PreviewViewLoader.missingContract(t)) + return PreviewViewLoader.missingCapability(e); if (t instanceof java.lang.reflect.InaccessibleObjectException || t instanceof IllegalAccessException || t instanceof IllegalAccessError) @@ -180,6 +213,7 @@ public final class TargetPreview implements AutoCloseable { PreviewFailure.Code.MODULE_ACCESS, "Target module access denied; inspect declared exports/opens", e); + } return failure(PreviewFailure.Code.LOAD, "NeitzelLib View load failed", e); } diff --git a/docs/preview-target-fixtures.md b/docs/preview-target-fixtures.md index 64e256b..40403b1 100644 --- a/docs/preview-target-fixtures.md +++ b/docs/preview-target-fixtures.md @@ -1,6 +1,30 @@ # Preview API and target adapter qualification -Implementation history: this page records its original bootstrap work package. The [first connected workflow](first-connected-workflow.md) now supplies worker transport, draft overlays and runnable minimal hosts; historical test counts below remain scoped to that earlier step. +The compatibility checks below cover the published 1.0.6 target, the earlier +DI adapter snapshot and the separated FX snapshot. The rest of the page +records the original Java 21 bootstrap qualification. The +[first connected workflow](first-connected-workflow.md) documents worker +transport, draft overlays and runnable minimal hosts. + +## Current DI compatibility checks + +Use JDK 25 and install the current Designer tools in the Maven repository +that supplies the target artifacts. The release-based legacy fixtures use +`ApplicationContext`. + +```sh +python3 scripts/check-preview-fixtures.py --target-java-home "$JAVA_HOME" +``` + +To repeat the legacy checks on the earlier development snapshot, point +`MAVEN_OPTS` at its separate repository and add +`--neitzellib-version 1.0.7-SNAPSHOT`. Follow the +[Spring fixture guide](../integration-fixtures/spring-di/README.md) for the +separated snapshot and the runtime checks without Neitzel's injection +implementation or Reflections. See the +[baseline record](runtime/neitzellib-baseline.md) for artifact identity. + +## Original bootstrap qualification Work package 6 is implemented against the [verified NeitzelLib development artifact](runtime/neitzellib-baseline.md), Java 21 and application JavaFX 21.0.7. This qualifies target-side execution; it does not connect the designer UI, snapshot activation or worker transport. Those remain work package 7. @@ -12,7 +36,10 @@ The dependency-free Java 21 preview API contains: - `PreviewProvider`: `modelType()` and `open(exampleId)`. - `PreviewSession`: `model()`, `context()`, asynchronous `ready()` and `close()`. -The NeitzelLib target adapter requires an `ApplicationContext` context. Providers have public no-argument constructors. They create fresh Models and explicitly configured services after selection, on the target FX thread. They own cleanup of partial allocations when construction throws before returning a session. The adapter owns the returned session and calls its cleanup once on load failure, readiness failure, timeout, cancellation or normal close. +The original fixtures use `ApplicationContext`. Current workers also accept +`ViewDependencies` when the captured FX runtime supplies the DI adapter API. +The [Spring fixture](../integration-fixtures/spring-di/README.md) qualifies +that path. Providers have public no-argument constructors. They create fresh Models and explicitly configured services after selection, on the target FX thread. They own cleanup of partial allocations when construction throws before returning a session. The adapter owns the returned session and calls its cleanup once on load failure, readiness failure, timeout, cancellation or normal close. Discovery reads UTF-8 `META-INF/neitzel-fx-designer/examples.properties` resources without loading provider or Model classes. This development metadata contract has format version 1: @@ -35,7 +62,7 @@ These are tested development signatures, not a published API release or a promis ## Lifecycle boundary established by the fixtures -NeitzelLib's `ViewModels` retains Model/ViewModel identities in a process-wide identity map with no public disposal operation. Closing a session releases provider-owned resources but cannot clear that map. Consequently `TargetPreview` allows **one session per target JVM**, including failed sessions. Every restart and interactive preview needs a fresh process. +The original Java 21 FX artifact retained Model/ViewModel identities in a process-wide identity map. That qualification established **one session per target JVM**, including failed sessions. The same process ownership rule still applies. Current managed loaders use a `ViewModelContext`. The worker closes it before the preview session's provider-owned services. The adapter's readiness deadline and cleanup are cooperative FX-thread operations. A blocked constructor, Controller or cleanup hook cannot be interrupted by the adapter. Work package 7 must enforce an external process deadline, bounded graceful shutdown and forced termination using the host-owned lifetime channel. The fixture runner enforces a 30-second process timeout. Session close is not proof that library-held objects have been garbage-collected. diff --git a/docs/runtime/neitzellib-baseline.json b/docs/runtime/neitzellib-baseline.json index 882b6e3..a626cbe 100644 --- a/docs/runtime/neitzellib-baseline.json +++ b/docs/runtime/neitzellib-baseline.json @@ -141,5 +141,195 @@ "repositoryPath": "de/neitzel/lib/fx-test/1.0.6/fx-test-1.0.6.jar", "sha256": "0cae3772377ad161535ab6b8414b350df37970c09a5872db35a00f305d6fdad3" } - ] + ], + "diAdapterSnapshot": { + "status": "qualified-development-snapshot", + "version": "1.0.7-SNAPSHOT", + "sourceBaseRevision": "efda8c2d14c0b812ba9f217a3cebbb81787278ea", + "sourceTree": "57f803dab0812e8ef44f0087f80326f44df24d62", + "requiredCapability": "ViewDependencies and managed loader methods", + "javaVersion": "25.0.5", + "javafxVersion": "27.0.1", + "springVersion": "6.2.11", + "testResults": { + "core": { + "tests": 9, + "failures": 0, + "errors": 0, + "skipped": 1 + }, + "injection": { + "tests": 10, + "failures": 0, + "errors": 0, + "skipped": 0 + }, + "data-grid": { + "tests": 33, + "failures": 0, + "errors": 0, + "skipped": 0 + }, + "fx": { + "tests": 415, + "failures": 0, + "errors": 0, + "skipped": 12 + }, + "fx-test": { + "tests": 2, + "failures": 0, + "errors": 0, + "skipped": 0 + } + }, + "artifacts": [ + { + "repositoryPath": "de/neitzel/lib/neitzellib/1.0.7-SNAPSHOT/neitzellib-1.0.7-SNAPSHOT.pom", + "sha256": "54e80182ab74387914298165318b175adffbc6011b8c7c80f4b7034c9c5da6cc" + }, + { + "repositoryPath": "de/neitzel/lib/core/1.0.7-SNAPSHOT/core-1.0.7-SNAPSHOT.pom", + "sha256": "c164de433753bf35e9e748cb169e499737e91787b962036bcd0192fd537da0a1" + }, + { + "repositoryPath": "de/neitzel/lib/core/1.0.7-SNAPSHOT/core-1.0.7-SNAPSHOT.jar", + "sha256": "3ed354f7975eadcf20774ae86311c67c0486bd074b4ee7d1eb23bb809a53411d" + }, + { + "repositoryPath": "de/neitzel/lib/injection/1.0.7-SNAPSHOT/injection-1.0.7-SNAPSHOT.pom", + "sha256": "65968ade4a6d4be69a4bacce363c8f2282f66e900d7ec4600c0a2a11b89b8d40" + }, + { + "repositoryPath": "de/neitzel/lib/injection/1.0.7-SNAPSHOT/injection-1.0.7-SNAPSHOT.jar", + "sha256": "541976f22b80ac65faec1b9181b7446040c578c2fc564062eedee1a6219ebf7a" + }, + { + "repositoryPath": "de/neitzel/lib/data-grid/1.0.7-SNAPSHOT/data-grid-1.0.7-SNAPSHOT.pom", + "sha256": "852feff1ec1652aed8c8cd13ec7138a648c08b77b8444f3bc28d08ef0d152a2c" + }, + { + "repositoryPath": "de/neitzel/lib/data-grid/1.0.7-SNAPSHOT/data-grid-1.0.7-SNAPSHOT.jar", + "sha256": "69ae9be16f71b0fb0c09c565a74e88f324df649a7ba24165eac9b87148708910" + }, + { + "repositoryPath": "de/neitzel/lib/fx/1.0.7-SNAPSHOT/fx-1.0.7-SNAPSHOT.pom", + "sha256": "72b1e07a0f1784e91fb015542ce424f9681267d2c8d7573f01a00209e2908c87" + }, + { + "repositoryPath": "de/neitzel/lib/fx/1.0.7-SNAPSHOT/fx-1.0.7-SNAPSHOT.jar", + "sha256": "d34b25a15715c27c26b4fc3c94a28695b5cf49d78edecc9f5e28cb3633bbaed5" + }, + { + "repositoryPath": "de/neitzel/lib/fx-test/1.0.7-SNAPSHOT/fx-test-1.0.7-SNAPSHOT.pom", + "sha256": "07decf3a7f28cdefca6800508b392bbd92b5d4f78bd00ca463e3deb40133048d" + }, + { + "repositoryPath": "de/neitzel/lib/fx-test/1.0.7-SNAPSHOT/fx-test-1.0.7-SNAPSHOT.jar", + "sha256": "a7e42ab2b1cc6254d2c487f87a291627e774c0a2b70ba76fffbdb953019e6e5d" + } + ] + }, + "fxInjectionSplit": { + "status": "qualified-development-snapshot", + "version": "1.0.7-SNAPSHOT", + "sourceBaseRevision": "efda8c2d14c0b812ba9f217a3cebbb81787278ea", + "sourceTree": "323f30c1e513da1189fb61fd8589fcca81d82cbc", + "requiredCapability": "FX managed ViewDependencies without injection or Reflections", + "javaVersion": "25.0.5", + "javafxVersion": "27.0.1", + "springVersion": "6.2.11", + "testResults": { + "core": { + "tests": 9, + "failures": 0, + "errors": 0, + "skipped": 1 + }, + "injection": { + "tests": 10, + "failures": 0, + "errors": 0, + "skipped": 0 + }, + "data-grid": { + "tests": 33, + "failures": 0, + "errors": 0, + "skipped": 0 + }, + "fx": { + "tests": 413, + "failures": 0, + "errors": 0, + "skipped": 12 + }, + "fx-test": { + "tests": 2, + "failures": 0, + "errors": 0, + "skipped": 0 + }, + "fx-injection": { + "tests": 2, + "failures": 0, + "errors": 0, + "skipped": 0 + } + }, + "artifacts": [ + { + "repositoryPath": "de/neitzel/lib/neitzellib/1.0.7-SNAPSHOT/neitzellib-1.0.7-SNAPSHOT.pom", + "sha256": "602d99dbc1633fe5f131dc7816babb07fe34a72c2cf31a79449c3f2e373a1849" + }, + { + "repositoryPath": "de/neitzel/lib/core/1.0.7-SNAPSHOT/core-1.0.7-SNAPSHOT.pom", + "sha256": "d88f50c5d3e57f598426b91e808b86a3993da0fa56feb61dc2c50327eb0e695e" + }, + { + "repositoryPath": "de/neitzel/lib/core/1.0.7-SNAPSHOT/core-1.0.7-SNAPSHOT.jar", + "sha256": "246c9b8ed7044569bcfeffcbe0d1bab9e2205c5fcf881f1938cab7fef7194f11" + }, + { + "repositoryPath": "de/neitzel/lib/injection/1.0.7-SNAPSHOT/injection-1.0.7-SNAPSHOT.pom", + "sha256": "65968ade4a6d4be69a4bacce363c8f2282f66e900d7ec4600c0a2a11b89b8d40" + }, + { + "repositoryPath": "de/neitzel/lib/injection/1.0.7-SNAPSHOT/injection-1.0.7-SNAPSHOT.jar", + "sha256": "a81a89bc94277d9454fa3991a964ac3411dafbecb709272f48e5c78d51720279" + }, + { + "repositoryPath": "de/neitzel/lib/data-grid/1.0.7-SNAPSHOT/data-grid-1.0.7-SNAPSHOT.pom", + "sha256": "852feff1ec1652aed8c8cd13ec7138a648c08b77b8444f3bc28d08ef0d152a2c" + }, + { + "repositoryPath": "de/neitzel/lib/data-grid/1.0.7-SNAPSHOT/data-grid-1.0.7-SNAPSHOT.jar", + "sha256": "9c250c149deb81812bbb310cd14fc58bb1a29b334863db798ecc2ed4eaa02956" + }, + { + "repositoryPath": "de/neitzel/lib/fx/1.0.7-SNAPSHOT/fx-1.0.7-SNAPSHOT.pom", + "sha256": "b1613c38a8775283101f9bc89b1c908a28e66273337ff47e180b8735645e5cc7" + }, + { + "repositoryPath": "de/neitzel/lib/fx/1.0.7-SNAPSHOT/fx-1.0.7-SNAPSHOT.jar", + "sha256": "f65dee75a7a960118ddcf747eee756ac1786bc85713cc638d9246c6f44db0782" + }, + { + "repositoryPath": "de/neitzel/lib/fx-test/1.0.7-SNAPSHOT/fx-test-1.0.7-SNAPSHOT.pom", + "sha256": "07decf3a7f28cdefca6800508b392bbd92b5d4f78bd00ca463e3deb40133048d" + }, + { + "repositoryPath": "de/neitzel/lib/fx-test/1.0.7-SNAPSHOT/fx-test-1.0.7-SNAPSHOT.jar", + "sha256": "fc9a5d4b2f697394d3c7e2eeb29e8f06e95b737799d03673d1c41947d19ed945" + }, + { + "repositoryPath": "de/neitzel/lib/fx-injection/1.0.7-SNAPSHOT/fx-injection-1.0.7-SNAPSHOT.pom", + "sha256": "8dcee2ca40dbf0ae8789f54f592b7695f1c2569b95ccfcc668b9c39fe00a2b10" + }, + { + "repositoryPath": "de/neitzel/lib/fx-injection/1.0.7-SNAPSHOT/fx-injection-1.0.7-SNAPSHOT.jar", + "sha256": "82868e661ed791dd5e349e238841a9bb4f1ed456aced99625f2de55604e2cabc" + } + ] + } } diff --git a/docs/runtime/neitzellib-baseline.md b/docs/runtime/neitzellib-baseline.md index 73a6eea..c7c15a4 100644 --- a/docs/runtime/neitzellib-baseline.md +++ b/docs/runtime/neitzellib-baseline.md @@ -1,6 +1,6 @@ # NeitzelLib release baseline -NeitzelFXDesigner uses `de.neitzel.lib:fx:1.0.6` on JDK 25 and JavaFX 27.0.1 for target tooling and its fixtures. That release provides managed Views, CommandBindings, direct `ViewLoader.loadComponent` loading for `fx:root` previews, one-way HTML and suggestion-list bindings, and literal DataGrid group-label keys. The Designer hosts use JavaFX 26. +NeitzelFXDesigner uses `de.neitzel.lib:fx:1.0.6` on JDK 25 and JavaFX 27.0.1 as the target tools' compile-time baseline and for release-based fixtures, including the original previews and the contact-book tutorial. That release provides managed Views, CommandBindings, direct `ViewLoader.loadComponent` loading for `fx:root` previews, one-way HTML and suggestion-list bindings, and literal DataGrid group-label keys. The Designer hosts use JavaFX 26. The [baseline manifest](neitzellib-baseline.json) records the source revision, tag, Surefire totals and SHA-256 checksums of the published POMs and JARs. It includes the `fx-test` module used by the contact-book example. See the [NeitzelLib 1.0.6 release](https://gitea.neitzel.de/konrad/NeitzelLib/releases/tag/v1.0.6). @@ -16,6 +16,36 @@ Maven resolves the release from the Gitea Maven registry. The verifier reads `~/ If you are qualifying a source change, use a separate local Maven repository. A new local build can produce different JAR bytes. The manifest identifies the registry artifacts used for the Designer release. +## DI adapter development qualification + +The manifest's `diAdapterSnapshot` section records the previous local FX +`1.0.7-SNAPSHOT` used for the first DI adapter qualification. It still +contains the Neitzel injection dependency and the legacy FX overloads. +It records the tested source tree separately from the published release +revision and identifies the actual POMs and JARs used for the fixture. +The Designer continues to compile target tools against FX 1.0.6. The target +worker links the optional DI contract against the captured application FX +runtime after discovering a provider's context. The release verifier checks +the published baseline at the top of the manifest. + +## Separated FX development qualification + +The manifest's `fxInjectionSplit` section identifies the separated +development artifacts. The previous snapshot uses the same Maven +coordinates and is preserved in a distinct local repository. The +published 1.0.6 release remains the target tool's compile-time baseline. +The target application supplies FX at runtime. The worker resolves +legacy loaders for a raw `ApplicationContext` and managed dependency +loaders for a `ViewDependencies` implementation. The separated snapshot +requires the latter. See the [provider compatibility table](../user-guide/projects.md#use-the-separated-fx-runtime-with-neitzel-di). + +To recheck the previous snapshot, use its own repository in +`MAVEN_OPTS` and run `check-preview-fixtures.py` with +`--neitzellib-version 1.0.7-SNAPSHOT`. Install the current Designer tools +into that repository while preserving its FX artifacts. Run the +[Spring checks](../../integration-fixtures/spring-di/README.md) against +the separated snapshot repository. + ## Original Java 21 qualification - Unmodified library main plus the new regression fixture: seven tests, one expected loading error in `componentAttributesApplyAfterInitialization`. Maven reported success because its POM hardcodes `testFailureIgnore=true`; the XML result correctly identified the failure. diff --git a/docs/user-guide/README.md b/docs/user-guide/README.md index f4cb1f5..b9a9b8d 100644 --- a/docs/user-guide/README.md +++ b/docs/user-guide/README.md @@ -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 diff --git a/docs/user-guide/architecture.md b/docs/user-guide/architecture.md index f46fcab..d051b82 100644 --- a/docs/user-guide/architecture.md +++ b/docs/user-guide/architecture.md @@ -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 | diff --git a/docs/user-guide/kontakt-kurzstart.md b/docs/user-guide/kontakt-kurzstart.md index d825693..506bd5e 100644 --- a/docs/user-guide/kontakt-kurzstart.md +++ b/docs/user-guide/kontakt-kurzstart.md @@ -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: diff --git a/docs/user-guide/kontakt-tutorial.md b/docs/user-guide/kontakt-tutorial.md index e8d2c8b..225295d 100644 --- a/docs/user-guide/kontakt-tutorial.md +++ b/docs/user-guide/kontakt-tutorial.md @@ -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 diff --git a/docs/user-guide/previews.md b/docs/user-guide/previews.md index 9546264..0632630 100644 --- a/docs/user-guide/previews.md +++ b/docs/user-guide/previews.md @@ -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. diff --git a/docs/user-guide/projects.md b/docs/user-guide/projects.md index 03dedb3..3a8e3b1 100644 --- a/docs/user-guide/projects.md +++ b/docs/user-guide/projects.md @@ -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`; 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 { +import de.neitzel.fx.view.ViewDependencies; +import de.neitzel.fxdesigner.preview.PreviewProvider; +import de.neitzel.fxdesigner.preview.PreviewSession; + +public final class PersonPreview implements PreviewProvider { public Class modelType() { return Person.class; } - public PreviewSession open(String id) { - if (!id.equals("person")) throw new IllegalArgumentException(id); - Person model = createSamplePerson(); - ApplicationContext context = new ApplicationContext(MyApplication.class); + + public PreviewSession 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` and +`PreviewSession` 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` +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: diff --git a/docs/user-guide/quick-start.md b/docs/user-guide/quick-start.md index 3e6a9d0..1c687ac 100644 --- a/docs/user-guide/quick-start.md +++ b/docs/user-guide/quick-start.md @@ -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. diff --git a/examples/contact-book/README.md b/examples/contact-book/README.md index 205f657..a8e37d5 100644 --- a/examples/contact-book/README.md +++ b/examples/contact-book/README.md @@ -39,6 +39,8 @@ Die normale App benötigt weder NeitzelFXDesigner noch dessen Vorschau-Artefakte ## Optionale Designer-Vorschau +Die Provider dieses Beispiels liefern einen `ApplicationContext` für FX 1.0.6. Beim Wechsel auf den getrennten FX-Entwicklungsstand gilt die [Provider-Migration](../../docs/user-guide/projects.md#use-the-separated-fx-runtime-with-neitzel-di). + Die Vorschau hängt am Maven-Profil `designer-preview` und der eingecheckten `neitzel-fx-designer.json`. Zuerst müssen die Designer-Worker und die passende lokale Preview-API im NeitzelFXDesigner-Checkout installiert sein. Folge danach dem [Tutorialabschnitt für Plugin und lokale Projektkonfiguration](../../docs/user-guide/kontakt-tutorial.md#4-das-projekt-mit-dem-designer-verbinden). Für den Profil-Build: ```sh diff --git a/integration-fixtures/spring-di/README.md b/integration-fixtures/spring-di/README.md new file mode 100644 index 0000000..19fb8dd --- /dev/null +++ b/integration-fixtures/spring-di/README.md @@ -0,0 +1,79 @@ +# Spring contact book + +This Maven fixture runs as a JavaFX application and as a NeitzelFXDesigner +preview. It uses Spring Framework 6.2.11, the separated NeitzelLib `1.0.7-SNAPSHOT`, +JavaFX 27.0.1 in the target and JDK 25. Views use the same FXML and adapter +in both environments. Spring owns the application services. Each Controller +and Component is a prototype. + +## Run it + +Set `JAVA_HOME` to JDK 25 and use a separate local Maven repository to stage +the development artifacts. From the Designer checkout: + +```sh +export DI_MAVEN_REPOSITORY="/absolute/path/to/di-repository" +export MAVEN_OPTS="-Dmaven.repo.local=$DI_MAVEN_REPOSITORY" +(cd ../NeitzelLib && ./mvnw -pl fx-test -am clean install) +./mvnw -B -ntp install +./mvnw -f integration-fixtures/spring-di/app/pom.xml javafx:run +``` + +Edit the book name to see the Spring-supplied Converter update the caption. +Closing the window first destroys its prototypes, then stops the shared +service. The [application bootstrap](app/src/main/java/fixture/spring/app/SpringBook.java) +uses the managed `ViewLoader`. The [Spring registration](app/src/main/java/fixture/spring/app/SpringBookContext.java) +assigns separate scopes to the view types and services. + +## Open the previews + +From the Designer checkout, set up the ignored local paths once: + +```sh +python3 scripts/configure-library-example.py \ + --project integration-fixtures/spring-di --target-java-home "$JAVA_HOME" +``` + +Use the same local Maven repository when starting the Designer or IntelliJ. +Open `app/src/main/resources/fixture/spring/ui/Book.fxml`, select +**Build and Refresh** and then **Form preview** or **Interactive preview**. +The preview starts with `Preview contact book`; changes to it belong to +that preview. **Stop preview** closes the session. Open `EntryCard.fxml` +and start its separate example to see that Component as a standalone root. + +The [Book provider](preview/src/main/java/fixture/spring/preview/BookExamples.java) +creates a fresh Model and Spring context. The [Component provider](preview/src/main/java/fixture/spring/preview/CardExamples.java) +returns its own Model and context. Both provide the application +[adapter](app/src/main/java/fixture/spring/app/SpringViews.java). +FXML resources and fields in `fixture.spring.ui` are accessible in the +[application module](app/src/main/java/module-info.java). The +[preview module](preview/src/main/java/module-info.java) exposes its providers. +The package named by `componentPackage` stays closed to demonstrate that +the Spring worker uses FXML resource access and the registered Spring beans. + +## Run the checks + +From the Designer checkout, using the same JDK and local Maven repository: + +```sh +python3 scripts/check-preview-fixtures.py --spring-di --target-java-home "$JAVA_HOME" +./designer-intellij/gradlew -p designer-intellij -PideaHome="$IDEA_HOME" \ + -Dmaven.repo.local="$DI_MAVEN_REPOSITORY" buildPlugin +./mvnw -pl designer-standalone \ + org.apache.maven.plugins:maven-dependency-plugin:3.6.1:build-classpath \ + -DincludeScope=test -Dmdep.outputFile=target/smoke-classpath.txt +python3 scripts/check-spring-hosts.py --java-home "$JAVA_HOME" \ + --target-java-home "$JAVA_HOME" --idea-home "$IDEA_HOME" +``` + +The worker checks include two simultaneous Views, separate scopes, nested +Components, Repeat and Table release, cleanup after load/readiness failure +and cancellation, module resource diagnostics, and the required runtime +diagnostic against FX 1.0.6. The host checks use disposably copied project +files and exercise the canvas, form preview and interactive preview. + +Each Spring context verifies that the running application or preview +cannot load Neitzel's `ApplicationContext` or Reflections and that +their JARs are absent from its classpath and module path. The test +runner separately verifies the normal Maven dependency trees. Its +missing-API check resolves FX 1.0.6 from a separate POM. diff --git a/integration-fixtures/spring-di/app/pom.xml b/integration-fixtures/spring-di/app/pom.xml new file mode 100644 index 0000000..0cf500e --- /dev/null +++ b/integration-fixtures/spring-di/app/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + + de.neitzel.fxdesigner.fixtures + spring-di + 1 + + spring-di-app + + + + de.neitzel.lib + fx + ${neitzellib.version} + + + org.springframework + spring-context + ${spring.version} + + + jakarta.annotation + jakarta.annotation-api + ${jakarta-annotation.version} + + + jakarta.inject + jakarta.inject-api + ${jakarta-inject.version} + + + + + + + org.openjfx + javafx-maven-plugin + ${javafx-maven-plugin.version} + + fixture.spring.app/fixture.spring.app.SpringBook + + + + + diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/FixtureService.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/FixtureService.java new file mode 100644 index 0000000..071ea27 --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/FixtureService.java @@ -0,0 +1,40 @@ +package fixture.spring.app; + +import jakarta.annotation.PreDestroy; +import java.util.ArrayList; +import java.util.List; + +/** An in-memory service shared by all View objects in one Spring context. */ +public final class FixtureService { + private final String label; + private final List live = new ArrayList<>(); + private int released; + private int atShutdown = -1; + private int shutdowns; + + public FixtureService(String label) { this.label = label; } + + public String label() { return label; } + + public void created(Object object) { live.add(object); } + + public void release(Object object) { + if (!live.remove(object)) throw new IllegalStateException("Unknown View object: " + object); + released++; + } + + public int liveCount() { return live.size(); } + + public int releasedCount() { return released; } + + public int liveAtShutdown() { return atShutdown; } + + public int shutdownCount() { return shutdowns; } + + @PreDestroy + public void shutdown() { + atShutdown = live.size(); + shutdowns++; + System.out.println("SPRING CLOSED " + label + " live=" + atShutdown + " released=" + released); + } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringBook.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringBook.java new file mode 100644 index 0000000..c499512 --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringBook.java @@ -0,0 +1,35 @@ +package fixture.spring.app; + +import de.neitzel.fx.view.ViewLoader; +import de.neitzel.fx.view.ViewModelContext; +import fixture.spring.model.Book; +import fixture.spring.ui.BookController; +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public final class SpringBook extends Application { + private SpringBookContext context; + private final ViewModelContext models = new ViewModelContext(); + + public static void main(String[] args) { launch(args); } + + @Override + public void start(Stage stage) { + context = SpringBookContext.open("Application service"); + var view = ViewLoader.loadWithDependencies(BookController.class.getResource("Book.fxml"), + Book.sample("Spring contact book"), context.dependencies(), models); + stage.setTitle("Spring contact book"); + stage.setScene(new Scene(view.getRoot(), 660, 500)); + stage.show(); + } + + @Override + public void stop() { + try { + models.close(); + } finally { + if (context != null) context.close(); + } + } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringBookContext.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringBookContext.java new file mode 100644 index 0000000..fda0da0 --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringBookContext.java @@ -0,0 +1,46 @@ +package fixture.spring.app; + +import de.neitzel.fx.view.Converter; +import fixture.spring.ui.BookController; +import fixture.spring.ui.EntryCard; +import fixture.spring.ui.EntryPanel; +import java.util.Map; +import java.util.Set; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public record SpringBookContext(AnnotationConfigApplicationContext spring, SpringViews dependencies) + implements AutoCloseable { + private static final Map, String> VIEW_BEANS = Map.of( + BookController.class, "bookController", EntryCard.class, "entryCard", EntryPanel.class, "entryPanel"); + + public static SpringBookContext open(String serviceLabel) { + SpringRuntime.requireNoNeitzelDi(serviceLabel); + var spring = new AnnotationConfigApplicationContext(); + try { + spring.registerBean(FixtureService.class, () -> new FixtureService(serviceLabel)); + spring.registerBean(NameConverter.class); + VIEW_BEANS.forEach((type, name) -> spring.registerBean(name, type, + bean -> bean.setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE))); + spring.refresh(); + return new SpringBookContext(spring, + new SpringViews(spring.getBeanFactory(), VIEW_BEANS, Set.of(EntryCard.class, EntryPanel.class))); + } catch (RuntimeException | Error failure) { + spring.close(); + throw failure; + } + } + + public FixtureService service() { return spring.getBean(FixtureService.class); } + + @Override + public void close() { spring.close(); } + + public static final class NameConverter implements Converter { + @Override + public Object toControlValue(Object value) { return "[" + value + "]"; } + + @Override + public Object toAttributeValue(Object value) { return value; } + } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringRuntime.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringRuntime.java new file mode 100644 index 0000000..c3bc6af --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringRuntime.java @@ -0,0 +1,35 @@ +package fixture.spring.app; + +import java.io.File; +import java.nio.file.Path; +import java.util.List; +import java.util.regex.Pattern; + +/** Verifies the artifact isolation in both the fixture application and its preview process. */ +final class SpringRuntime { + private static final Pattern NEITZEL_DI = Pattern.compile("(?:fx-injection|injection|reflections)-.*\\.jar"); + + private SpringRuntime() {} + + static void requireNoNeitzelDi(String label) { + var loader = Thread.currentThread().getContextClassLoader(); + for (String type : List.of("de.neitzel.injection.ApplicationContext", "org.reflections.Reflections")) { + try { + Class.forName(type, false, loader); + throw new IllegalStateException("Unexpected runtime type " + type); + } catch (ClassNotFoundException expected) { + // The fixture must be usable without either implementation. + } + } + for (String property : List.of("java.class.path", "jdk.module.path")) { + String path = System.getProperty(property, ""); + if (path.isEmpty()) continue; + for (String entry : path.split(Pattern.quote(File.pathSeparator))) { + if (NEITZEL_DI.matcher(Path.of(entry).getFileName().toString()).matches()) + throw new IllegalStateException("Unexpected DI artifact on " + property + ": " + entry); + } + } + var mode = SpringRuntime.class.getModule().isNamed() ? "module-path" : "classpath"; + System.out.println("SPRING FX ISOLATION " + mode + " " + label); + } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringViews.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringViews.java new file mode 100644 index 0000000..f264588 --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/app/SpringViews.java @@ -0,0 +1,36 @@ +package fixture.spring.app; + +import de.neitzel.fx.view.ViewDependencies; +import de.neitzel.fx.view.ViewObject; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; + +public record SpringViews(ConfigurableBeanFactory beans, Map, String> viewBeans, + Set> components) implements ViewDependencies { + public SpringViews { + viewBeans = Map.copyOf(viewBeans); + components = Set.copyOf(components); + } + + @Override + public boolean isComponent(Class type) { + return components.contains(type); + } + + @Override + public Optional findService(Class type) { + return Optional.ofNullable(beans.getBeanProvider(type).getIfAvailable()); + } + + @Override + public ViewObject createViewObject(Class type) { + String name = viewBeans.get(type); + if (name == null || !beans.isPrototype(name)) { + throw new IllegalArgumentException("Expected a prototype bean for " + type.getName()); + } + T instance = beans.getBean(name, type); + return new ViewObject<>(instance, () -> beans.destroyBean(name, instance)); + } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/model/Book.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/model/Book.java new file mode 100644 index 0000000..0956cb8 --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/model/Book.java @@ -0,0 +1,33 @@ +package fixture.spring.model; + +import java.util.ArrayList; +import java.util.List; + +public final class Book { + private String name; + private Entry featured; + private List entries = new ArrayList<>(); + + public static Book sample(String name) { + var book = new Book(); + book.setName(name); + var featured = new Entry("Featured"); + featured.setDetail(new Entry("Nested entry")); + book.setFeatured(featured); + book.getEntries().add(new Entry("First entry")); + book.getEntries().add(new Entry("Second entry")); + return book; + } + + public String getName() { return name; } + + public void setName(String name) { this.name = name; } + + public Entry getFeatured() { return featured; } + + public void setFeatured(Entry featured) { this.featured = featured; } + + public List getEntries() { return entries; } + + public void setEntries(List entries) { this.entries = entries; } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/model/Entry.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/model/Entry.java new file mode 100644 index 0000000..8a860b6 --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/model/Entry.java @@ -0,0 +1,18 @@ +package fixture.spring.model; + +public final class Entry { + private String name; + private Entry detail; + + public Entry(String name) { + this.name = name; + } + + public String getName() { return name; } + + public void setName(String name) { this.name = name; } + + public Entry getDetail() { return detail; } + + public void setDetail(Entry detail) { this.detail = detail; } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/BookController.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/BookController.java new file mode 100644 index 0000000..d913e9f --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/BookController.java @@ -0,0 +1,31 @@ +package fixture.spring.ui; + +import fixture.spring.app.FixtureService; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import javafx.fxml.FXML; +import javafx.scene.control.TextField; + +public final class BookController { + private final FixtureService service; + + @FXML + private TextField bookName; + + @Inject + public BookController(FixtureService service) { + this.service = service; + service.created(this); + } + + @FXML + private void initialize() { + bookName.setPromptText(service.label()); + bookName.setUserData(this); + } + + public FixtureService service() { return service; } + + @PreDestroy + public void dispose() { service.release(this); } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/EntryCard.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/EntryCard.java new file mode 100644 index 0000000..02ae7b9 --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/EntryCard.java @@ -0,0 +1,29 @@ +package fixture.spring.ui; + +import fixture.spring.app.FixtureService; +import fixture.spring.model.Entry; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.scene.layout.VBox; + +public final class EntryCard extends VBox { + private final FixtureService service; + private final ObjectProperty model = new SimpleObjectProperty<>(this, "model"); + + @Inject + public EntryCard(FixtureService service) { + this.service = service; + service.created(this); + } + + public ObjectProperty modelProperty() { return model; } + + public Entry getModel() { return model.get(); } + + public void setModel(Entry entry) { model.set(entry); } + + @PreDestroy + public void dispose() { service.release(this); } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/EntryPanel.java b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/EntryPanel.java new file mode 100644 index 0000000..f2f4e6c --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/fixture/spring/ui/EntryPanel.java @@ -0,0 +1,29 @@ +package fixture.spring.ui; + +import fixture.spring.app.FixtureService; +import fixture.spring.model.Entry; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.scene.layout.VBox; + +public final class EntryPanel extends VBox { + private final FixtureService service; + private final ObjectProperty model = new SimpleObjectProperty<>(this, "model"); + + @Inject + public EntryPanel(FixtureService service) { + this.service = service; + service.created(this); + } + + public ObjectProperty modelProperty() { return model; } + + public Entry getModel() { return model.get(); } + + public void setModel(Entry entry) { model.set(entry); } + + @PreDestroy + public void dispose() { service.release(this); } +} diff --git a/integration-fixtures/spring-di/app/src/main/java/module-info.java b/integration-fixtures/spring-di/app/src/main/java/module-info.java new file mode 100644 index 0000000..7df28ec --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/java/module-info.java @@ -0,0 +1,16 @@ +module fixture.spring.app { + requires fx; + requires jakarta.annotation; + requires jakarta.inject; + requires javafx.controls; + requires javafx.fxml; + requires spring.beans; + requires spring.context; + + exports fixture.spring.app; + exports fixture.spring.model; + exports fixture.spring.ui; + + opens fixture.spring.model to fx; + opens fixture.spring.ui; +} diff --git a/integration-fixtures/spring-di/app/src/main/resources/fixture/spring/app/Closed.fxml b/integration-fixtures/spring-di/app/src/main/resources/fixture/spring/app/Closed.fxml new file mode 100644 index 0000000..f4ab74f --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/resources/fixture/spring/app/Closed.fxml @@ -0,0 +1,2 @@ + + diff --git a/integration-fixtures/spring-di/app/src/main/resources/fixture/spring/ui/Book.fxml b/integration-fixtures/spring-di/app/src/main/resources/fixture/spring/ui/Book.fxml new file mode 100644 index 0000000..0f5adb2 --- /dev/null +++ b/integration-fixtures/spring-di/app/src/main/resources/fixture/spring/ui/Book.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + +