diff --git a/.gitignore b/.gitignore index b5a5fe3..1597ed3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ debug.out /nbactions.xml dependency-reduced-pom.xml .DS_Store + +# Machine-local designer paths, snapshots and drafts +.neitzel-fx-designer/ diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..b0b91be --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,17 @@ +# NeitzelLib + +Read README.md and the affected module's README before changes. Use the declared +Java/Maven baseline and the enclosing workspace's checkout/landing policy. + +Prefer Lombok for mechanical getters/setters, constructors and logger declarations +when changing Java code. Use focused annotations that preserve the existing API, +defaults, injection annotations, identity and equality. Keep validation, defensive +copies, JavaFX property operations and lifecycle logic explicit; retain records +and concise interface adapters. `@Data`/`@Value` require an intentional full value +contract, including safe `toString` output. Keep Lombok compile-time-only and +preserve every annotation processor in profile-specific configurations. + +Run affected module tests, including FXML/reflection and generated metadata when +models change. Inspect Surefire XML: the parent currently ignores test failures. +Do not install changed runtime artifacts over a Designer-pinned baseline without +explicitly qualifying and recording the replacement. diff --git a/README.md b/README.md index 28c7897..49c8e34 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Package scanner and type-based container used by `fx`. See [injection/README.md] ### fx-example -Person desk that shows how to use `fx` and `injection`. Run `mvn -pl fx-example -am javafx:run`. See [fx-example/README.md](fx-example/README.md). +Person desk that shows how to use `fx` and `injection`. Build with `./mvnw -pl fx-example -am install`, then run `./mvnw -f fx-example/pom.xml javafx:run`. See [fx-example/README.md](fx-example/README.md). ### gson @@ -69,4 +69,29 @@ Some network stuff using javax.mail as dependency. ### quarkus -Some additions for quarkus that might be useful. \ No newline at end of file +Some additions for quarkus that might be useful. + +## Start a JavaFX project + +The [complete quick start](fx/docs/quick-start.md) includes local snapshot installation, a standalone Maven POM, Java classes, FXML and launch commands. Continue with [MVVM and runtime architecture](fx/docs/architecture.md), the [FXML reference](fx/README.md), and the [person desk walkthrough](fx-example/README.md). The [injection guide](injection/README.md) also covers use without JavaFX. + +Build with Java 21. Maven wrapper version is 3.9.11; the project requires Maven 3.8.6 or later. Library version `1.0-SNAPSHOT` denotes development artifacts, not a published stable release. The parent POM currently ignores Surefire failures: check test reports, as explained in the quick start, rather than relying only on Maven's exit code. + +## Java source conventions + +Use focused Lombok annotations for mechanical accessors, constructors and logging; +see [the contributor instructions](AGENTS.md). The parent already configures +Lombok 1.18.42 as a provided dependency and an explicit annotation processor. +It is not required at runtime. Each checkout has a `lombok.config` boundary so +workstation-level settings cannot silently change generated APIs. + +Keep behavior-bearing methods and JavaFX property operations explicit. Records +remain records, and identity-based Models do not acquire generated equality. +The [Person desk example](fx-example/README.md) demonstrates Lombok JavaBeans +and constructor injection while retaining ordinary JavaBean APIs. + +API documentation runs Lombok's [delombok](https://projectlombok.org/features/delombok) +step at `process-classes` and reads `target/delombok`, including generated methods. +The plugin uses the same `${lombok.version}` as compilation; its output is not +added to the compiler source roots. Run `verify` (or at least `process-classes`) +before invoking standalone Javadoc/site reporting. diff --git a/core/src/main/java/de/neitzel/core/commandline/Parameter.java b/core/src/main/java/de/neitzel/core/commandline/Parameter.java index f2f70bd..a3ce680 100644 --- a/core/src/main/java/de/neitzel/core/commandline/Parameter.java +++ b/core/src/main/java/de/neitzel/core/commandline/Parameter.java @@ -1,14 +1,14 @@ package de.neitzel.core.commandline; +import java.util.List; +import java.util.function.Consumer; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.Setter; import lombok.Singular; import lombok.extern.slf4j.Slf4j; -import java.util.List; -import java.util.function.Consumer; - /** * The `Parameter` class defines a command-line parameter with associated metadata, * such as constraints on the number of values it accepts, descriptions, and aliases. @@ -21,6 +21,7 @@ import java.util.function.Consumer; @Builder @Getter @Setter +@AllArgsConstructor public class Parameter { /** @@ -165,30 +166,4 @@ public class Parameter { public Parameter() { } - /** - * Constructs a new Parameter with the given attributes. - * - * @param name The name of the parameter. - * @param minNumberValues The minimum number of values allowed for this parameter. - * @param maxNumberValues The maximum number of values allowed for this parameter. - * @param multipleEntries Indicates whether multiple entries are allowed for this parameter. - * @param shortDescription A brief description of the parameter. - * @param longDescription A detailed description of the parameter. - * @param callback A consumer function that processes a list of values associated with this parameter. - * @param isHelpCommand Indicates whether this parameter represents a help command. - * @param isDefaultParameter Indicates whether this parameter is the default parameter. - * @param aliasList A list of aliases for this parameter. - */ - public Parameter(String name, int minNumberValues, int maxNumberValues, boolean multipleEntries, String shortDescription, String longDescription, Consumer> callback, boolean isHelpCommand, boolean isDefaultParameter, List aliasList) { - this.name = name; - this.minNumberValues = minNumberValues; - this.maxNumberValues = maxNumberValues; - this.multipleEntries = multipleEntries; - this.shortDescription = shortDescription; - this.longDescription = longDescription; - this.callback = callback; - this.isHelpCommand = isHelpCommand; - this.isDefaultParameter = isDefaultParameter; - this.aliasList = aliasList; - } } diff --git a/core/src/main/java/de/neitzel/core/config/Configuration.java b/core/src/main/java/de/neitzel/core/config/Configuration.java index 010b8e3..07e3629 100644 --- a/core/src/main/java/de/neitzel/core/config/Configuration.java +++ b/core/src/main/java/de/neitzel/core/config/Configuration.java @@ -2,8 +2,6 @@ package de.neitzel.core.config; import de.neitzel.core.io.FileUtils; import de.neitzel.core.util.Strings; -import lombok.extern.slf4j.Slf4j; - import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -14,6 +12,8 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Map; import java.util.Properties; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; /** * Provides a utility class for managing configuration properties in an @@ -22,6 +22,7 @@ import java.util.Properties; * and updating properties. */ @Slf4j +@RequiredArgsConstructor public class Configuration { /** @@ -43,15 +44,6 @@ public class Configuration { this(new Properties()); } - /** - * Constructs a new Configuration instance using the provided properties. - * - * @param properties the Properties object containing configuration key-value pairs - */ - public Configuration(final Properties properties) { - this.properties = properties; - } - /** * Retrieves a boolean property value associated with the specified key. If the key does not exist in the properties, * the provided default value is returned. The method also supports interpreting specific string values as true. diff --git a/core/src/main/java/de/neitzel/core/io/TempDirectory.java b/core/src/main/java/de/neitzel/core/io/TempDirectory.java index f7ea1ed..1e8fb8e 100644 --- a/core/src/main/java/de/neitzel/core/io/TempDirectory.java +++ b/core/src/main/java/de/neitzel/core/io/TempDirectory.java @@ -5,6 +5,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Comparator; import java.util.stream.Stream; +import lombok.Getter; /** * A utility class for creating and managing a temporary directory. @@ -23,6 +24,7 @@ public class TempDirectory implements AutoCloseable { * The directory can be used to safely store temporary runtime files. It is automatically * deleted along with its content when the associated TempDirectory object is closed. */ + @Getter private final Path directory; /** @@ -37,15 +39,6 @@ public class TempDirectory implements AutoCloseable { this.directory = Files.createTempDirectory(prefix); } - /** - * Retrieves the path of the temporary directory associated with this instance. - * - * @return the {@code Path} of the temporary directory - */ - public Path getDirectory() { - return directory; - } - /** * Closes the temporary directory by cleaning up its contents and deleting the directory itself. *

diff --git a/core/src/main/java/de/neitzel/core/sql/Query.java b/core/src/main/java/de/neitzel/core/sql/Query.java index 2974ae1..91c99e3 100644 --- a/core/src/main/java/de/neitzel/core/sql/Query.java +++ b/core/src/main/java/de/neitzel/core/sql/Query.java @@ -1,8 +1,5 @@ package de.neitzel.core.sql; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.PreparedStatement; @@ -19,6 +16,9 @@ import java.util.Spliterators; import java.util.function.Function; import java.util.stream.Stream; import java.util.stream.StreamSupport; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; /** * A generic class for managing SQL queries and their execution using JDBC. @@ -28,6 +28,7 @@ import java.util.stream.StreamSupport; * @param The type of the objects returned by the query. */ @Slf4j +@RequiredArgsConstructor public class Query { /** @@ -74,15 +75,6 @@ public class Query { */ private String queryText; - /** - * Constructs a new Query object with the given database connection. - * - * @param connection The Connection object used to interact with the database. - */ - public Query(Connection connection) { - this.connection = connection; - } - /** * Executes the given SQL query using the provided database connection. * diff --git a/core/src/main/java/de/neitzel/core/sql/TrimmingResultSet.java b/core/src/main/java/de/neitzel/core/sql/TrimmingResultSet.java index eddefb8..e23b9a6 100644 --- a/core/src/main/java/de/neitzel/core/sql/TrimmingResultSet.java +++ b/core/src/main/java/de/neitzel/core/sql/TrimmingResultSet.java @@ -22,6 +22,7 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; import java.util.Map; +import lombok.RequiredArgsConstructor; /** * A wrapper implementation of the {@link ResultSet} interface that modifies or intercepts @@ -31,6 +32,7 @@ import java.util.Map; * If any additional behaviors or transformations are applied, they are documented * in the respective overridden method descriptions. */ +@RequiredArgsConstructor public class TrimmingResultSet implements ResultSet { /** @@ -44,15 +46,6 @@ public class TrimmingResultSet implements ResultSet { */ private final ResultSet resultSet; - /** - * Initializes a new instance of the TrimmingResultSet class, wrapping the provided ResultSet. - * - * @param resultSet the ResultSet to be wrapped and processed by this TrimmingResultSet instance - */ - public TrimmingResultSet(ResultSet resultSet) { - this.resultSet = resultSet; - } - /** * Moves the cursor forward one row from its current position in the ResultSet. * @@ -933,18 +926,6 @@ public class TrimmingResultSet implements ResultSet { return resultSet.getNCharacterStream(columnLabel); } - - - - - - - - - - - - /** * Retrieves the value of the designated column in the current row of this ResultSet object * as an Object in the Java programming language. The value will be converted to the specified @@ -965,8 +946,6 @@ public class TrimmingResultSet implements ResultSet { return resultSet.getObject(columnIndex, map); } - - /** * Retrieves the value of the specified column as a {@link Ref} object. * @@ -979,8 +958,6 @@ public class TrimmingResultSet implements ResultSet { return resultSet.getRef(columnIndex); } - - /** * Retrieves the Blob object designated by the given column index from the current row of the result set. * @@ -993,8 +970,6 @@ public class TrimmingResultSet implements ResultSet { return resultSet.getBlob(columnIndex); } - - /** * Retrieves the CLOB value at the specified column index from the underlying ResultSet. * @@ -1007,8 +982,6 @@ public class TrimmingResultSet implements ResultSet { return resultSet.getClob(columnIndex); } - - /** * Retrieves an SQL Array object from the specified column index * of the current row in the ResultSet. diff --git a/fx-example/README.md b/fx-example/README.md index 2013b0e..591bd0b 100644 --- a/fx-example/README.md +++ b/fx-example/README.md @@ -1,13 +1,100 @@ -# fx-example +# Person desk reference application -A person desk that uses [`fx`](../fx/README.md) and [`injection`](../injection/README.md). The guides use this module as the worked example. +This runnable application demonstrates [NeitzelLib FX](../fx/README.md) and [injection](../injection/README.md) together. It edits one Person with a home Address, nested Note, visit list, selected visit and tags. Use it as a reference for wiring a real screen; the [minimal quick start](../fx/docs/quick-start.md) is the smaller starting point for a new project. -The desk shows a direct binding in each direction, a converter, a computed binding, a view model subclass, a component with a nested note, a repeat, a table with a starting width and an open column, a date column, a list of simple values, and messages. The container side shows `@Config`, `@Singleton`, `@Named`, and injection by constructor, field, and setter. +## Build and run -From the NeitzelLib root, with Java 21: +From the NeitzelLib root with JDK 21: ```bash -mvn -pl fx-example -am javafx:run +./mvnw -pl fx-example -am install +./mvnw -f fx-example/pom.xml javafx:run ``` -The launch class is `de.neitzel.fx.example.Main`. The model is an ordinary `Person`. The view is `Desk.fxml`. `DeskLoadsTest` loads that same desk. +The first command installs local `1.0-SNAPSHOT` artifacts; the second runs only the application module. Do not combine `javafx:run` with `-am`, since the parent has no JavaFX launcher. The repository currently ignores Surefire failures; verify XML reports as shown in the [quick start](../fx/docs/quick-start.md), even when Maven reports success. + +The packaged alternative, after `package` or `install`, is: + +```bash +java -jar fx-example/target/fx-example-1.0-SNAPSHOT.jar +``` + +Keep the adjacent `target/libs` directory with the JAR: the manifest refers to those copied runtime dependencies. A desktop session is required. This example has no `module-info.java`; it is a classpath application. + +## Follow the code + +Paths below are relative to this module. Java sources share `src/main/java/de/neitzel/fx/example/`; FXML resources share `src/main/resources/de/neitzel/fx/example/view/`. + +| File/type | Responsibility | +| --- | --- | +| `Main` | Plain Java launcher calling `Application.launch` | +| `DeskApp` | Scan configuration, fresh sample Model, ViewLoader, Scene and message popup registration | +| `model/Person`, `Address`, `Note`, `Role` | JavaBean data and enum; no JavaFX properties required | +| `view/DeskController` and `Desk.fxml` | Screen handlers, computed greeting, controls and binding declarations | +| `view/PersonViewModel` | Handwritten ViewModel subclass with a derived title | +| `view/AddressForm` and `AddressForm.fxml` | Reusable home subform and injected heading, containing NoteForm | +| `view/NoteForm` and `NoteForm.fxml` | Nested Component bound to the note | +| `view/VisitForm` and `VisitForm.fxml` | Fresh form per repeated Address | +| `view/VisitRow` and `VisitRow.fxml` | Table row with editable fields and a trailing Remove button | +| `src/test/resources/de/neitzel/fx/example/NameLine.fxml` | Test-only second View of the same Person without reusable Component nodes | +| `view/AgeConverter`, `StreetConverter`, `VisitedOnConverter` | Text adaptation, validation failures and ISO dates | + +Use the actual source directories to locate helper services such as `AgeSuffix`, `StreetPolicy` and `FormHeading`. The injection guide explains constructor, field and setter injection with these types. No Designer code generation is required to run this example; `PersonViewModel` is handwritten. + +## Lombok and annotation processing + +`Person`, `Address` and `Note` use `@Getter`/`@Setter` to generate ordinary JavaBean +accessors. Their defaults, mutable lists and object identity are unchanged; no +`@Data` equality or string representation is generated. JavaFX property methods +remain explicit. `AgeConverter` and `VisitRow` use +`@RequiredArgsConstructor(onConstructor_ = @Inject)` so the generated public +constructors retain the injection annotation. + +Lombok is inherited from the parent as a compile-time-only dependency. The +optional `designer-preview` profile explicitly lists **both** Lombok and the +Designer Model metadata processor. Keep both when changing that profile: +metadata discovery must see the generated accessors during compilation. The +normal build needs no Designer processor; Lombok still runs. + +## Try the behaviors + +1. Change Name. The Model and name echo follow; title and computed greeting refresh. The draft field uses `direction="model"`: its edits write to the Model but later changes from another field do not overwrite it. +2. Edit Age using its `years ` text format. An invalid value stays visible while the previous Model value is retained. A message explains the failure; a valid value clears that conversion failure. +3. Edit the home street. The path-bound label follows. Empty street input fails through `StreetConverter`; the parent receives the child message with the `home.street` source prefix. +4. Edit the nested note. AddressForm's inner NoteForm binds to its own Model. The `Opened as ...` label records initial setup rather than tracking every later city edit. +5. Add a visit. Both the repeated forms and Table gain a row. Edit a street in one representation and observe the same Address in the other. The Table's Remove button delegates to the controller. +6. Select a visit in the ComboBox or Table. Both use the `selectedVisit` Attribute. Resize, sort and filter Table columns; filtering and sorting affect displayed rows without reordering the Model's list. +7. Edit the visited date in ISO form (`yyyy-MM-dd`). Invalid text keeps the old date. Add a tag to see a shared ObservableList of simple values. +8. Try the information, warning and fatal message buttons. Severity is data and logging behavior; a fatal message does not itself exit the application. Close each non-blocking popup normally. + +Changing a JavaBean setter directly after loading does not notify controls. All edits above go through ViewModel properties or observable collections. The [architecture guide](../fx/docs/architecture.md) explains this distinction and why you should normally use a new context for a separate window. + +## Automated regression coverage + +`src/test/java/de/neitzel/fx/example/DeskLoadsTest.java` loads the real Desk FXML on JavaFX and checks initial values, all binding directions, derived/computed text, conversion failures and recovery, child messages, Table edits/removal, message severities and boolean/enum write-back. It also demonstrates that a direct bean setter leaves controls unchanged and that another simple View reuses the same Model's ViewModel. + +Run the reactor tests without installing artifacts with: + +```bash +./mvnw -pl fx-example -am clean verify +``` + +Inspect Surefire XML reports; a successful Maven exit alone is insufficient with the current parent configuration. JavaFX tests need a usable graphical environment. See the Designer integration section below for the optional preview setup; ordinary application tests do not require the Designer. + +## Open the example in NeitzelFXDesigner + +The repository root includes `neitzel-fx-designer.json` with the `person-desk` context. It selects `fx-example`, classpath launch, the `designer-preview` Maven profile, the local runtime key `java21`, and `de.neitzel.fx.example.preview.DeskPreviewProvider`. Configure your own JDK path for that key; machine paths are not part of the shared project configuration. + +The optional profile adds the Designer preview API only to the test source set, compiles `src/designer/java`, includes its resources, and produces Model metadata for Person, Address and Note. It does not add a runtime dependency to the ordinary application, replace its handwritten PersonViewModel, or generate a default ViewModel registry. + +After preparing the Designer's local preview API and metadata processor artifacts, build with: + +```bash +./mvnw -pl fx-example -am -Pdesigner-preview verify +``` + +Check XML test reports as for the normal build. Follow `docs/user-guide/quick-start.md` in the [NeitzelFXDesigner repository](https://gitea.neitzel.de/konrad/NeitzelFXDesigner) for the complete artifact preparation, library-example setup script, local runtime mapping, application launch and Build and Refresh workflow. That guide covers both the standalone host and IntelliJ integration; this profile alone is not a Designer installation. + +FXML documents carry `neitzel-model` processing instructions for discovery. The preview provider offers `desk`, `address`, `visit`, `row` and `note` samples for the corresponding documents. Every session receives fresh sample Models and an injection context; the preview does not install the application's message popups. Open the document, Build and Refresh, choose its matching sample, then start interactive preview. Editing the preview's data does not save those values into the application source. + +The role choices are populated in `DeskController.initialize()` rather than using an application-enum `fx:constant` in FXML, because the current Designer projection cannot resolve that application constant. This is a Designer limitation, not a restriction of NeitzelLib or ordinary FXMLLoader. The regular application still shows the same Role values. diff --git a/fx-example/pom.xml b/fx-example/pom.xml index aa380e5..c4a56c0 100644 --- a/fx-example/pom.xml +++ b/fx-example/pom.xml @@ -36,14 +36,6 @@ ${jar.filename} - - org.apache.maven.plugins - maven-compiler-plugin - - - none - - org.openjfx javafx-maven-plugin @@ -97,4 +89,59 @@ + + + designer-preview + + + de.neitzel.fxdesigner + designer-preview-api + 0.1.0-SNAPSHOT + test + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.1 + + + designer-preview-sources + generate-test-sources + add-test-sourceadd-test-resource + + src/designer/java + src/designer/resources + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + full + + + org.projectlombok + lombok + ${lombok.version} + + + de.neitzel.fxdesigner + designer-model-processor + 0.1.0-SNAPSHOT + + + + -Adesigner.models=de.neitzel.fx.example.model.Person,de.neitzel.fx.example.model.Address,de.neitzel.fx.example.model.Note + + + + + + + diff --git a/fx-example/src/designer/java/de/neitzel/fx/example/preview/AddressPreviewProvider.java b/fx-example/src/designer/java/de/neitzel/fx/example/preview/AddressPreviewProvider.java new file mode 100644 index 0000000..3e7170d --- /dev/null +++ b/fx-example/src/designer/java/de/neitzel/fx/example/preview/AddressPreviewProvider.java @@ -0,0 +1,31 @@ +package de.neitzel.fx.example.preview; + +import de.neitzel.fx.example.DeskApp; +import de.neitzel.fx.example.model.Address; +import de.neitzel.fx.example.view.DeskController; +import de.neitzel.fx.example.view.PersonViewModel; +import de.neitzel.fxdesigner.preview.PreviewProvider; +import de.neitzel.fxdesigner.preview.PreviewSession; +import de.neitzel.injection.ApplicationContext; + +/** Independent samples for the nested, repeated and table-row Address components. */ +public final class AddressPreviewProvider implements PreviewProvider { + @Override + public Class

modelType() { + return Address.class; + } + + @Override + public PreviewSession open(String id) { + if (!java.util.Set.of("address", "visit", "row").contains(id)) + throw new IllegalArgumentException("Unknown address example: " + id); + var person = DeskApp.sample(); + var context = new ApplicationContext(DeskApp.class); + // An independently previewed row still needs the parent action's state. + // No Desk.fxml is loaded and no popup listener is installed. + if ("row".equals(id)) + context.getComponent(DeskController.class).setViewModel(new PersonViewModel(person)); + return new SampleSession<>( + "address".equals(id) ? person.getHome() : person.getVisits().getFirst(), context); + } +} diff --git a/fx-example/src/designer/java/de/neitzel/fx/example/preview/DeskPreviewProvider.java b/fx-example/src/designer/java/de/neitzel/fx/example/preview/DeskPreviewProvider.java new file mode 100644 index 0000000..a3811fe --- /dev/null +++ b/fx-example/src/designer/java/de/neitzel/fx/example/preview/DeskPreviewProvider.java @@ -0,0 +1,21 @@ +package de.neitzel.fx.example.preview; + +import de.neitzel.fx.example.DeskApp; +import de.neitzel.fx.example.model.Person; +import de.neitzel.fxdesigner.preview.PreviewProvider; +import de.neitzel.fxdesigner.preview.PreviewSession; +import de.neitzel.injection.ApplicationContext; + +/** Optional test-source preview adapter; it never enters the application distribution. */ +public final class DeskPreviewProvider implements PreviewProvider { + @Override + public Class modelType() { + return Person.class; + } + + @Override + public PreviewSession open(String id) { + if (!"desk".equals(id)) throw new IllegalArgumentException("Unknown desk example: " + id); + return new SampleSession<>(DeskApp.sample(), new ApplicationContext(DeskApp.class)); + } +} diff --git a/fx-example/src/designer/java/de/neitzel/fx/example/preview/NotePreviewProvider.java b/fx-example/src/designer/java/de/neitzel/fx/example/preview/NotePreviewProvider.java new file mode 100644 index 0000000..23db4f4 --- /dev/null +++ b/fx-example/src/designer/java/de/neitzel/fx/example/preview/NotePreviewProvider.java @@ -0,0 +1,22 @@ +package de.neitzel.fx.example.preview; + +import de.neitzel.fx.example.DeskApp; +import de.neitzel.fx.example.model.Note; +import de.neitzel.fxdesigner.preview.PreviewProvider; +import de.neitzel.fxdesigner.preview.PreviewSession; +import de.neitzel.injection.ApplicationContext; + +/** Independent sample for the nested note editor. */ +public final class NotePreviewProvider implements PreviewProvider { + @Override + public Class modelType() { + return Note.class; + } + + @Override + public PreviewSession open(String id) { + if (!"note".equals(id)) throw new IllegalArgumentException("Unknown note example: " + id); + return new SampleSession<>( + DeskApp.sample().getHome().getNote(), new ApplicationContext(DeskApp.class)); + } +} diff --git a/fx-example/src/designer/java/de/neitzel/fx/example/preview/PreviewProvidersTest.java b/fx-example/src/designer/java/de/neitzel/fx/example/preview/PreviewProvidersTest.java new file mode 100644 index 0000000..2c3daa2 --- /dev/null +++ b/fx-example/src/designer/java/de/neitzel/fx/example/preview/PreviewProvidersTest.java @@ -0,0 +1,86 @@ +package de.neitzel.fx.example.preview; + +import static org.junit.jupiter.api.Assertions.*; + +import de.neitzel.fx.example.view.DeskController; +import de.neitzel.fx.view.ViewLoader; + +import javafx.application.Platform; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.*; + +class PreviewProvidersTest { + @BeforeAll + static void startToolkit() throws Exception { + var ready = new CountDownLatch(1); + try { + Platform.startup(ready::countDown); + } catch (IllegalStateException alreadyRunning) { + ready.countDown(); + } + assertTrue(ready.await(10, TimeUnit.SECONDS)); + } + + private static void onFx(Runnable action) throws Exception { + var result = new CompletableFuture(); + Platform.runLater( + () -> { + try { + action.run(); + result.complete(null); + } catch (Throwable e) { + result.completeExceptionally(e); + } + }); + result.get(20, TimeUnit.SECONDS); + } + + @Test + void deskSamplesAreFreshAndLoadTheRealDesk() throws Exception { + onFx( + () -> { + var provider = new DeskPreviewProvider(); + var first = provider.open("desk"); + var second = provider.open("desk"); + assertNotSame(first.model(), second.model()); + assertNotSame(first.model().getHome(), second.model().getHome()); + assertNotSame(first.context(), second.context()); + var view = + ViewLoader.load( + DeskController.class.getResource("Desk.fxml"), + first.model(), + first.context()); + assertNotNull(view.getRoot().lookup("#nameField")); + assertEquals("Ada Lovelace", first.model().getName()); + assertTrue(first.ready().toCompletableFuture().isDone()); + assertThrows(IllegalArgumentException.class, () -> provider.open("unknown")); + }); + } + + @Test + void componentSamplesAndIndependentRowActionHaveRequiredState() throws Exception { + onFx( + () -> { + var addresses = new AddressPreviewProvider(); + var home = addresses.open("address"); + assertNotNull(home.model().getNote()); + var visit = addresses.open("visit"); + assertNotNull(visit.model().getVisitedOn()); + var row = addresses.open("row"); + assertDoesNotThrow( + () -> + row.context() + .getComponent(DeskController.class) + .removeVisit(row.model())); + var note = new NotePreviewProvider().open("note"); + assertEquals("Kept at home", note.model().getText()); + assertThrows(IllegalArgumentException.class, () -> addresses.open("desk")); + assertThrows( + IllegalArgumentException.class, + () -> new NotePreviewProvider().open("desk")); + }); + } +} diff --git a/fx-example/src/designer/java/de/neitzel/fx/example/preview/SampleSession.java b/fx-example/src/designer/java/de/neitzel/fx/example/preview/SampleSession.java new file mode 100644 index 0000000..8e29aa7 --- /dev/null +++ b/fx-example/src/designer/java/de/neitzel/fx/example/preview/SampleSession.java @@ -0,0 +1,11 @@ +package de.neitzel.fx.example.preview; + +import de.neitzel.fxdesigner.preview.PreviewSession; +import de.neitzel.injection.ApplicationContext; + +/** The sample owns no timers, network connections or background work to release. */ +record SampleSession(M model, ApplicationContext context) + implements PreviewSession { + @Override + public void close() {} +} diff --git a/fx-example/src/designer/resources/META-INF/neitzel-fx-designer/examples.properties b/fx-example/src/designer/resources/META-INF/neitzel-fx-designer/examples.properties new file mode 100644 index 0000000..a34ff5d --- /dev/null +++ b/fx-example/src/designer/resources/META-INF/neitzel-fx-designer/examples.properties @@ -0,0 +1,37 @@ +format=1 +count=5 +example.0.id=desk +example.0.label=Person desk +example.0.modelType=de.neitzel.fx.example.model.Person +example.0.providerClass=de.neitzel.fx.example.preview.DeskPreviewProvider +example.0.viewResource=de/neitzel/fx/example/view/Desk.fxml +example.0.componentPackage=de.neitzel.fx.example.view + +example.1.id=address +example.1.label=Home address +example.1.modelType=de.neitzel.fx.example.model.Address +example.1.providerClass=de.neitzel.fx.example.preview.AddressPreviewProvider +example.1.viewResource=de/neitzel/fx/example/view/AddressForm.fxml +example.1.componentPackage=de.neitzel.fx.example.view + +example.2.id=visit +example.2.label=Repeated visit +example.2.modelType=de.neitzel.fx.example.model.Address +example.2.providerClass=de.neitzel.fx.example.preview.AddressPreviewProvider +example.2.viewResource=de/neitzel/fx/example/view/VisitForm.fxml +example.2.componentPackage=de.neitzel.fx.example.view + +example.3.id=row +example.3.label=Table row +example.3.modelType=de.neitzel.fx.example.model.Address +example.3.providerClass=de.neitzel.fx.example.preview.AddressPreviewProvider +example.3.viewResource=de/neitzel/fx/example/view/VisitRow.fxml +example.3.componentPackage=de.neitzel.fx.example.view + +example.4.id=note +example.4.label=Address note +example.4.modelType=de.neitzel.fx.example.model.Note +example.4.providerClass=de.neitzel.fx.example.preview.NotePreviewProvider +example.4.viewResource=de/neitzel/fx/example/view/NoteForm.fxml +example.4.componentPackage=de.neitzel.fx.example.view + diff --git a/fx-example/src/main/java/de/neitzel/fx/example/model/Address.java b/fx-example/src/main/java/de/neitzel/fx/example/model/Address.java index 17eb8d0..64d2988 100644 --- a/fx-example/src/main/java/de/neitzel/fx/example/model/Address.java +++ b/fx-example/src/main/java/de/neitzel/fx/example/model/Address.java @@ -1,10 +1,14 @@ package de.neitzel.fx.example.model; import java.time.LocalDate; +import lombok.Getter; +import lombok.Setter; /** * An ordinary address the desk edits. */ +@Getter +@Setter public class Address { /** @@ -44,78 +48,6 @@ public class Address { this.city = city; } - /** - * Returns the street. - * - * @return the street - */ - public String getStreet() { - return street; - } - - /** - * Sets the street. - * - * @param street the street - */ - public void setStreet(String street) { - this.street = street; - } - - /** - * Returns the city. - * - * @return the city - */ - public String getCity() { - return city; - } - - /** - * Sets the city. - * - * @param city the city - */ - public void setCity(String city) { - this.city = city; - } - - /** - * Returns the day of the visit. - * - * @return the date, or {@code null} when none is set - */ - public LocalDate getVisitedOn() { - return visitedOn; - } - - /** - * Sets the day of the visit. - * - * @param visitedOn the date, or {@code null} to clear it - */ - public void setVisitedOn(LocalDate visitedOn) { - this.visitedOn = visitedOn; - } - - /** - * Returns the note attached to this address. - * - * @return the note, or {@code null} when none is set - */ - public Note getNote() { - return note; - } - - /** - * Sets the note attached to this address. - * - * @param note the note, or {@code null} when there is none - */ - public void setNote(Note note) { - this.note = note; - } - /** * Returns the street and city, for a combo box row. * diff --git a/fx-example/src/main/java/de/neitzel/fx/example/model/Note.java b/fx-example/src/main/java/de/neitzel/fx/example/model/Note.java index 5d87220..90fddb8 100644 --- a/fx-example/src/main/java/de/neitzel/fx/example/model/Note.java +++ b/fx-example/src/main/java/de/neitzel/fx/example/model/Note.java @@ -1,11 +1,16 @@ package de.neitzel.fx.example.model; +import lombok.Getter; +import lombok.Setter; + /** * A short note attached to an address. *

* The class is a complex attribute of {@link Address}: it has a read-write property of its own. * The home address form nests a component that edits this note. */ +@Getter +@Setter public class Note { /** @@ -28,21 +33,4 @@ public class Note { this.text = text; } - /** - * Returns the note text. - * - * @return the text - */ - public String getText() { - return text; - } - - /** - * Sets the note text. - * - * @param text the text - */ - public void setText(String text) { - this.text = text; - } } diff --git a/fx-example/src/main/java/de/neitzel/fx/example/model/Person.java b/fx-example/src/main/java/de/neitzel/fx/example/model/Person.java index 49fe640..48dab69 100644 --- a/fx-example/src/main/java/de/neitzel/fx/example/model/Person.java +++ b/fx-example/src/main/java/de/neitzel/fx/example/model/Person.java @@ -2,12 +2,16 @@ package de.neitzel.fx.example.model; import java.util.ArrayList; import java.util.List; +import lombok.Getter; +import lombok.Setter; /** * An ordinary person the desk edits. *

* Read-write attributes are what the View binds to. The class carries no JavaFX types. */ +@Getter +@Setter public class Person { /** @@ -56,151 +60,4 @@ public class Person { public Person() { } - /** - * Returns the name. - * - * @return the name - */ - public String getName() { - return name; - } - - /** - * Sets the name. - * - * @param name the name - */ - public void setName(String name) { - this.name = name; - } - - /** - * Returns the age in years. - * - * @return the age, or {@code null} when none is set - */ - public Integer getAge() { - return age; - } - - /** - * Sets the age in years. - * - * @param age the age - */ - public void setAge(Integer age) { - this.age = age; - } - - /** - * Returns the home address. - * - * @return the home address, or {@code null} when none is set - */ - public Address getHome() { - return home; - } - - /** - * Sets the home address. - * - * @param home the home address - */ - public void setHome(Address home) { - this.home = home; - } - - /** - * Returns the visits. - *

- * After the View has loaded, this is the list the View is watching. - * - * @return the visits - */ - public List

getVisits() { - return visits; - } - - /** - * Sets the visits. - * - * @param visits the visits - */ - public void setVisits(List
visits) { - this.visits = visits; - } - - /** - * Returns the visit chosen in the table and the combo box. - * - * @return the selected visit, or {@code null} when none is selected - */ - public Address getSelectedVisit() { - return selectedVisit; - } - - /** - * Sets the visit chosen in the table and the combo box. - * - * @param selectedVisit the selected visit - */ - public void setSelectedVisit(Address selectedVisit) { - this.selectedVisit = selectedVisit; - } - - /** - * Returns the tags. - *

- * After the View has loaded, this is the list the View is watching. - * - * @return the tags - */ - public List getTags() { - return tags; - } - - /** - * Sets the tags. - * - * @param tags the tags - */ - public void setTags(List tags) { - this.tags = tags; - } - - /** - * Returns whether the person is active. - * - * @return {@code true} when the person is active - */ - public boolean isActive() { - return active; - } - - /** - * Sets whether the person is active. - * - * @param active {@code true} when the person is active - */ - public void setActive(boolean active) { - this.active = active; - } - - /** - * Returns the role. - * - * @return the role, or {@code null} when none is set - */ - public Role getRole() { - return role; - } - - /** - * Sets the role. - * - * @param role the role - */ - public void setRole(Role role) { - this.role = role; - } } diff --git a/fx-example/src/main/java/de/neitzel/fx/example/view/AgeConverter.java b/fx-example/src/main/java/de/neitzel/fx/example/view/AgeConverter.java index c6f3274..210588f 100644 --- a/fx-example/src/main/java/de/neitzel/fx/example/view/AgeConverter.java +++ b/fx-example/src/main/java/de/neitzel/fx/example/view/AgeConverter.java @@ -3,11 +3,13 @@ package de.neitzel.fx.example.view; import de.neitzel.fx.view.Converter; import jakarta.inject.Inject; import jakarta.inject.Singleton; +import lombok.RequiredArgsConstructor; /** * Translates an age between the Model and the text field. */ @Singleton +@RequiredArgsConstructor(onConstructor_ = @Inject) public class AgeConverter implements Converter { /** @@ -15,16 +17,6 @@ public class AgeConverter implements Converter { */ private final AgeSuffix suffix; - /** - * Creates a converter that reads its suffix from the injected service. - * - * @param suffix the suffix written in front of the age - */ - @Inject - public AgeConverter(AgeSuffix suffix) { - this.suffix = suffix; - } - /** * Writes the suffix in front of the age. * diff --git a/fx-example/src/main/java/de/neitzel/fx/example/view/DeskController.java b/fx-example/src/main/java/de/neitzel/fx/example/view/DeskController.java index faade7b..fc4b2a9 100644 --- a/fx-example/src/main/java/de/neitzel/fx/example/view/DeskController.java +++ b/fx-example/src/main/java/de/neitzel/fx/example/view/DeskController.java @@ -1,6 +1,7 @@ package de.neitzel.fx.example.view; import de.neitzel.fx.example.model.Address; +import de.neitzel.fx.example.model.Role; import de.neitzel.fx.view.HasViewModel; import de.neitzel.fx.view.Message; import de.neitzel.fx.view.ViewModel; @@ -8,6 +9,7 @@ import de.neitzel.fx.view.ViewModelClass; import jakarta.inject.Singleton; import javafx.fxml.FXML; import javafx.scene.control.TextField; +import javafx.scene.control.ChoiceBox; import java.time.LocalDate; import java.util.List; @@ -35,6 +37,16 @@ public class DeskController implements HasViewModel { @FXML private TextField tagField; + /** Role values are supplied in the application runtime, not instantiated by the designer host. */ + @FXML + private ChoiceBox roleChoice; + + /** Supplies enum choices before the declarative value binding is applied. */ + @FXML + public void initialize() { + roleChoice.getItems().setAll(Role.values()); + } + /** * The person view model, set before the bindings run. */ diff --git a/fx-example/src/main/java/de/neitzel/fx/example/view/VisitRow.java b/fx-example/src/main/java/de/neitzel/fx/example/view/VisitRow.java index d0a2275..78e0926 100644 --- a/fx-example/src/main/java/de/neitzel/fx/example/view/VisitRow.java +++ b/fx-example/src/main/java/de/neitzel/fx/example/view/VisitRow.java @@ -7,6 +7,7 @@ import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.fxml.FXML; import javafx.scene.layout.HBox; +import lombok.RequiredArgsConstructor; /** * Row that edits one visit in the visit table. @@ -16,6 +17,7 @@ import javafx.scene.layout.HBox; * order: street, city, then the visit date. Remove sits after them and is not a column. */ @Singleton +@RequiredArgsConstructor(onConstructor_ = @Inject) public class VisitRow extends HBox { /** @@ -28,16 +30,6 @@ public class VisitRow extends HBox { */ private final ObjectProperty model = new SimpleObjectProperty<>(this, "model"); - /** - * Creates a row that can remove its visit. - * - * @param desk the desk controller - */ - @Inject - public VisitRow(DeskController desk) { - this.desk = desk; - } - /** * Returns the model property the table sets. * diff --git a/fx-example/src/main/resources/de/neitzel/fx/example/view/AddressForm.fxml b/fx-example/src/main/resources/de/neitzel/fx/example/view/AddressForm.fxml index 76862bf..7721f0f 100644 --- a/fx-example/src/main/resources/de/neitzel/fx/example/view/AddressForm.fxml +++ b/fx-example/src/main/resources/de/neitzel/fx/example/view/AddressForm.fxml @@ -1,4 +1,5 @@ + @@ -9,7 +10,7 @@ + xmlns:fx="http://javafx.com/fxml/1" spacing="6"> diff --git a/fx-example/src/main/resources/de/neitzel/fx/example/view/Desk.fxml b/fx-example/src/main/resources/de/neitzel/fx/example/view/Desk.fxml index 5f356c7..67caff1 100644 --- a/fx-example/src/main/resources/de/neitzel/fx/example/view/Desk.fxml +++ b/fx-example/src/main/resources/de/neitzel/fx/example/view/Desk.fxml @@ -1,6 +1,6 @@ + - @@ -13,7 +13,6 @@ - @@ -22,7 +21,7 @@ - @@ -70,14 +69,7 @@