Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ff9753de8 | ||
|
|
a3f7d2423f | ||
|
|
981cd68f49 | ||
|
|
e915ed392f | ||
|
|
8aefe53ad1 | ||
|
|
12aad4d3a1 | ||
|
|
fba2735e1e | ||
|
|
17c36ccae7 | ||
|
|
42c1ee19a1 | ||
|
|
dcd26a088f |
@@ -84,6 +84,12 @@ The [complete quick start](fx/docs/quick-start.md) includes local installation,
|
|||||||
|
|
||||||
Build with Java 25. Maven wrapper version is 3.9.11; the project requires Maven 3.9.11 or later. Surefire fails the build if tests fail.
|
Build with Java 25. Maven wrapper version is 3.9.11; the project requires Maven 3.9.11 or later. Surefire fails the build if tests fail.
|
||||||
|
|
||||||
|
## Changes in 1.0.4
|
||||||
|
|
||||||
|
- Show or hide DataGrid columns from the header checklist or context menu while retaining column order and widths.
|
||||||
|
- Observe column visibility changes from applications that store their own view preferences.
|
||||||
|
- Use reusable action icons with tooltips and accessible names in JavaFX controls.
|
||||||
|
|
||||||
## Changes in 1.0.2
|
## Changes in 1.0.2
|
||||||
|
|
||||||
- Display saved HTML and SingleFile archives offline with [HtmlViewer](fx/docs/html-viewer.md). Each viewer can grant external image access for its current document.
|
- Display saved HTML and SingleFile archives offline with [HtmlViewer](fx/docs/html-viewer.md). Each viewer can grant external image access for its current document.
|
||||||
@@ -93,7 +99,7 @@ Build with Java 25. Maven wrapper version is 3.9.11; the project requires Maven
|
|||||||
|
|
||||||
## Use a release from Maven
|
## Use a release from Maven
|
||||||
|
|
||||||
To use release `1.0.2`, add the Gitea registry to the consuming project's POM and use the release
|
To use release `1.0.4`, add the Gitea registry to the consuming project's POM and use the release
|
||||||
version for the module you need:
|
version for the module you need:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
@@ -108,7 +114,7 @@ version for the module you need:
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>fx</artifactId>
|
<artifactId>fx</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
```
|
```
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>core</artifactId>
|
<artifactId>core</artifactId>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion><parent><groupId>de.neitzel.lib</groupId><artifactId>neitzellib</artifactId><version>1.0.2</version></parent>
|
<modelVersion>4.0.0</modelVersion><parent><groupId>de.neitzel.lib</groupId><artifactId>neitzellib</artifactId><version>1.0.4</version></parent>
|
||||||
<artifactId>data-grid-jdbc</artifactId><description>Optional mapped JDBC grid source</description>
|
<artifactId>data-grid-jdbc</artifactId><description>Optional mapped JDBC grid source</description>
|
||||||
<dependencies><dependency><groupId>de.neitzel.lib</groupId><artifactId>data-grid</artifactId><version>${project.version}</version></dependency>
|
<dependencies><dependency><groupId>de.neitzel.lib</groupId><artifactId>data-grid</artifactId><version>${project.version}</version></dependency>
|
||||||
<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><version>2.5.252</version><scope>test</scope></dependency></dependencies></project>
|
<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><version>2.5.252</version><scope>test</scope></dependency></dependencies></project>
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent><groupId>de.neitzel.lib</groupId><artifactId>neitzellib</artifactId><version>1.0.2</version></parent>
|
<parent><groupId>de.neitzel.lib</groupId><artifactId>neitzellib</artifactId><version>1.0.4</version></parent>
|
||||||
<artifactId>data-grid</artifactId>
|
<artifactId>data-grid</artifactId>
|
||||||
<description>Toolkit-independent filter, query and grid setup contracts</description>
|
<description>Toolkit-independent filter, query and grid setup contracts</description>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>encryption</artifactId>
|
<artifactId>encryption</artifactId>
|
||||||
|
|||||||
@@ -30,12 +30,12 @@ From the NeitzelLib root with JDK 25:
|
|||||||
./mvnw -f fx-example/pom.xml javafx:run
|
./mvnw -f fx-example/pom.xml javafx:run
|
||||||
```
|
```
|
||||||
|
|
||||||
The first command installs local `1.0.2` artifacts; the second runs only the application module. Do not combine `javafx:run` with `-am`, since the parent has no JavaFX launcher. See the [quick start](../fx/docs/quick-start.md) for test reports.
|
The first command installs local `1.0.4` artifacts; the second runs only the application module. Do not combine `javafx:run` with `-am`, since the parent has no JavaFX launcher. See the [quick start](../fx/docs/quick-start.md) for test reports.
|
||||||
|
|
||||||
The packaged alternative, after `package` or `install`, is:
|
The packaged alternative, after `package` or `install`, is:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
java -jar fx-example/target/fx-example-1.0.2.jar
|
java -jar fx-example/target/fx-example-1.0.4.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.
|
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.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ From the repository root with JDK 25, build without installing runtime artifacts
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
./mvnw -pl fx-example -am package -DskipTests
|
./mvnw -pl fx-example -am package -DskipTests
|
||||||
java -cp 'fx-example/target/fx-example-1.0.2.jar:fx-example/target/libs/*' de.neitzel.fx.example.grid.ProductGridMain
|
java -cp 'fx-example/target/fx-example-1.0.4.jar:fx-example/target/libs/*' de.neitzel.fx.example.grid.ProductGridMain
|
||||||
```
|
```
|
||||||
|
|
||||||
The default catalog has 10,000 products. Both backends use identical stable IDs, names, categories, quantities and DECIMAL(12,2) prices. Fixtures include duplicate sort values, nulls, empty text, mixed case, Unicode, apostrophes and literal SQL wildcard characters. One `ProductCatalog` service maintains original text and Locale.ROOT comparison keys together on insertion/reset. Mutations run on application workers and explicitly refresh the grid; browsing is read-only.
|
The default catalog has 10,000 products. Both backends use identical stable IDs, names, categories, quantities and DECIMAL(12,2) prices. Fixtures include duplicate sort values, nulls, empty text, mixed case, Unicode, apostrophes and literal SQL wildcard characters. One `ProductCatalog` service maintains original text and Locale.ROOT comparison keys together on insertion/reset. Mutations run on application workers and explicitly refresh the grid; browsing is read-only.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
After the reactor `verify` or `package` build, from the repository root (no local artifact install required):
|
After the reactor `verify` or `package` build, from the repository root (no local artifact install required):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
java -cp 'fx-example/target/fx-example-1.0.2.jar:fx-example/target/libs/*' \
|
java -cp 'fx-example/target/fx-example-1.0.4.jar:fx-example/target/libs/*' \
|
||||||
de.neitzel.fx.example.theme.ThemeGalleryMain
|
de.neitzel.fx.example.theme.ThemeGalleryMain
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>fx-example</artifactId>
|
<artifactId>fx-example</artifactId>
|
||||||
|
|||||||
+79
-5
@@ -56,7 +56,7 @@ These are the versions configured by this source snapshot, not a promise of comp
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| JDK | Java 25 | Select a matching JDK for compilation and launch |
|
| JDK | Java 25 | Select a matching JDK for compilation and launch |
|
||||||
| Maven | Minimum 3.9.11; wrapper 3.9.11 | Use the wrapper or an installed Maven |
|
| Maven | Minimum 3.9.11; wrapper 3.9.11 | Use the wrapper or an installed Maven |
|
||||||
| Library | `de.neitzel.lib:fx:1.0.2` | Use the Gitea Maven registry or install the local reactor |
|
| Library | `de.neitzel.lib:fx:1.0.4` | Use the Gitea Maven registry or install the local reactor |
|
||||||
| Internal modules | `fx` directly depends on `core`, `injection` and toolkit-independent `data-grid` | Resolved transitively through Maven |
|
| Internal modules | `fx` directly depends on `core`, `injection` and toolkit-independent `data-grid` | Resolved transitively through Maven |
|
||||||
| JavaFX | 27.0.1: base, graphics, controls, FXML and web | Resolved transitively; deployment still needs platform-native artifacts |
|
| JavaFX | 27.0.1: base, graphics, controls, FXML and web | Resolved transitively; deployment still needs platform-native artifacts |
|
||||||
| Saved HTML | jsoup 1.23.2, ph-css 8.2.3, TwelveMonkeys WebP 3.15.3 | Resolved transitively by `fx`; no separate application setup |
|
| Saved HTML | jsoup 1.23.2, ph-css 8.2.3, TwelveMonkeys WebP 3.15.3 | Resolved transitively by `fx`; no separate application setup |
|
||||||
@@ -171,7 +171,7 @@ A direct binding names a control by `fx:id`, a JavaFX property of that control,
|
|||||||
|
|
||||||
For `both` and `model`, the write happens when the JavaFX property changes, including each change of a text property. There is no separate save. `view` does not write the attribute.
|
For `both` and `model`, the write happens when the JavaFX property changes, including each change of a text property. There is no separate save. `view` does not write the attribute.
|
||||||
|
|
||||||
`BindingList` is the element that holds direct bindings, computed bindings, and repeats. Its default property is `elements`, so the children in FXML are the list. An unknown child fails the load with `Not a binding element:`. The children that apply are a direct binding, a computed binding, and a repeat.
|
`BindingList` is the element that holds direct bindings, computed bindings, command bindings, and repeats. Its default property is `elements`, so the children in FXML are the list. An unknown child fails the load with `Not a binding element:`. Command bindings require a managed View.
|
||||||
|
|
||||||
When the attribute value is already an `ObservableList`, the control property is set to that same list. Direction and converter are not consulted. The tag binding names `direction="view"` and still shares the list. See [A list of simple values](#a-list-of-simple-values).
|
When the attribute value is already an `ObservableList`, the control property is set to that same list. Direction and converter are not consulted. The tag binding names `direction="view"` and still shares the list. See [A list of simple values](#a-list-of-simple-values).
|
||||||
|
|
||||||
@@ -185,6 +185,21 @@ A binding that names no such control fails with `No control "` and the id. A mis
|
|||||||
| `view` | Shows the attribute and follows later changes of the JavaFX property. Edits to the control stay on the control. |
|
| `view` | Shows the attribute and follows later changes of the JavaFX property. Edits to the control stay on the control. |
|
||||||
| `model` | Shows the current value, writes the attribute when the control changes, and leaves the control where it is when the attribute changes later. |
|
| `model` | Shows the current value, writes the attribute when the control changes, and leaves the control where it is when the attribute changes later. |
|
||||||
|
|
||||||
|
For `view`, a public `xxxProperty()` accessor on the ViewModel or its replacement can
|
||||||
|
return an `ObservableValue`, such as a `ReadOnlyStringProperty` or a `BooleanBinding`.
|
||||||
|
The value is read once at load and then followed as the observable changes. For a computed
|
||||||
|
value, declare its dependencies in JavaFX. The example connects the derived
|
||||||
|
`saveDisabledProperty()` to a button.
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<DirectBinding control="save" property="disable" path="saveDisabled" direction="view"/>
|
||||||
|
```
|
||||||
|
|
||||||
|
`both` and `model` require an accessor that exposes a writable `Property`. The error for
|
||||||
|
a read-only source gives the path, target control and property, and FXML resource.
|
||||||
|
`ViewModel.property(name)` and `LoadedView.property(name)` continue to look up writable
|
||||||
|
properties.
|
||||||
|
|
||||||
The desk puts all three on `name`. The name field is `both`. Shown name (`nameEcho`) is `view`: typing there leaves `Person.name` and the name field unchanged, and typing in the name field updates the echo. Name draft (`nameDraft`) is `model`: it opens as `Ada Lovelace`, stays there while the name field changes, and typing in the draft writes `Person.name` and updates the name field and the echo.
|
The desk puts all three on `name`. The name field is `both`. Shown name (`nameEcho`) is `view`: typing there leaves `Person.name` and the name field unchanged, and typing in the name field updates the echo. Name draft (`nameDraft`) is `model`: it opens as `Ada Lovelace`, stays there while the name field changes, and typing in the draft writes `Person.name` and updates the name field and the echo.
|
||||||
|
|
||||||
Always specify `direction`: it has no default. A non-null value other than `view`, `model`, or `both` fails the load with `Not a direction:`. Omitting it can currently fail with a `NullPointerException` during binding application. The ObservableList shortcut described above bypasses direction handling; do not rely on that shortcut to omit the declaration.
|
Always specify `direction`: it has no default. A non-null value other than `view`, `model`, or `both` fails the load with `Not a direction:`. Omitting it can currently fail with a `NullPointerException` during binding application. The ObservableList shortcut described above bypasses direction handling; do not rely on that shortcut to omit the declaration.
|
||||||
@@ -193,7 +208,7 @@ For a complex last segment the control receives the model instance behind the vi
|
|||||||
|
|
||||||
## Paths
|
## Paths
|
||||||
|
|
||||||
A path is attribute names separated by `.`. One name is an attribute of this view's view model, or `latestMessage`, or a `nameProperty()` on the view model. Earlier names must be complex attributes. The direction applies to the last name.
|
A path is attribute names separated by `.`. The last name resolves to an attribute, `latestMessage`, or a `nameProperty()` accessor. Earlier names must be complex attributes. The direction applies to the last name.
|
||||||
|
|
||||||
`home.street` on the home street label steps through the home view model, and `view` applies to `street`. When a complex attribute along the path is null, that binding is left unapplied and both sides keep their current values. The load still succeeds.
|
`home.street` on the home street label steps through the home view model, and `view` applies to `street`. When a complex attribute along the path is null, that binding is left unapplied and both sides keep their current values. The load still succeeds.
|
||||||
|
|
||||||
@@ -201,7 +216,7 @@ The path is resolved when the binding is applied. A binding whose last segment i
|
|||||||
|
|
||||||
A list is not indexed in a path. Repeat a component, place a table, or hand a list of simple values to a control.
|
A list is not indexed in a path. Repeat a component, place a table, or hand a list of simple values to a control.
|
||||||
|
|
||||||
A path that is not a read-write attribute fails the load with `No read-write attribute for path "` and the path. `Object.getClass` is not an attribute, and a getter without a setter is not one either.
|
An unresolved path fails the load with `No read-write attribute for path "` and the path. `Object.getClass` is not an attribute, and a getter without a setter is not one either.
|
||||||
|
|
||||||
## Converter
|
## Converter
|
||||||
|
|
||||||
@@ -251,6 +266,38 @@ A missing method fails the load with `No computed method "` and the method value
|
|||||||
|
|
||||||
An `onAction="#method"` handler is ordinary FXML. `addVisit`, `addTag`, `leaveNote`, `leaveWarning`, and `leaveFatal` are handlers. They are separate from the computed binding.
|
An `onAction="#method"` handler is ordinary FXML. `addVisit`, `addTag`, `leaveNote`, `leaveWarning`, and `leaveFatal` are handlers. They are separate from the computed binding.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
A `Command` combines an availability observable and an action. The ViewModel returns one
|
||||||
|
stable instance from a public getter. A keyboard shortcut can call `execute()` directly.
|
||||||
|
The command checks the current availability on every invocation.
|
||||||
|
|
||||||
|
```java
|
||||||
|
private final Command clear = new Command(documentOpen, editor::clear);
|
||||||
|
|
||||||
|
public Command getClear() {
|
||||||
|
return clear;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearFromKeyboard() {
|
||||||
|
clear.execute();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Load the FXML with a `ViewModelContext`. Inside its `BindingList`, add one declaration per
|
||||||
|
button or menu item. Here both controls use the same `getClear()` command.
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<CommandBinding control="clearButton" path="clear"/>
|
||||||
|
<CommandBinding control="clearMenuItem" path="clear"/>
|
||||||
|
```
|
||||||
|
|
||||||
|
Import `de.neitzel.fx.view.CommandBinding` and give both controls the corresponding `fx:id`.
|
||||||
|
The binding owns the control's `disable` and `onAction` properties. Use the command's
|
||||||
|
availability as the condition for disabling these controls. The managed View detaches
|
||||||
|
both bindings on close. For dynamically created menu items, keep the registration from
|
||||||
|
`CommandBindings.bind(item, command)` and close it when discarding the item.
|
||||||
|
|
||||||
## Controller
|
## Controller
|
||||||
|
|
||||||
Name the class on the root with `fx:controller`. The container creates it with `getComponent`, so it is the cached singleton. `@FXML` fields are filled during load, before the bindings run.
|
Name the class on the root with `fx:controller`. The container creates it with `getComponent`, so it is the cached singleton. `@FXML` fields are filled during load, before the bindings run.
|
||||||
@@ -433,6 +480,32 @@ Other load failures, all `IllegalArgumentException`:
|
|||||||
|
|
||||||
These style classes are on the nodes: `table`, `column-header-row`, `table-scroll`, `table-header-scroll`, `column-header`, `column-cell`, `column-resize`, `column-opener`, `sort-mark`, `selected`, `column-popup`, `column-search`, `column-select-all`, `column-comparison-operator`, `column-comparison-value`, and `filtered` on an opener whose column has an active filter.
|
These style classes are on the nodes: `table`, `column-header-row`, `table-scroll`, `table-header-scroll`, `column-header`, `column-cell`, `column-resize`, `column-opener`, `sort-mark`, `selected`, `column-popup`, `column-search`, `column-select-all`, `column-comparison-operator`, `column-comparison-value`, and `filtered` on an opener whose column has an active filter.
|
||||||
|
|
||||||
|
### Managed Views and Model contexts
|
||||||
|
|
||||||
|
Use the four-argument loader when a window, dialog or dockable owns a View:
|
||||||
|
|
||||||
|
```java
|
||||||
|
try (var models = new ViewModelContext();
|
||||||
|
var loaded = ViewLoader.load(fxml, model, application, models)) {
|
||||||
|
// Use loaded.getRoot() while this View is open.
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In a GUI host, retain the handles until the real close event. A drag between docking groups
|
||||||
|
keeps the same View open. Close an individual `LoadedView` to remove its bindings, including
|
||||||
|
those on components and collection rows. Close its `ViewModelContext` once the owning
|
||||||
|
window or archive ends. The context closes remaining Views and releases the Model-to-ViewModel
|
||||||
|
registrations. Views of the same model instance in one context share a ViewModel.
|
||||||
|
|
||||||
|
The managed loader creates a fresh injected Controller or Component for each instance.
|
||||||
|
Dependencies still come from the application context. Controllers and Components can
|
||||||
|
implement `AutoCloseable` to release additional resources such as programmatic event handlers
|
||||||
|
or subscriptions to application services. The library also closes these resources if FXML or
|
||||||
|
binding setup throws. Use these handles on the FX application thread.
|
||||||
|
|
||||||
|
The three-argument loader keeps its existing shared cache and Controller behavior. Manage a
|
||||||
|
View with the four-argument loader if it needs deterministic cleanup.
|
||||||
|
|
||||||
### Column width
|
### Column width
|
||||||
|
|
||||||
A column with no `width` shares the table width with the other open columns. A `width` is the starting width, and not below the header text. The text minimum is the header text's layout width, rounded up, plus 8. The desk's Street column opens at 300 and Visited at 120. City names no width, so it receives what remains of the table's 496, which is 76.
|
A column with no `width` shares the table width with the other open columns. A `width` is the starting width, and not below the header text. The text minimum is the header text's layout width, rounded up, plus 8. The desk's Street column opens at 300 and Visited at 120. City names no width, so it receives what remains of the table's 496, which is 76.
|
||||||
@@ -541,7 +614,8 @@ These are the `IllegalArgumentException` messages a document can produce. The vi
|
|||||||
| `No control "` | `fx:id` is missing |
|
| `No control "` | `fx:id` is missing |
|
||||||
| `No property ` | the control has no such JavaFX property |
|
| `No property ` | the control has no such JavaFX property |
|
||||||
| `Not a direction:` | an explicitly supplied direction is not `view`, `model`, or `both`; an omitted direction can instead cause `NullPointerException` |
|
| `Not a direction:` | an explicitly supplied direction is not `view`, `model`, or `both`; an omitted direction can instead cause `NullPointerException` |
|
||||||
| `No read-write attribute for path "` | the path is not an attribute |
|
| `No read-write attribute for path "` | the path did not resolve to an attribute or a named observable |
|
||||||
|
| `Read-only source for path` | use `view` to read an observable source |
|
||||||
| `Not a binding element:` | a child of `BindingList` is not a direct binding, a computed binding, or a repeat |
|
| `Not a binding element:` | a child of `BindingList` is not a direct binding, a computed binding, or a repeat |
|
||||||
| `No converter ` / `Not a converter:` | the converter class is missing or does not implement `Converter` |
|
| `No converter ` / `Not a converter:` | the converter class is missing or does not implement `Converter` |
|
||||||
| `No controller for ` / `No computed method "` | a computed binding has no controller or no such method |
|
| `No controller for ` / `No computed method "` | a computed binding has no controller or no such method |
|
||||||
|
|||||||
@@ -47,9 +47,22 @@ Drag a column's right boundary to preview a bounded width; release commits that
|
|||||||
column and Escape restores its previous sizing intent. Drag a header label to
|
column and Escape restores its previous sizing intent. Drag a header label to
|
||||||
move a column, or into the grouping area to add a chip. Insertion feedback and
|
move a column, or into the grouping area to add a chip. Insertion feedback and
|
||||||
fixed-position constraints apply; invalid/outside drops cancel without sorting.
|
fixed-position constraints apply; invalid/outside drops cancel without sorting.
|
||||||
Grouped columns remain visible. Drag chips to reorder levels, and use × to remove
|
Drag chips to reorder grouping levels, and use × to remove a grouping level.
|
||||||
a grouping level. A header click still sorts and the separate filter icon opens
|
A header click sorts and the separate filter icon opens its editor. The Grid
|
||||||
its editor. The Grid setup menu offers keyboard-operable Column settings.
|
setup menu offers keyboard-operable Column settings.
|
||||||
|
|
||||||
|
The arrow at the far right of the header opens a checklist of all columns.
|
||||||
|
Select a column to toggle its visibility. A column header's context menu offers
|
||||||
|
ascending and descending sorting, clearing that column's sort, filtering and
|
||||||
|
grouping where configured, resetting the column width, and hiding the column.
|
||||||
|
The arrow remains available when every column is hidden.
|
||||||
|
|
||||||
|
Applications can use `setColumnVisible(id, visible)`, `isColumnVisible(id)`,
|
||||||
|
and `columnVisibilityRevisionProperty()` to observe changes from either the UI or code.
|
||||||
|
Visibility applies to the open grid, including later pages. Hiding a column
|
||||||
|
preserves its order, width, filters, sorting, and grouping, and leaves existing
|
||||||
|
row components and drafts in place. Saved setups currently store the column
|
||||||
|
order and widths.
|
||||||
|
|
||||||
Each group has a disclosure triangle. Expansion follows the typed ordered path,
|
Each group has a disclosure triangle. Expansion follows the typed ordered path,
|
||||||
not its label or page number. Parent collapse preserves child choices. Current
|
not its label or page number. Parent collapse preserves child choices. Current
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
# Your first JavaFX application
|
# Your first JavaFX application
|
||||||
|
|
||||||
This walkthrough creates a complete Maven project with one editable name and a label that follows it. It uses Java 25, JavaFX 27.0.1 and NeitzelLib 1.0.2. The source build below uses the matching release tag.
|
This walkthrough creates a complete Maven project with one editable name and a label that follows it. It uses Java 25, JavaFX 27.0.1 and NeitzelLib 1.0.4. The source build below uses the matching release tag.
|
||||||
|
|
||||||
## Prepare the library
|
## Prepare the library
|
||||||
|
|
||||||
Install a JDK 25. Use the library's Maven wrapper (3.9.11), or a separate Maven installation version 3.9.11 or newer. Check `java -version` and `./mvnw -version` before building; on macOS, select the JDK with `export JAVA_HOME=$(/usr/libexec/java_home -v 25)` if necessary.
|
Install a JDK 25. Use the library's Maven wrapper (3.9.11), or a separate Maven installation version 3.9.11 or newer. Check `java -version` and `./mvnw -version` before building; on macOS, select the JDK with `export JAVA_HOME=$(/usr/libexec/java_home -v 25)` if necessary.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone --branch v1.0.2 https://gitea.neitzel.de/konrad/NeitzelLib.git
|
git clone --branch v1.0.4 https://gitea.neitzel.de/konrad/NeitzelLib.git
|
||||||
cd NeitzelLib
|
cd NeitzelLib
|
||||||
./mvnw -pl fx-example -am install
|
./mvnw -pl fx-example -am install
|
||||||
./mvnw -f fx-example/pom.xml javafx:run
|
./mvnw -f fx-example/pom.xml javafx:run
|
||||||
@@ -66,7 +66,7 @@ hello-fx/
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>fx</artifactId>
|
<artifactId>fx</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
@@ -190,7 +190,7 @@ For a named-module application, see the [module and lifecycle notes](architectur
|
|||||||
|
|
||||||
| Symptom | Check |
|
| Symptom | Check |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| Maven cannot resolve `de.neitzel.lib:fx:1.0.2` or its parent | Install the library reactor first; use the same Maven local repository for both projects. For direct downloads, see the [Maven repository setup](../../README.md#use-a-release-from-maven). |
|
| Maven cannot resolve `de.neitzel.lib:fx:1.0.4` or its parent | Install the library reactor first; use the same Maven local repository for both projects. For direct downloads, see the [Maven repository setup](../../README.md#use-a-release-from-maven). |
|
||||||
| `No plugin found for prefix 'javafx'` | Invoke the example POM directly, or use the complete application POM above. Do not invoke the goal on the library reactor parent. |
|
| `No plugin found for prefix 'javafx'` | Invoke the example POM directly, or use the complete application POM above. Do not invoke the goal on the library reactor parent. |
|
||||||
| JavaFX runtime/native library failure | Check the JDK version, architecture and JavaFX dependencies actually resolved; avoid mixing native artifacts from different platforms or JavaFX versions. |
|
| JavaFX runtime/native library failure | Check the JDK version, architecture and JavaFX dependencies actually resolved; avoid mixing native artifacts from different platforms or JavaFX versions. |
|
||||||
| `getResource(...)` returns null | The FXML belongs under `src/main/resources` in the matching package; verify it was copied to `target/classes`. Resource names are case-sensitive. |
|
| `getResource(...)` returns null | The FXML belongs under `src/main/resources` in the matching package; verify it was copied to `target/classes`. Resource names are case-sensitive. |
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>fx</artifactId>
|
<artifactId>fx</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package de.neitzel.fx.control;
|
||||||
|
|
||||||
|
import javafx.scene.control.ButtonBase;
|
||||||
|
import javafx.scene.control.ContentDisplay;
|
||||||
|
import javafx.scene.control.Tooltip;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.scene.shape.SVGPath;
|
||||||
|
|
||||||
|
/** A button graphic that follows the control's text color and exposes a tooltip and accessible name. */
|
||||||
|
public final class ActionIcon {
|
||||||
|
private ActionIcon() {}
|
||||||
|
|
||||||
|
/** Installs an outlined icon drawn on a 16 by 16 coordinate grid. */
|
||||||
|
public static void install(ButtonBase button, String description, String path) {
|
||||||
|
var icon = new SVGPath();
|
||||||
|
icon.setContent(path);
|
||||||
|
icon.setFill(null);
|
||||||
|
icon.strokeProperty().bind(button.textFillProperty());
|
||||||
|
icon.setStrokeWidth(1.5);
|
||||||
|
icon.setStrokeLineCap(javafx.scene.shape.StrokeLineCap.ROUND);
|
||||||
|
icon.setStrokeLineJoin(javafx.scene.shape.StrokeLineJoin.ROUND);
|
||||||
|
var graphic = new StackPane(icon);
|
||||||
|
graphic.setMinSize(18, 18);
|
||||||
|
graphic.setPrefSize(18, 18);
|
||||||
|
graphic.setMaxSize(18, 18);
|
||||||
|
graphic.setMouseTransparent(true);
|
||||||
|
button.setGraphic(graphic);
|
||||||
|
button.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
|
||||||
|
button.setAccessibleText(description);
|
||||||
|
button.setTooltip(new Tooltip(description));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ import java.util.Map;
|
|||||||
* The list of binding elements declared inside {@code fx:define}.
|
* The list of binding elements declared inside {@code fx:define}.
|
||||||
* <p>
|
* <p>
|
||||||
* The list is not a scene-graph child. FXML adds each {@link DirectBinding},
|
* The list is not a scene-graph child. FXML adds each {@link DirectBinding},
|
||||||
* {@link ComputedBinding}, or {@link Repeat} child to {@link #getElements()}.
|
* {@link ComputedBinding}, {@link CommandBinding}, or {@link Repeat} child to {@link #getElements()}.
|
||||||
*/
|
*/
|
||||||
@DefaultProperty("elements")
|
@DefaultProperty("elements")
|
||||||
public class BindingList {
|
public class BindingList {
|
||||||
@@ -42,14 +42,16 @@ public class BindingList {
|
|||||||
* @param context the container that creates a named Converter
|
* @param context the container that creates a named Converter
|
||||||
*/
|
*/
|
||||||
void apply(Map<String, Object> namespace, Object viewModel, Object controller, Parent root,
|
void apply(Map<String, Object> namespace, Object viewModel, Object controller, Parent root,
|
||||||
ApplicationContext context) {
|
ApplicationContext context, ViewLifetime lifetime) {
|
||||||
for (Object element : elements) {
|
for (Object element : elements) {
|
||||||
if (element instanceof DirectBinding directBinding) {
|
if (element instanceof DirectBinding directBinding) {
|
||||||
DirectBindingApplier.apply(namespace, viewModel, directBinding, context);
|
DirectBindingApplier.apply(namespace, viewModel, directBinding, context, lifetime);
|
||||||
} else if (element instanceof ComputedBinding computedBinding) {
|
} else if (element instanceof ComputedBinding computedBinding) {
|
||||||
ComputedBindingApplier.apply(namespace, viewModel, controller, root, computedBinding);
|
ComputedBindingApplier.apply(namespace, viewModel, controller, root, computedBinding, lifetime);
|
||||||
|
} else if (element instanceof CommandBinding commandBinding) {
|
||||||
|
CommandBindingApplier.apply(namespace, viewModel, commandBinding, lifetime);
|
||||||
} else if (element instanceof Repeat repeat) {
|
} else if (element instanceof Repeat repeat) {
|
||||||
RepeatApplier.apply(namespace, viewModel, repeat, context);
|
RepeatApplier.apply(namespace, viewModel, repeat, context, lifetime);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Not a binding element: " + element);
|
throw new IllegalArgumentException("Not a binding element: " + element);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import javafx.beans.value.ObservableBooleanValue;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One action with a live availability rule. Use the command and its availability on the
|
||||||
|
* JavaFX application thread.
|
||||||
|
*/
|
||||||
|
public final class Command {
|
||||||
|
|
||||||
|
/** The availability observed by each control displaying this command. */
|
||||||
|
@Getter
|
||||||
|
private final ObservableBooleanValue canExecute;
|
||||||
|
|
||||||
|
private final Runnable action;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a command for one action and execution context.
|
||||||
|
*
|
||||||
|
* @param canExecute live availability of the action
|
||||||
|
* @param action the work to start while the command is available
|
||||||
|
*/
|
||||||
|
public Command(ObservableBooleanValue canExecute, Runnable action) {
|
||||||
|
this.canExecute = Objects.requireNonNull(canExecute);
|
||||||
|
this.action = Objects.requireNonNull(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the action after checking the current availability, including for keyboard
|
||||||
|
* shortcuts or callers without an attached control.
|
||||||
|
*/
|
||||||
|
public void execute() {
|
||||||
|
if (canExecute.get()) {
|
||||||
|
action.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/** Connects an FXML button or menu item to a command supplied by its ViewModel. */
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public final class CommandBinding {
|
||||||
|
|
||||||
|
/** The target control's {@code fx:id}. */
|
||||||
|
private String control;
|
||||||
|
|
||||||
|
/** The simple bean property name of the command on the ViewModel. */
|
||||||
|
private String path;
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.control.ButtonBase;
|
||||||
|
import javafx.scene.control.MenuItem;
|
||||||
|
|
||||||
|
final class CommandBindingApplier {
|
||||||
|
|
||||||
|
private CommandBindingApplier() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static void validate(List<BindingList> lists, Map<String, Object> namespace) {
|
||||||
|
var commands = new IdentityHashMap<Object, CommandBinding>();
|
||||||
|
var propertyBindings = new ArrayList<Object>();
|
||||||
|
for (BindingList list : lists) {
|
||||||
|
for (Object element : list.getElements()) {
|
||||||
|
if (element instanceof CommandBinding binding) {
|
||||||
|
Object control = target(namespace, binding);
|
||||||
|
if (commands.put(control, binding) != null) {
|
||||||
|
throw invalid(namespace, binding, "duplicate owner for disable and onAction");
|
||||||
|
}
|
||||||
|
} else if (element instanceof DirectBinding binding) {
|
||||||
|
addConflict(propertyBindings, namespace, binding.getControl(), binding.getProperty());
|
||||||
|
} else if (element instanceof ComputedBinding binding) {
|
||||||
|
addConflict(propertyBindings, namespace, binding.getControl(), binding.getProperty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Object control : propertyBindings) {
|
||||||
|
CommandBinding command = commands.get(control);
|
||||||
|
if (command != null) {
|
||||||
|
throw invalid(namespace, command, "another binding owns disable or onAction");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addConflict(List<Object> targets, Map<String, Object> namespace,
|
||||||
|
String control, String property) {
|
||||||
|
if ("disable".equals(property) || "onAction".equals(property)) {
|
||||||
|
targets.add(namespace.get(control));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void apply(Map<String, Object> namespace, Object viewModel, CommandBinding binding,
|
||||||
|
ViewLifetime lifetime) {
|
||||||
|
if (!lifetime.managed()) {
|
||||||
|
throw invalid(namespace, binding, "CommandBinding requires a ViewModelContext");
|
||||||
|
}
|
||||||
|
var target = target(namespace, binding);
|
||||||
|
var command = command(namespace, binding, viewModel);
|
||||||
|
try {
|
||||||
|
var registration = target instanceof ButtonBase button
|
||||||
|
? CommandBindings.bind(button, command) : CommandBindings.bind((MenuItem) target, command);
|
||||||
|
lifetime.own(registration::close);
|
||||||
|
} catch (IllegalArgumentException failure) {
|
||||||
|
throw invalid(namespace, binding, failure.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object target(Map<String, Object> namespace, CommandBinding binding) {
|
||||||
|
var target = namespace.get(binding.getControl());
|
||||||
|
if (target == null) {
|
||||||
|
throw invalid(namespace, binding, "unknown target fx:id");
|
||||||
|
}
|
||||||
|
if (!(target instanceof ButtonBase) && !(target instanceof MenuItem)) {
|
||||||
|
throw invalid(namespace, binding, "target must be a ButtonBase or MenuItem");
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Command command(Map<String, Object> namespace, CommandBinding binding, Object viewModel) {
|
||||||
|
var path = binding.getPath();
|
||||||
|
if (path == null || path.isBlank() || path.contains(".")) {
|
||||||
|
throw invalid(namespace, binding, "expected a simple command path");
|
||||||
|
}
|
||||||
|
var getter = "get" + Character.toUpperCase(path.charAt(0)) + path.substring(1);
|
||||||
|
try {
|
||||||
|
var value = viewModel.getClass().getMethod(getter).invoke(viewModel);
|
||||||
|
if (value instanceof Command command) {
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
throw invalid(namespace, binding, getter + "() must return a Command instance");
|
||||||
|
} catch (NoSuchMethodException | IllegalAccessException failure) {
|
||||||
|
throw invalid(namespace, binding, "missing accessible command getter " + getter + "()");
|
||||||
|
} catch (InvocationTargetException failure) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
invalid(namespace, binding, "command getter " + getter + "() failed").getMessage(),
|
||||||
|
failure.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IllegalArgumentException invalid(Map<String, Object> namespace, CommandBinding binding,
|
||||||
|
String reason) {
|
||||||
|
return new IllegalArgumentException("Invalid CommandBinding in " + namespace.get(FXMLLoader.LOCATION_KEY)
|
||||||
|
+ " for " + binding.getControl() + " (disable/onAction), path " + binding.getPath() + ": " + reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import javafx.beans.property.BooleanProperty;
|
||||||
|
import javafx.beans.property.ObjectProperty;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.control.ButtonBase;
|
||||||
|
import javafx.scene.control.MenuItem;
|
||||||
|
|
||||||
|
/** Attaches reusable commands to JavaFX action controls. */
|
||||||
|
public final class CommandBindings {
|
||||||
|
|
||||||
|
private static final Object REGISTRATION_KEY = new Object();
|
||||||
|
|
||||||
|
private CommandBindings() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A single control's attachment to a command. Close on the JavaFX application thread. */
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface Registration extends AutoCloseable {
|
||||||
|
/** Removes this attachment. Subsequent calls have no effect. */
|
||||||
|
@Override
|
||||||
|
void close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attaches the command to a button's action and disable properties.
|
||||||
|
*
|
||||||
|
* @param button the action control
|
||||||
|
* @param command the command to execute
|
||||||
|
* @return the attachment to close when the control is no longer in use
|
||||||
|
*/
|
||||||
|
public static Registration bind(ButtonBase button, Command command) {
|
||||||
|
return attach(button.getProperties(), button.disableProperty(), button.onActionProperty(), command);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attaches the command to a menu item's action and disable properties.
|
||||||
|
*
|
||||||
|
* @param item the menu action
|
||||||
|
* @param command the command to execute
|
||||||
|
* @return the attachment to close when the menu item is no longer in use
|
||||||
|
*/
|
||||||
|
public static Registration bind(MenuItem item, Command command) {
|
||||||
|
return attach(item.getProperties(), item.disableProperty(), item.onActionProperty(), command);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Registration attach(Map<Object, Object> properties, BooleanProperty disable,
|
||||||
|
ObjectProperty<EventHandler<ActionEvent>> onAction, Command command) {
|
||||||
|
Objects.requireNonNull(command);
|
||||||
|
if (properties.containsKey(REGISTRATION_KEY) || disable.isBound()) {
|
||||||
|
throw new IllegalArgumentException("disable is already bound");
|
||||||
|
}
|
||||||
|
if (onAction.isBound() || onAction.get() != null) {
|
||||||
|
throw new IllegalArgumentException("onAction already has an owner");
|
||||||
|
}
|
||||||
|
var available = command.getCanExecute();
|
||||||
|
ChangeListener<Boolean> update = (observable, before, after) -> disable.set(!after);
|
||||||
|
EventHandler<ActionEvent> handler = event -> command.execute();
|
||||||
|
disable.set(!available.get());
|
||||||
|
onAction.set(handler);
|
||||||
|
available.addListener(update);
|
||||||
|
properties.put(REGISTRATION_KEY, handler);
|
||||||
|
return () -> {
|
||||||
|
if (properties.remove(REGISTRATION_KEY, handler)) {
|
||||||
|
available.removeListener(update);
|
||||||
|
if (onAction.get() == handler && !onAction.isBound()) {
|
||||||
|
onAction.set(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javafx.beans.property.Property;
|
import javafx.beans.property.Property;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.util.Builder;
|
import javafx.util.Builder;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
@@ -51,20 +52,20 @@ final class Components {
|
|||||||
* @param context the container that creates Components
|
* @param context the container that creates Components
|
||||||
* @return a builder for a Component, or {@code null} when the type is not a Component
|
* @return a builder for a Component, or {@code null} when the type is not a Component
|
||||||
*/
|
*/
|
||||||
static Builder<?> builder(Class<?> type, ApplicationContext context) {
|
static Builder<?> builder(Class<?> type, ApplicationContext context, ViewLifetime owner) {
|
||||||
Object component;
|
Object component;
|
||||||
try {
|
try {
|
||||||
component = context.getComponent(type.asSubclass(Object.class));
|
component = owner.managed() ? context.createComponent(type) : context.getComponent(type);
|
||||||
} catch (IllegalArgumentException notAComponent) {
|
} catch (IllegalArgumentException notAComponent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (component.getClass() != type) {
|
if (component.getClass() != type) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!LoadSession.claimFirst(type)) {
|
if (!owner.managed() && !LoadSession.claimFirst(type)) {
|
||||||
component = context.createComponent(type.asSubclass(Object.class));
|
component = context.createComponent(type.asSubclass(Object.class));
|
||||||
}
|
}
|
||||||
return new ComponentBuilder(component, context);
|
return new ComponentBuilder(component, context, owner.child());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,6 +78,7 @@ final class Components {
|
|||||||
private final Object component;
|
private final Object component;
|
||||||
/** The context used to load its document. */
|
/** The context used to load its document. */
|
||||||
private final ApplicationContext context;
|
private final ApplicationContext context;
|
||||||
|
private final ViewLifetime lifetime;
|
||||||
/** Values already resolved by the containing FXMLLoader. */
|
/** Values already resolved by the containing FXMLLoader. */
|
||||||
private final Map<String, Object> values = new LinkedHashMap<>();
|
private final Map<String, Object> values = new LinkedHashMap<>();
|
||||||
|
|
||||||
@@ -106,7 +108,7 @@ final class Components {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object build() {
|
public Object build() {
|
||||||
Object result = load(component, context);
|
Object result = load(component, context, lifetime);
|
||||||
if (!values.isEmpty()) {
|
if (!values.isEmpty()) {
|
||||||
// A second fx:root load uses the public FXMLLoader API for bean setters,
|
// A second fx:root load uses the public FXMLLoader API for bean setters,
|
||||||
// enum/numeric coercion and diagnostics, without depending on BeanAdapter
|
// enum/numeric coercion and diagnostics, without depending on BeanAdapter
|
||||||
@@ -145,9 +147,9 @@ final class Components {
|
|||||||
* @param context the container that creates the instance and its dependencies
|
* @param context the container that creates the instance and its dependencies
|
||||||
* @return the loaded Component
|
* @return the loaded Component
|
||||||
*/
|
*/
|
||||||
static Object fresh(Class<?> type, ApplicationContext context) {
|
static Object fresh(Class<?> type, ApplicationContext context, ViewLifetime lifetime) {
|
||||||
Object component = context.createComponent(type.asSubclass(Object.class));
|
Object component = context.createComponent(type.asSubclass(Object.class));
|
||||||
return load(component, context);
|
return load(component, context, lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,8 +160,18 @@ final class Components {
|
|||||||
* @param component the Component
|
* @param component the Component
|
||||||
* @param model the Model instance
|
* @param model the Model instance
|
||||||
*/
|
*/
|
||||||
static void setModel(Object component, Object model) {
|
static void setModel(Object component, Object model, ViewLifetime lifetime) {
|
||||||
|
if (!lifetime.managed()) {
|
||||||
modelProperty(component).setValue(model);
|
modelProperty(component).setValue(model);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LoadSession session = LoadSession.nest();
|
||||||
|
try {
|
||||||
|
modelProperty(component).setValue(model);
|
||||||
|
session.checkFailure();
|
||||||
|
} finally {
|
||||||
|
LoadSession.unnest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,7 +181,8 @@ final class Components {
|
|||||||
* @param context the container that creates nested Components
|
* @param context the container that creates nested Components
|
||||||
* @return the loaded Component
|
* @return the loaded Component
|
||||||
*/
|
*/
|
||||||
private static Object load(Object component, ApplicationContext context) {
|
private static Object load(Object component, ApplicationContext context, ViewLifetime lifetime) {
|
||||||
|
lifetime.ownController(component);
|
||||||
Class<?> type = component.getClass();
|
Class<?> type = component.getClass();
|
||||||
String document = type.getSimpleName() + ".fxml";
|
String document = type.getSimpleName() + ".fxml";
|
||||||
URL fxml = type.getResource(document);
|
URL fxml = type.getResource(document);
|
||||||
@@ -179,11 +192,18 @@ final class Components {
|
|||||||
LoadSession nested = LoadSession.nest();
|
LoadSession nested = LoadSession.nest();
|
||||||
try {
|
try {
|
||||||
FXMLLoader loader = new FXMLLoader(fxml, ViewLoader.resources(context, fxml, type));
|
FXMLLoader loader = new FXMLLoader(fxml, ViewLoader.resources(context, fxml, type));
|
||||||
|
FxmlHandlers.observe(loader, lifetime);
|
||||||
loader.setRoot(component);
|
loader.setRoot(component);
|
||||||
loader.setController(component);
|
loader.setController(component);
|
||||||
loader.setBuilderFactory(nestedType -> builder(nestedType, context));
|
loader.setControllerFactory(nestedType -> ViewLoader.createController(context, nestedType, lifetime));
|
||||||
|
loader.setBuilderFactory(nestedType -> builder(nestedType, context, lifetime));
|
||||||
loader.load();
|
loader.load();
|
||||||
watchModel(component, List.copyOf(nested.bindingLists()), loader.getNamespace(), context);
|
nested.checkFailure();
|
||||||
|
if (lifetime.managed() && component instanceof Node node) {
|
||||||
|
node.getProperties().put(Components.class, Boolean.TRUE);
|
||||||
|
lifetime.own(() -> node.getProperties().remove(Components.class));
|
||||||
|
}
|
||||||
|
watchModel(component, List.copyOf(nested.bindingLists()), loader.getNamespace(), context, lifetime);
|
||||||
return component;
|
return component;
|
||||||
} catch (IOException failure) {
|
} catch (IOException failure) {
|
||||||
throw new IllegalStateException("Could not load component " + fxml, failure);
|
throw new IllegalStateException("Could not load component " + fxml, failure);
|
||||||
@@ -201,25 +221,38 @@ final class Components {
|
|||||||
* @param context the container that creates a named Converter
|
* @param context the container that creates a named Converter
|
||||||
*/
|
*/
|
||||||
private static void watchModel(Object component, List<BindingList> lists, Map<String, Object> namespace,
|
private static void watchModel(Object component, List<BindingList> lists, Map<String, Object> namespace,
|
||||||
ApplicationContext context) {
|
ApplicationContext context, ViewLifetime lifetime) {
|
||||||
Property<Object> model = modelProperty(component);
|
Property<Object> model = modelProperty(component);
|
||||||
boolean[] applied = {false};
|
boolean[] applied = {false};
|
||||||
model.addListener((observable, oldValue, newValue) -> {
|
lifetime.listen(model, (observable, oldValue, newValue) -> {
|
||||||
if (newValue == null || applied[0]) {
|
if (newValue == null || applied[0]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
applied[0] = true;
|
applied[0] = true;
|
||||||
Object viewModel = ViewModels.of(newValue, ViewModels.namedOn(component.getClass()));
|
try {
|
||||||
|
Object viewModel = ViewModels.of(lifetime.models(), newValue, ViewModels.namedOn(component.getClass()));
|
||||||
if (component instanceof HasViewModel hasViewModel && viewModel instanceof ViewModel bound) {
|
if (component instanceof HasViewModel hasViewModel && viewModel instanceof ViewModel bound) {
|
||||||
hasViewModel.setViewModel(bound);
|
hasViewModel.setViewModel(bound);
|
||||||
}
|
}
|
||||||
Parent root = (Parent) component;
|
Parent root = (Parent) component;
|
||||||
|
CommandBindingApplier.validate(lists, namespace);
|
||||||
for (BindingList list : lists) {
|
for (BindingList list : lists) {
|
||||||
list.apply(namespace, viewModel, component, root, context);
|
list.apply(namespace, viewModel, component, root, context, lifetime);
|
||||||
|
}
|
||||||
|
if (lifetime.managed()) Table.openAll(root, viewModel, context, lifetime);
|
||||||
|
} catch (RuntimeException | Error failure) {
|
||||||
|
lifetime.rollback(failure);
|
||||||
|
if (!lifetime.managed() || !LoadSession.recordFailure(failure)) {
|
||||||
|
throw failure;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean ownsBindings(Node node) {
|
||||||
|
return node.hasProperties() && node.getProperties().containsKey(Components.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Component's {@code model} property.
|
* Returns the Component's {@code model} property.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ final class ComputedBindingApplier {
|
|||||||
Object viewModel,
|
Object viewModel,
|
||||||
Object controller,
|
Object controller,
|
||||||
Parent root,
|
Parent root,
|
||||||
ComputedBinding binding) {
|
ComputedBinding binding, ViewLifetime lifetime) {
|
||||||
Object control = namespace.get(binding.getControl());
|
Object control = namespace.get(binding.getControl());
|
||||||
if (control == null) {
|
if (control == null) {
|
||||||
throw new IllegalArgumentException("No control \"" + binding.getControl() + "\"");
|
throw new IllegalArgumentException("No control \"" + binding.getControl() + "\"");
|
||||||
@@ -49,9 +49,9 @@ final class ComputedBindingApplier {
|
|||||||
Property<Object> target = controlProperty(control, binding.getProperty());
|
Property<Object> target = controlProperty(control, binding.getProperty());
|
||||||
Runnable refresh = refresh(controller, binding.getMethod(), target);
|
Runnable refresh = refresh(controller, binding.getMethod(), target);
|
||||||
refresh.run();
|
refresh.run();
|
||||||
watchControls(root, target, refresh);
|
watchNode(root, target, refresh, lifetime);
|
||||||
if (viewModel instanceof ViewModel model) {
|
if (viewModel instanceof ViewModel model) {
|
||||||
model.addAttributeListener((observable, oldValue, newValue) -> refresh.run());
|
model.addAttributeListener(lifetime, (observable, oldValue, newValue) -> refresh.run());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,17 +80,6 @@ final class ComputedBindingApplier {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Watches JavaFX properties on controls under {@code root}, other than {@code target}.
|
|
||||||
*
|
|
||||||
* @param root the scene-graph root
|
|
||||||
* @param target the property the method writes, which is not watched
|
|
||||||
* @param refresh the refresh to run when a watched property changes
|
|
||||||
*/
|
|
||||||
private static void watchControls(Parent root, Property<?> target, Runnable refresh) {
|
|
||||||
watchNode(root, target, refresh);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watches one control and walks its children.
|
* Watches one control and walks its children.
|
||||||
*
|
*
|
||||||
@@ -98,13 +87,13 @@ final class ComputedBindingApplier {
|
|||||||
* @param target the property the method writes, which is not watched
|
* @param target the property the method writes, which is not watched
|
||||||
* @param refresh the refresh to run when a watched property changes
|
* @param refresh the refresh to run when a watched property changes
|
||||||
*/
|
*/
|
||||||
private static void watchNode(Node node, Property<?> target, Runnable refresh) {
|
private static void watchNode(Node node, Property<?> target, Runnable refresh, ViewLifetime lifetime) {
|
||||||
if (node instanceof Control control) {
|
if (node instanceof Control control) {
|
||||||
watchProperties(control, target, refresh);
|
watchProperties(control, target, refresh, lifetime);
|
||||||
}
|
}
|
||||||
if (node instanceof Parent parent) {
|
if (node instanceof Parent parent) {
|
||||||
for (Node child : parent.getChildrenUnmodifiable()) {
|
for (Node child : parent.getChildrenUnmodifiable()) {
|
||||||
watchNode(child, target, refresh);
|
watchNode(child, target, refresh, lifetime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +106,7 @@ final class ComputedBindingApplier {
|
|||||||
* @param refresh the refresh to run when a watched property changes
|
* @param refresh the refresh to run when a watched property changes
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void watchProperties(Object bean, Property<?> target, Runnable refresh) {
|
private static void watchProperties(Object bean, Property<?> target, Runnable refresh, ViewLifetime lifetime) {
|
||||||
ChangeListener<Object> listener = (observable, oldValue, newValue) -> refresh.run();
|
ChangeListener<Object> listener = (observable, oldValue, newValue) -> refresh.run();
|
||||||
for (Method method : bean.getClass().getMethods()) {
|
for (Method method : bean.getClass().getMethods()) {
|
||||||
if (method.getParameterCount() != 0 || !method.getName().endsWith("Property")) {
|
if (method.getParameterCount() != 0 || !method.getName().endsWith("Property")) {
|
||||||
@@ -128,7 +117,7 @@ final class ComputedBindingApplier {
|
|||||||
}
|
}
|
||||||
Object value = readProperty(bean, method);
|
Object value = readProperty(bean, method);
|
||||||
if (value instanceof ObservableValue<?> observable && observable != target) {
|
if (value instanceof ObservableValue<?> observable && observable != target) {
|
||||||
((ObservableValue<Object>) observable).addListener(listener);
|
lifetime.listen((ObservableValue<Object>) observable, listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
previous = pagingButton("Previous page", "M2 7 L14 0 V14 Z"),
|
previous = pagingButton("Previous page", "M2 7 L14 0 V14 Z"),
|
||||||
next = pagingButton("Next page", "M2 0 L14 7 L2 14 Z"),
|
next = pagingButton("Next page", "M2 0 L14 7 L2 14 Z"),
|
||||||
last = pagingButton("Last page", "M0 0 L12 7 L0 14 Z M14 0 H16 V14 H14 Z"),
|
last = pagingButton("Last page", "M0 0 L12 7 L0 14 Z M14 0 H16 V14 H14 Z"),
|
||||||
retry = new Button("Retry"),
|
retry = actionButton("Retry", "M2 8 A6 6 0 1 1 5 13 M2 3 V8 H7"),
|
||||||
refresh = new Button("Refresh");
|
refresh = actionButton("Refresh", "M14 7 A6 6 0 1 0 13 11 M14 2 V7 H9");
|
||||||
private final ComboBox<String> pageSize = new ComboBox<>();
|
private final ComboBox<String> pageSize = new ComboBox<>();
|
||||||
private GridQuery initial;
|
private GridQuery initial;
|
||||||
private List<ResultColumn> columnDefinitions;
|
private List<ResultColumn> columnDefinitions;
|
||||||
@@ -59,6 +59,8 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
private final Label activeFilters = new Label();
|
private final Label activeFilters = new Label();
|
||||||
private final Label interactionStatus = new Label();
|
private final Label interactionStatus = new Label();
|
||||||
private final MenuButton setupMenu = new MenuButton("Grid setup");
|
private final MenuButton setupMenu = new MenuButton("Grid setup");
|
||||||
|
private final MenuButton columnMenu = new MenuButton();
|
||||||
|
private final ReadOnlyLongWrapper columnVisibilityRevision = new ReadOnlyLongWrapper();
|
||||||
private final ReadOnlyLongWrapper committedRevision = new ReadOnlyLongWrapper();
|
private final ReadOnlyLongWrapper committedRevision = new ReadOnlyLongWrapper();
|
||||||
private List<String> defaultGrouping = List.of();
|
private List<String> defaultGrouping = List.of();
|
||||||
private GridSetup developerDefaults;
|
private GridSetup developerDefaults;
|
||||||
@@ -68,6 +70,12 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
private GridPersistenceAttachment<K, T> attachment;
|
private GridPersistenceAttachment<K, T> attachment;
|
||||||
private GridColumnSettings<K, T> columnSettings;
|
private GridColumnSettings<K, T> columnSettings;
|
||||||
|
|
||||||
|
private static Button actionButton(String description, String path) {
|
||||||
|
var button = new Button();
|
||||||
|
de.neitzel.fx.control.ActionIcon.install(button, description, path);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
private static Button pagingButton(String name, String path) {
|
private static Button pagingButton(String name, String path) {
|
||||||
var button = new Button();
|
var button = new Button();
|
||||||
var icon = new SVGPath();
|
var icon = new SVGPath();
|
||||||
@@ -272,7 +280,12 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
List.of(),
|
List.of(),
|
||||||
new PageRequest.Paged(
|
new PageRequest.Paged(
|
||||||
0, Math.min(50, source.capabilities().maximumPageSize())));
|
0, Math.min(50, source.capabilities().maximumPageSize())));
|
||||||
renderer = table.openResults(columns, rowFactory);
|
renderer = table.openResults(columns, rowFactory, columnMenu);
|
||||||
|
columnMenu.getStyleClass().add("data-grid-column-menu");
|
||||||
|
columnMenu.setAccessibleText("Column visibility");
|
||||||
|
columnMenu.setTooltip(new Tooltip("Column visibility"));
|
||||||
|
columnMenu.setOnShowing(event -> updateColumnMenu());
|
||||||
|
renderer.setHeaderMenuFactory(this::headerMenu);
|
||||||
renderer.setSelectionMode(getSelectionMode());
|
renderer.setSelectionMode(getSelectionMode());
|
||||||
selectedKeys.bind(renderer.selectedKeysProperty());
|
selectedKeys.bind(renderer.selectedKeysProperty());
|
||||||
selectedElements.bind(renderer.selectedElementsProperty());
|
selectedElements.bind(renderer.selectedElementsProperty());
|
||||||
@@ -343,9 +356,12 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
controls.getChildren().add(setupMenu);
|
controls.getChildren().add(setupMenu);
|
||||||
interactionStatus.setWrapText(true);
|
interactionStatus.setWrapText(true);
|
||||||
interactionStatus.getStyleClass().add("data-grid-interaction-status");
|
interactionStatus.getStyleClass().add("data-grid-interaction-status");
|
||||||
|
de.neitzel.fx.control.ActionIcon.install(setupMenu, "Grid setup",
|
||||||
|
"M2 4 H14 M2 8 H14 M2 12 H14 M5 2 V6 M11 6 V10 M7 10 V14");
|
||||||
var css = DataGrid.class.getResource("data-grid.css");
|
var css = DataGrid.class.getResource("data-grid.css");
|
||||||
if (css != null) getStylesheets().add(css.toExternalForm());
|
if (css != null) getStylesheets().add(css.toExternalForm());
|
||||||
Button clearActiveFilters = new Button("Clear filters");
|
Button clearActiveFilters = actionButton("Clear filters",
|
||||||
|
"M1 2 H15 L9 8 V14 L6 12 V8 Z M11 10 L15 14 M15 10 L11 14");
|
||||||
clearActiveFilters.setOnAction(e -> setFilters(List.of()));
|
clearActiveFilters.setOnAction(e -> setFilters(List.of()));
|
||||||
filterSummary.getChildren().addAll(activeFilters, clearActiveFilters);
|
filterSummary.getChildren().addAll(activeFilters, clearActiveFilters);
|
||||||
filterSummary.setVisible(false);
|
filterSummary.setVisible(false);
|
||||||
@@ -417,6 +433,66 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
renderer.setColumnOrder(ids);
|
renderer.setColumnOrder(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns whether this grid currently displays the column. */
|
||||||
|
public boolean isColumnVisible(String id) {
|
||||||
|
check();
|
||||||
|
return renderer.isColumnVisible(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shows or hides a column without fetching rows or changing the saved grid setup. */
|
||||||
|
public void setColumnVisible(String id, boolean visible) {
|
||||||
|
if (visible == isColumnVisible(id)) return;
|
||||||
|
closeFilter();
|
||||||
|
renderer.setColumnVisible(id, visible);
|
||||||
|
columnVisibilityRevision.set(columnVisibilityRevision.get() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Observes effective visibility changes, which are independent of saved grid setups. */
|
||||||
|
public ReadOnlyLongProperty columnVisibilityRevisionProperty() {
|
||||||
|
return columnVisibilityRevision.getReadOnlyProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateColumnMenu() {
|
||||||
|
columnMenu.getItems().setAll(renderer.columnOrder().stream().map(id -> {
|
||||||
|
CheckMenuItem item = new CheckMenuItem(renderer.columnHeader(id));
|
||||||
|
item.setSelected(isColumnVisible(id));
|
||||||
|
item.setOnAction(e -> setColumnVisible(id, item.isSelected()));
|
||||||
|
return item;
|
||||||
|
}).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ContextMenu headerMenu(String id, HBox cell) {
|
||||||
|
var menu = new ContextMenu(
|
||||||
|
menuItem("Sort ascending", () -> setSort(new SortKey(id, SortKey.Direction.ASCENDING))),
|
||||||
|
menuItem("Sort descending", () -> setSort(new SortKey(id, SortKey.Direction.DESCENDING))));
|
||||||
|
if (query().sort().stream().anyMatch(key -> key.columnId().equals(id)))
|
||||||
|
menu.getItems().add(menuItem("Clear sort", () -> setSort(null)));
|
||||||
|
if (filterColumns.containsKey(id)) {
|
||||||
|
var filterButton = cell.lookup(".filter-button");
|
||||||
|
menu.getItems().add(menuItem("Filter…", () -> openFilter(id, filterButton)));
|
||||||
|
}
|
||||||
|
if (renderer.canGroup(id)) {
|
||||||
|
boolean grouped = renderer.groupingColumns().contains(id);
|
||||||
|
menu.getItems().add(menuItem(grouped ? "Remove grouping" : "Group by column", () -> {
|
||||||
|
var nextGroups = new ArrayList<>(renderer.groupingColumns());
|
||||||
|
if (grouped) nextGroups.remove(id);
|
||||||
|
else if (!nextGroups.contains(id)) nextGroups.add(id);
|
||||||
|
setGroupingColumns(nextGroups);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
menu.getItems().addAll(
|
||||||
|
menuItem("Reset column width", () -> setColumnWidth(id, new ColumnWidth.Default())),
|
||||||
|
new SeparatorMenuItem(),
|
||||||
|
menuItem("Hide column", () -> setColumnVisible(id, false)));
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MenuItem menuItem(String text, Runnable action) {
|
||||||
|
var item = new MenuItem(text);
|
||||||
|
item.setOnAction(e -> action.run());
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
public double setColumnWidth(String id, ColumnWidth width) {
|
public double setColumnWidth(String id, ColumnWidth width) {
|
||||||
check();
|
check();
|
||||||
closeFilter();
|
closeFilter();
|
||||||
@@ -1252,6 +1328,7 @@ public final class DataGrid<K, T> extends VBox implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
if (attachment != null) attachment.close();
|
if (attachment != null) attachment.close();
|
||||||
closed = true;
|
closed = true;
|
||||||
|
columnMenu.hide();
|
||||||
closeFilter();
|
closeFilter();
|
||||||
declaration.close();
|
declaration.close();
|
||||||
if (coordinator != null) coordinator.close();
|
if (coordinator != null) coordinator.close();
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ import lombok.Setter;
|
|||||||
* View's ViewModel. Further names step into the ViewModel of a Complex attribute, and the
|
* View's ViewModel. Further names step into the ViewModel of a Complex attribute, and the
|
||||||
* direction applies to the last name. When that last name is complex, the control receives the
|
* direction applies to the last name. When that last name is complex, the control receives the
|
||||||
* Model instance behind the ViewModel. Direction values are {@code view}, {@code model}, and
|
* Model instance behind the ViewModel. Direction values are {@code view}, {@code model}, and
|
||||||
* {@code both}. The Converter value is the class name. The container creates that class.
|
* {@code both}. The last segment of a {@code view} binding may also name a public
|
||||||
|
* {@code xxxProperty()} accessor returning a read-only observable. The Converter value is the
|
||||||
|
* class name. The container creates that class.
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javafx.beans.property.Property;
|
import javafx.beans.property.Property;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -30,48 +32,69 @@ final class DirectBindingApplier {
|
|||||||
* @param context the container that creates a named Converter
|
* @param context the container that creates a named Converter
|
||||||
*/
|
*/
|
||||||
static void apply(Map<String, Object> namespace, Object viewModel, DirectBinding binding,
|
static void apply(Map<String, Object> namespace, Object viewModel, DirectBinding binding,
|
||||||
ApplicationContext context) {
|
ApplicationContext context, ViewLifetime lifetime) {
|
||||||
Object control = namespace.get(binding.getControl());
|
Object control = namespace.get(binding.getControl());
|
||||||
if (control == null) {
|
if (control == null) {
|
||||||
throw new IllegalArgumentException("No control \"" + binding.getControl() + "\"");
|
throw new IllegalArgumentException("No control \"" + binding.getControl() + "\"");
|
||||||
}
|
}
|
||||||
selectComponentViewModel(control, viewModel, binding);
|
selectComponentViewModel(control, viewModel, binding, lifetime);
|
||||||
Resolved resolved = resolve(viewModel, binding.getPath());
|
Resolved resolved = resolve(viewModel, binding.getPath());
|
||||||
if (resolved == null) {
|
if (resolved == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Property<?> controlProperty = controlProperty(control, binding.getProperty());
|
Property<?> controlProperty = controlProperty(control, binding.getProperty());
|
||||||
Property<?> attribute = resolved.attribute;
|
if (!resolved.writable) {
|
||||||
|
alignReadOnly(namespace, controlProperty, resolved, binding, context, lifetime);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Property<?> attribute = (Property<?>) resolved.attribute;
|
||||||
if (resolved.complex) {
|
if (resolved.complex) {
|
||||||
switch (binding.getDirection()) {
|
switch (binding.getDirection()) {
|
||||||
case "both" -> alignBothComplex(controlProperty, attribute);
|
case "both" -> alignBothComplex(controlProperty, attribute, lifetime);
|
||||||
case "view" -> alignTowardViewComplex(controlProperty, attribute);
|
case "view" -> alignTowardViewComplex(controlProperty, attribute, lifetime);
|
||||||
case "model" -> alignTowardModelComplex(controlProperty, attribute);
|
case "model" -> alignTowardModelComplex(controlProperty, attribute, lifetime);
|
||||||
default -> throw new IllegalArgumentException("Not a direction: " + binding.getDirection());
|
default -> throw new IllegalArgumentException("Not a direction: " + binding.getDirection());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (attribute.getValue() instanceof ObservableList<?> values) {
|
if (attribute.getValue() instanceof ObservableList<?> values) {
|
||||||
assignList(controlProperty, values);
|
assignList(controlProperty, values, lifetime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String converterName = binding.getConverter();
|
String converterName = binding.getConverter();
|
||||||
if (converterName == null || converterName.isEmpty()) {
|
if (converterName == null || converterName.isEmpty()) {
|
||||||
alignPlain(controlProperty, attribute, binding.getDirection());
|
alignPlain(controlProperty, attribute, binding.getDirection(), lifetime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Converter converter = converter(context, converterName);
|
Converter converter = converter(context, converterName);
|
||||||
switch (binding.getDirection()) {
|
switch (binding.getDirection()) {
|
||||||
case "both" -> alignConverted(
|
case "both" -> alignConverted(
|
||||||
controlProperty, attribute, converter, resolved.owner, resolved.name, true, true);
|
controlProperty, attribute, converter, resolved.owner, resolved.name, true, true, lifetime);
|
||||||
case "view" -> alignConverted(
|
case "view" -> alignConverted(
|
||||||
controlProperty, attribute, converter, resolved.owner, resolved.name, true, false);
|
controlProperty, attribute, converter, resolved.owner, resolved.name, true, false, lifetime);
|
||||||
case "model" -> alignConverted(
|
case "model" -> alignConverted(
|
||||||
controlProperty, attribute, converter, resolved.owner, resolved.name, false, true);
|
controlProperty, attribute, converter, resolved.owner, resolved.name, false, true, lifetime);
|
||||||
default -> throw new IllegalArgumentException("Not a direction: " + binding.getDirection());
|
default -> throw new IllegalArgumentException("Not a direction: " + binding.getDirection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Connects a named observable to the View when its accessor exposes no writable property. */
|
||||||
|
private static void alignReadOnly(Map<String, Object> namespace, Property<?> control, Resolved resolved,
|
||||||
|
DirectBinding binding, ApplicationContext context, ViewLifetime lifetime) {
|
||||||
|
if (!"view".equals(binding.getDirection())) {
|
||||||
|
throw new IllegalArgumentException("Read-only source for path \"" + binding.getPath()
|
||||||
|
+ "\" requires direction=\"view\" on " + binding.getControl() + "." + binding.getProperty()
|
||||||
|
+ " in " + namespace.get(FXMLLoader.LOCATION_KEY));
|
||||||
|
}
|
||||||
|
String converterName = binding.getConverter();
|
||||||
|
if (converterName == null || converterName.isEmpty()) {
|
||||||
|
alignTowardView(control, resolved.attribute, lifetime);
|
||||||
|
} else {
|
||||||
|
alignConverted(control, resolved.attribute, converter(context, converterName),
|
||||||
|
resolved.owner, resolved.name, true, false, lifetime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aligns a plain Attribute in the named direction.
|
* Aligns a plain Attribute in the named direction.
|
||||||
*
|
*
|
||||||
@@ -79,11 +102,11 @@ final class DirectBindingApplier {
|
|||||||
* @param attribute the Attribute
|
* @param attribute the Attribute
|
||||||
* @param direction {@code view}, {@code model}, or {@code both}
|
* @param direction {@code view}, {@code model}, or {@code both}
|
||||||
*/
|
*/
|
||||||
private static void alignPlain(Property<?> controlProperty, Property<?> attribute, String direction) {
|
private static void alignPlain(Property<?> controlProperty, Property<?> attribute, String direction, ViewLifetime lifetime) {
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case "both" -> alignBoth(controlProperty, attribute);
|
case "both" -> alignBoth(controlProperty, attribute, lifetime);
|
||||||
case "view" -> alignTowardView(controlProperty, attribute);
|
case "view" -> alignTowardView(controlProperty, attribute, lifetime);
|
||||||
case "model" -> alignTowardModel(controlProperty, attribute);
|
case "model" -> alignTowardModel(controlProperty, attribute, lifetime);
|
||||||
default -> throw new IllegalArgumentException("Not a direction: " + direction);
|
default -> throw new IllegalArgumentException("Not a direction: " + direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +123,10 @@ final class DirectBindingApplier {
|
|||||||
/**
|
/**
|
||||||
* The Attribute the Path names.
|
* The Attribute the Path names.
|
||||||
*/
|
*/
|
||||||
private final Property<?> attribute;
|
private final ObservableValue<?> attribute;
|
||||||
|
|
||||||
|
/** Whether the Attribute resolves to a writable endpoint. */
|
||||||
|
private final boolean writable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether that Attribute is complex.
|
* Whether that Attribute is complex.
|
||||||
@@ -153,13 +179,16 @@ final class DirectBindingApplier {
|
|||||||
current = child;
|
current = child;
|
||||||
}
|
}
|
||||||
String last = names[names.length - 1];
|
String last = names[names.length - 1];
|
||||||
Property<?> attribute = propertyOf(current, last);
|
Property<?> property = propertyOf(current, last);
|
||||||
if (attribute == null) {
|
ViewModel owner = current instanceof ViewModel model ? model : null;
|
||||||
|
if (property != null) {
|
||||||
|
return new Resolved(property, true, owner != null && owner.isComplex(last), owner, last);
|
||||||
|
}
|
||||||
|
ObservableValue<?> source = NamedProperties.getReadOnly(current, last);
|
||||||
|
if (source == null) {
|
||||||
throw missing(path);
|
throw missing(path);
|
||||||
}
|
}
|
||||||
boolean complex = current instanceof ViewModel stepped && stepped.isComplex(last);
|
return new Resolved(source, false, false, owner, last);
|
||||||
ViewModel owner = current instanceof ViewModel model ? model : null;
|
|
||||||
return new Resolved(attribute, complex, owner, last);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,7 +201,7 @@ final class DirectBindingApplier {
|
|||||||
* @param viewModel the ViewModel for this View
|
* @param viewModel the ViewModel for this View
|
||||||
* @param binding the declaration
|
* @param binding the declaration
|
||||||
*/
|
*/
|
||||||
private static void selectComponentViewModel(Object control, Object viewModel, DirectBinding binding) {
|
private static void selectComponentViewModel(Object control, Object viewModel, DirectBinding binding, ViewLifetime lifetime) {
|
||||||
if (!"model".equals(binding.getProperty())) {
|
if (!"model".equals(binding.getProperty())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -184,7 +213,7 @@ final class DirectBindingApplier {
|
|||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ViewModels.of(instance, requested);
|
ViewModels.of(lifetime.models(), instance, requested);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -279,23 +308,24 @@ final class DirectBindingApplier {
|
|||||||
* which is the last name of the Path.
|
* which is the last name of the Path.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void alignConverted(Property<?> controlProperty, Property<?> attribute, Converter converter,
|
private static void alignConverted(Property<?> controlProperty, ObservableValue<?> source, Converter converter,
|
||||||
ViewModel owner, String sourceName, boolean towardView, boolean towardModel) {
|
ViewModel owner, String sourceName, boolean towardView, boolean towardModel,
|
||||||
|
ViewLifetime lifetime) {
|
||||||
Property<Object> control = (Property<Object>) controlProperty;
|
Property<Object> control = (Property<Object>) controlProperty;
|
||||||
Property<Object> source = (Property<Object>) attribute;
|
|
||||||
Link link = new Link();
|
Link link = new Link();
|
||||||
pushControl(control, source, converter, owner, sourceName, link);
|
pushControl(control, source, converter, owner, sourceName, link);
|
||||||
if (towardView) {
|
if (towardView) {
|
||||||
source.addListener((observable, oldValue, newValue) -> {
|
lifetime.listen(source, (observable, oldValue, newValue) -> {
|
||||||
if (!link.applying) {
|
if (!link.applying) {
|
||||||
pushControl(control, source, converter, owner, sourceName, link);
|
pushControl(control, source, converter, owner, sourceName, link);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (towardModel) {
|
if (towardModel) {
|
||||||
control.addListener((observable, oldValue, newValue) -> {
|
Property<Object> target = (Property<Object>) source;
|
||||||
|
lifetime.listen(control, (observable, oldValue, newValue) -> {
|
||||||
if (!link.applying) {
|
if (!link.applying) {
|
||||||
pushAttribute(control, source, converter, owner, sourceName, link);
|
pushAttribute(control, target, converter, owner, sourceName, link);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -311,7 +341,7 @@ final class DirectBindingApplier {
|
|||||||
* @param source the Attribute name used as the failure source
|
* @param source the Attribute name used as the failure source
|
||||||
* @param link the guard against hearing this write
|
* @param link the guard against hearing this write
|
||||||
*/
|
*/
|
||||||
private static void pushControl(Property<Object> control, Property<Object> attribute, Converter converter,
|
private static void pushControl(Property<Object> control, ObservableValue<?> attribute, Converter converter,
|
||||||
ViewModel owner, String source, Link link) {
|
ViewModel owner, String source, Link link) {
|
||||||
try {
|
try {
|
||||||
Object shown = converter.toControlValue(attribute.getValue());
|
Object shown = converter.toControlValue(attribute.getValue());
|
||||||
@@ -321,8 +351,13 @@ final class DirectBindingApplier {
|
|||||||
} finally {
|
} finally {
|
||||||
link.applying = false;
|
link.applying = false;
|
||||||
}
|
}
|
||||||
|
if (owner != null) {
|
||||||
owner.clearBindingFailure(source);
|
owner.clearBindingFailure(source);
|
||||||
|
}
|
||||||
} catch (RuntimeException failure) {
|
} catch (RuntimeException failure) {
|
||||||
|
if (owner == null) {
|
||||||
|
throw failure;
|
||||||
|
}
|
||||||
owner.reportBindingFailure(source, failureText(failure));
|
owner.reportBindingFailure(source, failureText(failure));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,21 +447,21 @@ final class DirectBindingApplier {
|
|||||||
* @param attribute the complex Attribute
|
* @param attribute the complex Attribute
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void alignBothComplex(Property<?> controlProperty, Property<?> attribute) {
|
private static void alignBothComplex(Property<?> controlProperty, Property<?> attribute, ViewLifetime lifetime) {
|
||||||
Property<Object> control = (Property<Object>) controlProperty;
|
Property<Object> control = (Property<Object>) controlProperty;
|
||||||
Property<Object> source = (Property<Object>) attribute;
|
Property<Object> source = (Property<Object>) attribute;
|
||||||
control.setValue(modelBehind(source.getValue()));
|
control.setValue(modelBehind(source.getValue()));
|
||||||
source.addListener((observable, oldValue, newValue) -> {
|
lifetime.listen(source, (observable, oldValue, newValue) -> {
|
||||||
Object model = modelBehind(newValue);
|
Object model = modelBehind(newValue);
|
||||||
if (control.getValue() != model) {
|
if (control.getValue() != model) {
|
||||||
control.setValue(model);
|
control.setValue(model);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
control.addListener((observable, oldValue, newValue) -> {
|
lifetime.listen(control, (observable, oldValue, newValue) -> {
|
||||||
if (modelBehind(source.getValue()) == newValue) {
|
if (modelBehind(source.getValue()) == newValue) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
source.setValue(newValue == null ? null : ViewModels.of(newValue));
|
source.setValue(newValue == null ? null : ViewModels.of(lifetime.models(), newValue, null));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,11 +472,11 @@ final class DirectBindingApplier {
|
|||||||
* @param attribute the complex Attribute
|
* @param attribute the complex Attribute
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void alignTowardViewComplex(Property<?> controlProperty, Property<?> attribute) {
|
private static void alignTowardViewComplex(Property<?> controlProperty, Property<?> attribute, ViewLifetime lifetime) {
|
||||||
Property<Object> control = (Property<Object>) controlProperty;
|
Property<Object> control = (Property<Object>) controlProperty;
|
||||||
Property<Object> source = (Property<Object>) attribute;
|
Property<Object> source = (Property<Object>) attribute;
|
||||||
control.setValue(modelBehind(source.getValue()));
|
control.setValue(modelBehind(source.getValue()));
|
||||||
source.addListener((observable, oldValue, newValue) -> control.setValue(modelBehind(newValue)));
|
lifetime.listen(source, (observable, oldValue, newValue) -> control.setValue(modelBehind(newValue)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -451,15 +486,15 @@ final class DirectBindingApplier {
|
|||||||
* @param attribute the complex Attribute
|
* @param attribute the complex Attribute
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void alignTowardModelComplex(Property<?> controlProperty, Property<?> attribute) {
|
private static void alignTowardModelComplex(Property<?> controlProperty, Property<?> attribute, ViewLifetime lifetime) {
|
||||||
Property<Object> control = (Property<Object>) controlProperty;
|
Property<Object> control = (Property<Object>) controlProperty;
|
||||||
Property<Object> source = (Property<Object>) attribute;
|
Property<Object> source = (Property<Object>) attribute;
|
||||||
control.setValue(modelBehind(source.getValue()));
|
control.setValue(modelBehind(source.getValue()));
|
||||||
control.addListener((observable, oldValue, newValue) -> {
|
lifetime.listen(control, (observable, oldValue, newValue) -> {
|
||||||
if (modelBehind(source.getValue()) == newValue) {
|
if (modelBehind(source.getValue()) == newValue) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
source.setValue(newValue == null ? null : ViewModels.of(newValue));
|
source.setValue(newValue == null ? null : ViewModels.of(lifetime.models(), newValue, null));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,8 +518,13 @@ final class DirectBindingApplier {
|
|||||||
* @param values the list the ViewModel and the Model share
|
* @param values the list the ViewModel and the Model share
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void assignList(Property<?> controlProperty, ObservableList<?> values) {
|
private static void assignList(Property<?> controlProperty, ObservableList<?> values, ViewLifetime lifetime) {
|
||||||
((Property<Object>) controlProperty).setValue(values);
|
Property<Object> target = (Property<Object>) controlProperty;
|
||||||
|
Object previous = target.getValue();
|
||||||
|
target.setValue(values);
|
||||||
|
lifetime.own(() -> {
|
||||||
|
if (target.getValue() == values) target.setValue(previous);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -494,8 +534,11 @@ final class DirectBindingApplier {
|
|||||||
* @param attribute the Attribute
|
* @param attribute the Attribute
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void alignBoth(Property<?> controlProperty, Property<?> attribute) {
|
private static void alignBoth(Property<?> controlProperty, Property<?> attribute, ViewLifetime lifetime) {
|
||||||
((Property<Object>) controlProperty).bindBidirectional((Property<Object>) attribute);
|
Property<Object> control = (Property<Object>) controlProperty;
|
||||||
|
Property<Object> source = (Property<Object>) attribute;
|
||||||
|
control.bindBidirectional(source);
|
||||||
|
lifetime.own(() -> control.unbindBidirectional(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -505,11 +548,11 @@ final class DirectBindingApplier {
|
|||||||
* @param attribute the Attribute
|
* @param attribute the Attribute
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void alignTowardView(Property<?> controlProperty, Property<?> attribute) {
|
private static void alignTowardView(Property<?> controlProperty, ObservableValue<?> attribute,
|
||||||
|
ViewLifetime lifetime) {
|
||||||
Property<Object> control = (Property<Object>) controlProperty;
|
Property<Object> control = (Property<Object>) controlProperty;
|
||||||
Property<Object> source = (Property<Object>) attribute;
|
control.setValue(attribute.getValue());
|
||||||
control.setValue(source.getValue());
|
lifetime.listen(attribute, (observable, oldValue, newValue) -> control.setValue(newValue));
|
||||||
source.addListener((observable, oldValue, newValue) -> control.setValue(newValue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -519,10 +562,10 @@ final class DirectBindingApplier {
|
|||||||
* @param attribute the Attribute
|
* @param attribute the Attribute
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void alignTowardModel(Property<?> controlProperty, Property<?> attribute) {
|
private static void alignTowardModel(Property<?> controlProperty, Property<?> attribute, ViewLifetime lifetime) {
|
||||||
Property<Object> control = (Property<Object>) controlProperty;
|
Property<Object> control = (Property<Object>) controlProperty;
|
||||||
Property<Object> target = (Property<Object>) attribute;
|
Property<Object> target = (Property<Object>) attribute;
|
||||||
control.setValue(target.getValue());
|
control.setValue(target.getValue());
|
||||||
control.addListener((observable, oldValue, newValue) -> target.setValue(newValue));
|
lifetime.listen(control, (observable, oldValue, newValue) -> target.setValue(newValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.List;
|
||||||
|
import javafx.beans.property.Property;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.fxml.LoadListener;
|
||||||
|
|
||||||
|
/** Removes handler properties assigned by the managed FXML document when its View closes. */
|
||||||
|
final class FxmlHandlers implements LoadListener {
|
||||||
|
|
||||||
|
private final ViewLifetime lifetime;
|
||||||
|
private final Deque<List<String>> handlers = new ArrayDeque<>();
|
||||||
|
|
||||||
|
private FxmlHandlers(ViewLifetime lifetime) {
|
||||||
|
this.lifetime = lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void observe(FXMLLoader loader, ViewLifetime lifetime) {
|
||||||
|
if (lifetime.managed()) loader.setLoadListener(new FxmlHandlers(lifetime));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readEventHandlerAttribute(String name, String value) {
|
||||||
|
handlers.getLast().add(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(Object value) {
|
||||||
|
List<String> attributes = handlers.removeLast();
|
||||||
|
if (value == null) return;
|
||||||
|
for (String attribute : attributes) {
|
||||||
|
Property<?> property = NamedProperties.get(value, attribute);
|
||||||
|
if (property != null && property.getValue() instanceof EventHandler<?> handler) {
|
||||||
|
lifetime.own(() -> {
|
||||||
|
if (property.getValue() == handler) property.setValue(null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void beginElement() {
|
||||||
|
handlers.addLast(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void beginInstanceDeclarationElement(Class<?> type) { beginElement(); }
|
||||||
|
@Override public void beginUnknownTypeElement(String name) { beginElement(); }
|
||||||
|
@Override public void beginIncludeElement() { beginElement(); }
|
||||||
|
@Override public void beginReferenceElement() { beginElement(); }
|
||||||
|
@Override public void beginCopyElement() { beginElement(); }
|
||||||
|
@Override public void beginRootElement() { beginElement(); }
|
||||||
|
@Override public void beginPropertyElement(String name, Class<?> sourceType) { beginElement(); }
|
||||||
|
@Override public void beginUnknownStaticPropertyElement(String name) { beginElement(); }
|
||||||
|
@Override public void beginScriptElement() { beginElement(); }
|
||||||
|
@Override public void beginDefineElement() { beginElement(); }
|
||||||
|
|
||||||
|
@Override public void readImportProcessingInstruction(String target) { }
|
||||||
|
@Override public void readLanguageProcessingInstruction(String language) { }
|
||||||
|
@Override public void readComment(String comment) { }
|
||||||
|
@Override public void readInternalAttribute(String name, String value) { }
|
||||||
|
@Override public void readPropertyAttribute(String name, Class<?> sourceType, String value) { }
|
||||||
|
@Override public void readUnknownStaticPropertyAttribute(String name, String value) { }
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ import java.util.Set;
|
|||||||
final class LoadSession {
|
final class LoadSession {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sessions open on this thread. The last one is the outermost load.
|
* The sessions open on this thread, with the current session first.
|
||||||
*/
|
*/
|
||||||
private static final ThreadLocal<Deque<LoadSession>> STACK = new ThreadLocal<>();
|
private static final ThreadLocal<Deque<LoadSession>> STACK = new ThreadLocal<>();
|
||||||
|
|
||||||
@@ -32,25 +32,33 @@ final class LoadSession {
|
|||||||
*/
|
*/
|
||||||
private final Set<Class<?>> built = new HashSet<>();
|
private final Set<Class<?>> built = new HashSet<>();
|
||||||
|
|
||||||
|
private Throwable bindingFailure;
|
||||||
|
|
||||||
|
// JavaFX reports exceptions from a property listener to the thread's uncaught handler.
|
||||||
|
// Keep a synchronous Component failure with the load that triggered that property change.
|
||||||
|
static boolean recordFailure(Throwable failure) {
|
||||||
|
Deque<LoadSession> stack = STACK.get();
|
||||||
|
if (stack == null) return false;
|
||||||
|
LoadSession session = stack.peek();
|
||||||
|
if (session.bindingFailure == null) {
|
||||||
|
session.bindingFailure = failure;
|
||||||
|
} else if (session.bindingFailure != failure) {
|
||||||
|
session.bindingFailure.addSuppressed(failure);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkFailure() {
|
||||||
|
if (bindingFailure instanceof RuntimeException runtime) throw runtime;
|
||||||
|
if (bindingFailure instanceof Error error) throw error;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevents instantiation from outside this class.
|
* Prevents instantiation from outside this class.
|
||||||
*/
|
*/
|
||||||
private LoadSession() {
|
private LoadSession() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts a session on this thread.
|
|
||||||
*
|
|
||||||
* @return the open session
|
|
||||||
*/
|
|
||||||
static LoadSession open() {
|
|
||||||
Deque<LoadSession> stack = new ArrayDeque<>();
|
|
||||||
LoadSession session = new LoadSession();
|
|
||||||
stack.push(session);
|
|
||||||
STACK.set(stack);
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a nested session for a Component document.
|
* Opens a nested session for a Component document.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -84,13 +92,6 @@ final class LoadSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Drops the session for this thread.
|
|
||||||
*/
|
|
||||||
static void close() {
|
|
||||||
STACK.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a binding list created while a session is open.
|
* Registers a binding list created while a session is open.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
* The scene-graph root and ViewModel produced by loading a View for a Model instance.
|
* The scene-graph root and ViewModel produced by loading a View for a Model instance.
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||||
public final class LoadedView {
|
public final class LoadedView implements AutoCloseable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The scene-graph root of the loaded View.
|
* The scene-graph root of the loaded View.
|
||||||
@@ -23,6 +23,17 @@ public final class LoadedView {
|
|||||||
*/
|
*/
|
||||||
private final Object viewModel;
|
private final Object viewModel;
|
||||||
|
|
||||||
|
private final ViewLifetime lifetime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases the resources owned by a managed View. Calling this twice is harmless.
|
||||||
|
* Use the ViewLoader overload taking a ViewModelContext to opt into managed lifetimes.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
lifetime.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ViewModel the View is bound to.
|
* Returns the ViewModel the View is bound to.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.neitzel.fx.view;
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
import javafx.beans.property.Property;
|
import javafx.beans.property.Property;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -26,17 +27,31 @@ final class NamedProperties {
|
|||||||
* @return the property, or {@code null} when {@code bean} declares none of that name
|
* @return the property, or {@code null} when {@code bean} declares none of that name
|
||||||
*/
|
*/
|
||||||
static Property<?> get(Object bean, String name) {
|
static Property<?> get(Object bean, String name) {
|
||||||
|
Object value = read(bean, name, true);
|
||||||
|
return value instanceof Property<?> property ? property : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a named observable whose accessor exposes a read-only source.
|
||||||
|
*
|
||||||
|
* @param bean the object that declares the source
|
||||||
|
* @param name the source name
|
||||||
|
* @return the source or {@code null} when there is no such accessor or it returns {@code null}
|
||||||
|
*/
|
||||||
|
static ObservableValue<?> getReadOnly(Object bean, String name) {
|
||||||
|
Object value = read(bean, name, false);
|
||||||
|
return value instanceof ObservableValue<?> source ? source : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object read(Object bean, String name, boolean writable) {
|
||||||
String methodName = name + "Property";
|
String methodName = name + "Property";
|
||||||
try {
|
try {
|
||||||
Method method = bean.getClass().getMethod(methodName);
|
Method method = bean.getClass().getMethod(methodName);
|
||||||
if (!Property.class.isAssignableFrom(method.getReturnType())) {
|
Class<?> type = method.getReturnType();
|
||||||
|
if (!ObservableValue.class.isAssignableFrom(type) || writable != Property.class.isAssignableFrom(type)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Object value = method.invoke(bean);
|
return method.invoke(bean);
|
||||||
if (value instanceof Property<?> property) {
|
|
||||||
return property;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} catch (NoSuchMethodException notDeclared) {
|
} catch (NoSuchMethodException notDeclared) {
|
||||||
return null;
|
return null;
|
||||||
} catch (IllegalAccessException | InvocationTargetException failure) {
|
} catch (IllegalAccessException | InvocationTargetException failure) {
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ package de.neitzel.fx.view;
|
|||||||
|
|
||||||
import de.neitzel.injection.ApplicationContext;
|
import de.neitzel.injection.ApplicationContext;
|
||||||
import javafx.beans.property.Property;
|
import javafx.beans.property.Property;
|
||||||
import javafx.collections.ListChangeListener;
|
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,7 +35,7 @@ final class RepeatApplier {
|
|||||||
* @param context the container that creates each Component
|
* @param context the container that creates each Component
|
||||||
*/
|
*/
|
||||||
static void apply(Map<String, Object> namespace, Object viewModel, Repeat repeat,
|
static void apply(Map<String, Object> namespace, Object viewModel, Repeat repeat,
|
||||||
ApplicationContext context) {
|
ApplicationContext context, ViewLifetime lifetime) {
|
||||||
Object named = namespace.get(repeat.getPane());
|
Object named = namespace.get(repeat.getPane());
|
||||||
if (!(named instanceof Pane pane)) {
|
if (!(named instanceof Pane pane)) {
|
||||||
throw new IllegalArgumentException("No pane \"" + repeat.getPane() + "\"");
|
throw new IllegalArgumentException("No pane \"" + repeat.getPane() + "\"");
|
||||||
@@ -44,10 +45,15 @@ final class RepeatApplier {
|
|||||||
throw new IllegalArgumentException("No collection \"" + repeat.getCollection() + "\"");
|
throw new IllegalArgumentException("No collection \"" + repeat.getCollection() + "\"");
|
||||||
}
|
}
|
||||||
Class<?> type = componentType(repeat.getComponent());
|
Class<?> type = componentType(repeat.getComponent());
|
||||||
|
int offset = pane.getChildren().size();
|
||||||
|
List<RepeatedChild> children = new ArrayList<>();
|
||||||
|
lifetime.own(() -> pane.getChildren().removeAll(children.stream().map(RepeatedChild::node).toList()));
|
||||||
for (Object element : values) {
|
for (Object element : values) {
|
||||||
pane.getChildren().add(child(type, context, element));
|
RepeatedChild child = child(type, context, element, lifetime);
|
||||||
|
children.add(child);
|
||||||
|
pane.getChildren().add(child.node());
|
||||||
}
|
}
|
||||||
listen(pane, type, context, values);
|
listen(pane, type, context, values, lifetime, offset, children);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,20 +82,24 @@ final class RepeatApplier {
|
|||||||
* @param values the collection
|
* @param values the collection
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void listen(Pane pane, Class<?> type, ApplicationContext context, ObservableList<?> values) {
|
private static void listen(Pane pane, Class<?> type, ApplicationContext context, ObservableList<?> values,
|
||||||
|
ViewLifetime lifetime, int offset, List<RepeatedChild> children) {
|
||||||
ObservableList<Object> elements = (ObservableList<Object>) values;
|
ObservableList<Object> elements = (ObservableList<Object>) values;
|
||||||
elements.addListener((ListChangeListener<Object>) change -> {
|
lifetime.listen(elements, change -> {
|
||||||
while (change.next()) {
|
while (change.next()) {
|
||||||
if (change.wasPermutated() || change.wasUpdated()) {
|
if (change.wasPermutated() || change.wasUpdated()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (change.getRemovedSize() > 0) {
|
for (int removed = 0; removed < change.getRemovedSize(); removed++) {
|
||||||
pane.getChildren().remove(change.getFrom(), change.getFrom() + change.getRemovedSize());
|
RepeatedChild child = children.remove(change.getFrom());
|
||||||
|
pane.getChildren().remove(child.node());
|
||||||
|
child.lifetime().close();
|
||||||
}
|
}
|
||||||
for (int index = 0; index < change.getAddedSize(); index++) {
|
for (int index = 0; index < change.getAddedSize(); index++) {
|
||||||
pane.getChildren().add(
|
RepeatedChild child = child(type, context, change.getAddedSubList().get(index), lifetime);
|
||||||
change.getFrom() + index,
|
int position = change.getFrom() + index;
|
||||||
child(type, context, change.getAddedSubList().get(index)));
|
children.add(position, child);
|
||||||
|
pane.getChildren().add(offset + position, child.node());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -103,11 +113,20 @@ final class RepeatApplier {
|
|||||||
* @param element the Model instance
|
* @param element the Model instance
|
||||||
* @return the loaded Component
|
* @return the loaded Component
|
||||||
*/
|
*/
|
||||||
private static Node child(Class<?> type, ApplicationContext context, Object element) {
|
private static RepeatedChild child(Class<?> type, ApplicationContext context, Object element,
|
||||||
Object component = Components.fresh(type, context);
|
ViewLifetime owner) {
|
||||||
Components.setModel(component, element);
|
ViewLifetime lifetime = owner.child();
|
||||||
return (Node) component;
|
try {
|
||||||
|
Object component = Components.fresh(type, context, lifetime);
|
||||||
|
Components.setModel(component, element, lifetime);
|
||||||
|
return new RepeatedChild((Node) component, lifetime);
|
||||||
|
} catch (RuntimeException | Error failure) {
|
||||||
|
lifetime.rollback(failure);
|
||||||
|
throw failure;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record RepeatedChild(Node node, ViewLifetime lifetime) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Component class named by the repeat.
|
* Returns the Component class named by the repeat.
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ final class ResultColumnSeparators extends Group {
|
|||||||
return decoration;
|
return decoration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean matchesColumnCount(int columns) {
|
||||||
|
return getChildren().size() == Math.max(0, columns - 1);
|
||||||
|
}
|
||||||
|
|
||||||
void position(double[] widths) {
|
void position(double[] widths) {
|
||||||
double x = 0;
|
double x = 0;
|
||||||
for (int i = 0; i < getChildren().size(); i++) {
|
for (int i = 0; i < getChildren().size(); i++) {
|
||||||
|
|||||||
@@ -343,13 +343,10 @@ final class ResultHeaderGestures implements AutoCloseable {
|
|||||||
headerViewport = pane;
|
headerViewport = pane;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (scroll == null
|
if (scroll == null || headerViewport == null || Double.isNaN(pointerX))
|
||||||
|| headerViewport == null
|
return;
|
||||||
|| Double.isNaN(pointerX)
|
var bounds = headerViewport.localToScene(headerViewport.getBoundsInLocal());
|
||||||
|| !headerViewport
|
if (!bounds.contains(pointerX, pointerY)) return;
|
||||||
.localToScene(headerViewport.getBoundsInLocal())
|
|
||||||
.contains(pointerX, pointerY)) return;
|
|
||||||
var bounds = scroll.localToScene(scroll.getViewportBounds());
|
|
||||||
double delta =
|
double delta =
|
||||||
pointerX < bounds.getMinX() + 30
|
pointerX < bounds.getMinX() + 30
|
||||||
? -.012
|
? -.012
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package de.neitzel.fx.view;
|
|||||||
|
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.beans.binding.DoubleBinding;
|
import javafx.beans.binding.DoubleBinding;
|
||||||
|
import javafx.beans.binding.ObjectBinding;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
@@ -9,29 +11,43 @@ import javafx.scene.layout.VBox;
|
|||||||
/** Makes equal normalized scroll values represent equal pixel offsets in queried results. */
|
/** Makes equal normalized scroll values represent equal pixel offsets in queried results. */
|
||||||
final class ResultScrollAlignment implements AutoCloseable {
|
final class ResultScrollAlignment implements AutoCloseable {
|
||||||
private final HBox header;
|
private final HBox header;
|
||||||
|
private final VBox body;
|
||||||
private final double originalMinimum;
|
private final double originalMinimum;
|
||||||
|
private final Insets originalPadding;
|
||||||
|
private final ObjectBinding<Insets> bodyPadding;
|
||||||
private final DoubleBinding minimum;
|
private final DoubleBinding minimum;
|
||||||
|
private final DoubleBinding viewportDifference;
|
||||||
|
|
||||||
ResultScrollAlignment(HBox header, VBox body, ScrollPane headerScroll, ScrollPane bodyScroll) {
|
ResultScrollAlignment(
|
||||||
|
HBox header, VBox body, ScrollPane headerScroll, ScrollPane bodyScroll,
|
||||||
|
boolean hasHeaderAccessory) {
|
||||||
this.header = header;
|
this.header = header;
|
||||||
|
this.body = body;
|
||||||
originalMinimum = header.getMinWidth();
|
originalMinimum = header.getMinWidth();
|
||||||
|
originalPadding = body.getPadding();
|
||||||
|
viewportDifference = Bindings.createDoubleBinding(
|
||||||
|
() -> headerScroll.getViewportBounds().getWidth()
|
||||||
|
- bodyScroll.getViewportBounds().getWidth(),
|
||||||
|
headerScroll.viewportBoundsProperty(), bodyScroll.viewportBoundsProperty());
|
||||||
|
// The fixed header menu can make the header viewport narrower. Add trailing body space
|
||||||
|
// so the last column can scroll fully into view in both viewports.
|
||||||
|
bodyPadding = hasHeaderAccessory ? Bindings.createObjectBinding(
|
||||||
|
() -> new Insets(originalPadding.getTop(),
|
||||||
|
originalPadding.getRight() + Math.max(0, -viewportDifference.get()),
|
||||||
|
originalPadding.getBottom(), originalPadding.getLeft()),
|
||||||
|
viewportDifference) : null;
|
||||||
|
if (bodyPadding != null) body.paddingProperty().bind(bodyPadding);
|
||||||
// A vertical body scrollbar narrows its viewport. Trailing row actions can also
|
// A vertical body scrollbar narrows its viewport. Trailing row actions can also
|
||||||
// make its content wider than the column headings. Reserve blank header space
|
// make its content wider than the column headings. Reserve blank header space
|
||||||
// so both scrollable extents match; the existing two-way hvalue binding then
|
// so both scrollable extents match; the existing two-way hvalue binding then
|
||||||
// moves every mapped field and heading by the same number of pixels.
|
// moves every mapped field and heading by the same number of pixels.
|
||||||
minimum =
|
minimum =
|
||||||
Bindings.createDoubleBinding(
|
Bindings.createDoubleBinding(
|
||||||
() ->
|
() -> body.getLayoutBounds().getWidth()
|
||||||
body.getLayoutBounds().getWidth()
|
+ (hasHeaderAccessory
|
||||||
+ Math.max(
|
? viewportDifference.get()
|
||||||
0,
|
: Math.max(0, viewportDifference.get())),
|
||||||
headerScroll.getViewportBounds().getWidth()
|
body.layoutBoundsProperty(), viewportDifference);
|
||||||
- bodyScroll
|
|
||||||
.getViewportBounds()
|
|
||||||
.getWidth()),
|
|
||||||
body.layoutBoundsProperty(),
|
|
||||||
headerScroll.viewportBoundsProperty(),
|
|
||||||
bodyScroll.viewportBoundsProperty());
|
|
||||||
header.minWidthProperty().bind(minimum);
|
header.minWidthProperty().bind(minimum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,5 +56,11 @@ final class ResultScrollAlignment implements AutoCloseable {
|
|||||||
header.minWidthProperty().unbind();
|
header.minWidthProperty().unbind();
|
||||||
header.setMinWidth(originalMinimum);
|
header.setMinWidth(originalMinimum);
|
||||||
minimum.dispose();
|
minimum.dispose();
|
||||||
|
if (bodyPadding != null) {
|
||||||
|
body.paddingProperty().unbind();
|
||||||
|
body.setPadding(originalPadding);
|
||||||
|
bodyPadding.dispose();
|
||||||
|
}
|
||||||
|
viewportDifference.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import javafx.beans.property.Property;
|
|||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
@@ -156,6 +157,8 @@ public class Table extends VBox {
|
|||||||
* One Row per element that has been shown. A hidden element keeps its Row.
|
* One Row per element that has been shown. A hidden element keeps its Row.
|
||||||
*/
|
*/
|
||||||
private final Map<Object, Node> rows = new IdentityHashMap<>();
|
private final Map<Object, Node> rows = new IdentityHashMap<>();
|
||||||
|
private final Map<Object, ViewLifetime> rowLifetimes = new IdentityHashMap<>();
|
||||||
|
private ViewLifetime lifetime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The collection this Table shows.
|
* The collection this Table shows.
|
||||||
@@ -246,13 +249,26 @@ public class Table extends VBox {
|
|||||||
*/
|
*/
|
||||||
public <K, T> TableResults<K, T> openResults(List<ResultColumn> definitions,
|
public <K, T> TableResults<K, T> openResults(List<ResultColumn> definitions,
|
||||||
java.util.function.Function<T, ResultRow> factory) {
|
java.util.function.Function<T, ResultRow> factory) {
|
||||||
|
return openResults(definitions, factory, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
<K, T> TableResults<K, T> openResults(List<ResultColumn> definitions,
|
||||||
|
java.util.function.Function<T, ResultRow> factory, Region headerAccessory) {
|
||||||
if (!javafx.application.Platform.isFxApplicationThread()) {
|
if (!javafx.application.Platform.isFxApplicationThread()) {
|
||||||
throw new IllegalStateException("Use the JavaFX application thread");
|
throw new IllegalStateException("Use the JavaFX application thread");
|
||||||
}
|
}
|
||||||
if (opened || resultMode) {
|
if (opened || resultMode) {
|
||||||
throw new IllegalStateException("Table is already open");
|
throw new IllegalStateException("Table is already open");
|
||||||
}
|
}
|
||||||
TableResults<K, T> renderer = new TableResults<>(header, body, List.copyOf(definitions), factory, headerScroll, scroll);
|
TableResults<K, T> renderer = new TableResults<>(
|
||||||
|
header, body, List.copyOf(definitions), factory, headerScroll, scroll, headerAccessory);
|
||||||
|
if (headerAccessory != null) {
|
||||||
|
getChildren().remove(headerScroll);
|
||||||
|
headerScroll.setMinWidth(0);
|
||||||
|
HBox.setHgrow(headerScroll, Priority.ALWAYS);
|
||||||
|
headerAccessory.setMaxHeight(Double.MAX_VALUE);
|
||||||
|
getChildren().addFirst(new HBox(headerScroll, headerAccessory));
|
||||||
|
}
|
||||||
// DataGrid grows this Table; let its viewport consume that height as well.
|
// DataGrid grows this Table; let its viewport consume that height as well.
|
||||||
VBox.setVgrow(scroll, Priority.ALWAYS);
|
VBox.setVgrow(scroll, Priority.ALWAYS);
|
||||||
resultMode = true;
|
resultMode = true;
|
||||||
@@ -347,8 +363,8 @@ public class Table extends VBox {
|
|||||||
* @param viewModel the ViewModel for this View
|
* @param viewModel the ViewModel for this View
|
||||||
* @param context the container that creates each Row
|
* @param context the container that creates each Row
|
||||||
*/
|
*/
|
||||||
static void openAll(Parent root, Object viewModel, ApplicationContext context) {
|
static void openAll(Parent root, Object viewModel, ApplicationContext context, ViewLifetime lifetime) {
|
||||||
walk(root, viewModel, context);
|
walk(root, root, viewModel, context, lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -357,7 +373,7 @@ public class Table extends VBox {
|
|||||||
* @param viewModel the ViewModel for this View
|
* @param viewModel the ViewModel for this View
|
||||||
* @param context the container that creates each Row
|
* @param context the container that creates each Row
|
||||||
*/
|
*/
|
||||||
void open(Object viewModel, ApplicationContext context) {
|
void open(Object viewModel, ApplicationContext context, ViewLifetime owner) {
|
||||||
if (resultMode) {
|
if (resultMode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -366,6 +382,15 @@ public class Table extends VBox {
|
|||||||
}
|
}
|
||||||
opened = true;
|
opened = true;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
lifetime = owner.child();
|
||||||
|
lifetime.own(() -> {
|
||||||
|
rowLifetimes.clear();
|
||||||
|
rows.clear();
|
||||||
|
body.getChildren().clear();
|
||||||
|
elements = FXCollections.observableArrayList();
|
||||||
|
selection.set(null);
|
||||||
|
this.context = null;
|
||||||
|
});
|
||||||
if (columns.isEmpty()) {
|
if (columns.isEmpty()) {
|
||||||
throw new IllegalArgumentException("A table needs a column");
|
throw new IllegalArgumentException("A table needs a column");
|
||||||
}
|
}
|
||||||
@@ -380,7 +405,7 @@ public class Table extends VBox {
|
|||||||
}
|
}
|
||||||
buildHeader();
|
buildHeader();
|
||||||
ensureWidths();
|
ensureWidths();
|
||||||
elements.addListener((ListChangeListener<Object>) this::onCollectionChange);
|
lifetime.listen(elements, this::onCollectionChange);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1169,6 +1194,8 @@ public class Table extends VBox {
|
|||||||
}
|
}
|
||||||
for (Object removed : change.getRemoved()) {
|
for (Object removed : change.getRemoved()) {
|
||||||
rows.remove(removed);
|
rows.remove(removed);
|
||||||
|
ViewLifetime removedRow = rowLifetimes.remove(removed);
|
||||||
|
if (removedRow != null) removedRow.close();
|
||||||
if (selection.get() == removed) {
|
if (selection.get() == removed) {
|
||||||
selection.set(null);
|
selection.set(null);
|
||||||
}
|
}
|
||||||
@@ -1297,18 +1324,27 @@ public class Table extends VBox {
|
|||||||
* @return the Row
|
* @return the Row
|
||||||
*/
|
*/
|
||||||
private Node createRow(Object element) {
|
private Node createRow(Object element) {
|
||||||
Object component = Components.fresh(rowType, context);
|
ViewLifetime rowLifetime = lifetime.child();
|
||||||
Components.setModel(component, element);
|
try {
|
||||||
|
Object component = Components.fresh(rowType, context, rowLifetime);
|
||||||
|
Components.setModel(component, element, rowLifetime);
|
||||||
if (!(component instanceof Node node)) {
|
if (!(component instanceof Node node)) {
|
||||||
throw new IllegalArgumentException("Row is not a node: " + rowType.getName());
|
throw new IllegalArgumentException("Row is not a node: " + rowType.getName());
|
||||||
}
|
}
|
||||||
node.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
|
EventHandler<MouseEvent> select = event -> {
|
||||||
if (event.getButton() == MouseButton.PRIMARY) {
|
if (event.getButton() == MouseButton.PRIMARY) {
|
||||||
selection.set(element);
|
selection.set(element);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
watchEdits(node);
|
node.addEventFilter(MouseEvent.MOUSE_CLICKED, select);
|
||||||
|
rowLifetime.own(() -> node.removeEventFilter(MouseEvent.MOUSE_CLICKED, select));
|
||||||
|
watchEdits(node, rowLifetime);
|
||||||
|
if (rowLifetime.managed()) rowLifetimes.put(element, rowLifetime);
|
||||||
return node;
|
return node;
|
||||||
|
} catch (RuntimeException | Error failure) {
|
||||||
|
rowLifetime.rollback(failure);
|
||||||
|
throw failure;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1316,13 +1352,13 @@ public class Table extends VBox {
|
|||||||
*
|
*
|
||||||
* @param node the Row or one of its fields
|
* @param node the Row or one of its fields
|
||||||
*/
|
*/
|
||||||
private void watchEdits(Node node) {
|
private void watchEdits(Node node, ViewLifetime rowLifetime) {
|
||||||
if (node instanceof javafx.scene.control.TextInputControl input) {
|
if (node instanceof javafx.scene.control.TextInputControl input) {
|
||||||
input.textProperty().addListener((observable, previous, current) -> refresh());
|
rowLifetime.listen(input.textProperty(), (observable, previous, current) -> refresh());
|
||||||
}
|
}
|
||||||
if (node instanceof Parent parent) {
|
if (node instanceof Parent parent) {
|
||||||
for (Node child : parent.getChildrenUnmodifiable()) {
|
for (Node child : parent.getChildrenUnmodifiable()) {
|
||||||
watchEdits(child);
|
watchEdits(child, rowLifetime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1530,18 +1566,20 @@ public class Table extends VBox {
|
|||||||
* @param viewModel the ViewModel for this View
|
* @param viewModel the ViewModel for this View
|
||||||
* @param context the container that creates each Row
|
* @param context the container that creates each Row
|
||||||
*/
|
*/
|
||||||
private static void walk(Node node, Object viewModel, ApplicationContext context) {
|
private static void walk(Node node, Parent root, Object viewModel, ApplicationContext context,
|
||||||
|
ViewLifetime lifetime) {
|
||||||
|
if (node != root && Components.ownsBindings(node)) return;
|
||||||
if (node instanceof Table table) {
|
if (node instanceof Table table) {
|
||||||
table.open(viewModel, context);
|
table.open(viewModel, context, lifetime);
|
||||||
}
|
}
|
||||||
if (!(node instanceof Parent parent)) {
|
if (!(node instanceof Parent parent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (Node child : parent.getChildrenUnmodifiable()) {
|
for (Node child : parent.getChildrenUnmodifiable()) {
|
||||||
walk(child, viewModel, context);
|
walk(child, root, viewModel, context, lifetime);
|
||||||
}
|
}
|
||||||
if (parent instanceof ScrollPane pane && pane.getContent() != null) {
|
if (parent instanceof ScrollPane pane && pane.getContent() != null) {
|
||||||
walk(pane.getContent(), viewModel, context);
|
walk(pane.getContent(), root, viewModel, context, lifetime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import javafx.collections.*;
|
|||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ContextMenu;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.Tooltip;
|
import javafx.scene.control.Tooltip;
|
||||||
|
import javafx.geometry.Side;
|
||||||
import javafx.scene.input.MouseButton;
|
import javafx.scene.input.MouseButton;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
@@ -20,6 +22,7 @@ import javafx.scene.layout.VBox;
|
|||||||
import javafx.scene.shape.SVGPath;
|
import javafx.scene.shape.SVGPath;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,10 +34,12 @@ import java.util.function.Function;
|
|||||||
public final class TableResults<K, T> implements AutoCloseable {
|
public final class TableResults<K, T> implements AutoCloseable {
|
||||||
private final HBox header;
|
private final HBox header;
|
||||||
private final VBox body;
|
private final VBox body;
|
||||||
|
private final Region headerAccessory;
|
||||||
private final Function<T, ResultRow> factory;
|
private final Function<T, ResultRow> factory;
|
||||||
private final Map<String, ResultColumn> definitions = new LinkedHashMap<>();
|
private final Map<String, ResultColumn> definitions = new LinkedHashMap<>();
|
||||||
private final Map<String, ColumnWidth> widths = new LinkedHashMap<>();
|
private final Map<String, ColumnWidth> widths = new LinkedHashMap<>();
|
||||||
private List<String> order;
|
private List<String> order;
|
||||||
|
private final Set<String> hiddenColumns = new HashSet<>();
|
||||||
private List<Entry<K, T>> entries = List.of();
|
private List<Entry<K, T>> entries = List.of();
|
||||||
private final ReadOnlyObjectWrapper<K> selectedKey = new ReadOnlyObjectWrapper<>();
|
private final ReadOnlyObjectWrapper<K> selectedKey = new ReadOnlyObjectWrapper<>();
|
||||||
private final ReadOnlyObjectWrapper<T> selectedElement = new ReadOnlyObjectWrapper<>();
|
private final ReadOnlyObjectWrapper<T> selectedElement = new ReadOnlyObjectWrapper<>();
|
||||||
@@ -56,6 +61,8 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
private List<SortKey> sortKeys = List.of();
|
private List<SortKey> sortKeys = List.of();
|
||||||
private java.util.function.BiConsumer<String, Node> filterRequest = (id, node) -> {};
|
private java.util.function.BiConsumer<String, Node> filterRequest = (id, node) -> {};
|
||||||
private java.util.function.Consumer<String> sortRequest = id -> {};
|
private java.util.function.Consumer<String> sortRequest = id -> {};
|
||||||
|
private BiFunction<String, HBox, ContextMenu> headerMenuFactory;
|
||||||
|
private ContextMenu headerMenu;
|
||||||
|
|
||||||
private List<GroupColumn<T>> groupColumns = List.of();
|
private List<GroupColumn<T>> groupColumns = List.of();
|
||||||
private List<String> grouping = List.of();
|
private List<String> grouping = List.of();
|
||||||
@@ -79,10 +86,12 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
List<ResultColumn> columns,
|
List<ResultColumn> columns,
|
||||||
Function<T, ResultRow> factory,
|
Function<T, ResultRow> factory,
|
||||||
javafx.scene.control.ScrollPane headerScroll,
|
javafx.scene.control.ScrollPane headerScroll,
|
||||||
javafx.scene.control.ScrollPane bodyScroll) {
|
javafx.scene.control.ScrollPane bodyScroll,
|
||||||
|
Region headerAccessory) {
|
||||||
requireFx();
|
requireFx();
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.body = body;
|
this.body = body;
|
||||||
|
this.headerAccessory = headerAccessory;
|
||||||
this.factory = Objects.requireNonNull(factory);
|
this.factory = Objects.requireNonNull(factory);
|
||||||
gestures = new ResultHeaderGestures(this, header, body);
|
gestures = new ResultHeaderGestures(this, header, body);
|
||||||
if (columns.isEmpty())
|
if (columns.isEmpty())
|
||||||
@@ -94,7 +103,8 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
order = List.copyOf(definitions.keySet());
|
order = List.copyOf(definitions.keySet());
|
||||||
validateOrder(order);
|
validateOrder(order);
|
||||||
scrollAlignment = new ResultScrollAlignment(header, body, headerScroll, bodyScroll);
|
scrollAlignment = new ResultScrollAlignment(
|
||||||
|
header, body, headerScroll, bodyScroll, headerAccessory != null);
|
||||||
drawHeader();
|
drawHeader();
|
||||||
body.setOnMouseClicked(e -> {
|
body.setOnMouseClicked(e -> {
|
||||||
if (e.getTarget() == body && e.getButton() == MouseButton.PRIMARY) select(null);
|
if (e.getTarget() == body && e.getButton() == MouseButton.PRIMARY) select(null);
|
||||||
@@ -105,7 +115,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
checkOpen();
|
checkOpen();
|
||||||
columnSeparators = true;
|
columnSeparators = true;
|
||||||
drawHeader();
|
drawHeader();
|
||||||
entries.forEach(e -> layoutRow(e.view()));
|
applyWidths(widths);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReadOnlyObjectProperty<K> selectedKeyProperty() {
|
public ReadOnlyObjectProperty<K> selectedKeyProperty() {
|
||||||
@@ -143,6 +153,27 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
return Map.copyOf(widths);
|
return Map.copyOf(widths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isColumnVisible(String id) {
|
||||||
|
checkOpen();
|
||||||
|
if (!definitions.containsKey(id)) throw new IllegalArgumentException("Unknown column: " + id);
|
||||||
|
return !hiddenColumns.contains(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setColumnVisible(String id, boolean visible) {
|
||||||
|
if (visible == isColumnVisible(id)) return;
|
||||||
|
Node focus = header.getScene() == null ? null : header.getScene().getFocusOwner();
|
||||||
|
boolean headerFocused = focus != null && descendant(header, focus);
|
||||||
|
if (visible) hiddenColumns.remove(id);
|
||||||
|
else hiddenColumns.add(id);
|
||||||
|
drawHeader();
|
||||||
|
applyWidths(widths);
|
||||||
|
if (headerFocused && headerAccessory != null) headerAccessory.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> visibleOrder(List<String> ordering) {
|
||||||
|
return ordering.stream().filter(id -> !hiddenColumns.contains(id)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
/** Marks retained rows unavailable without disabling header/query controls. */
|
/** Marks retained rows unavailable without disabling header/query controls. */
|
||||||
public void setRowsInteractive(boolean interactive) {
|
public void setRowsInteractive(boolean interactive) {
|
||||||
checkOpen();
|
checkOpen();
|
||||||
@@ -157,6 +188,11 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
sortRequest = Objects.requireNonNull(handler);
|
sortRequest = Objects.requireNonNull(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setHeaderMenuFactory(BiFunction<String, HBox, ContextMenu> factory) {
|
||||||
|
checkOpen();
|
||||||
|
headerMenuFactory = Objects.requireNonNull(factory);
|
||||||
|
}
|
||||||
|
|
||||||
/** Opt-in filter actions; clicking the icon never issues a sort request. */
|
/** Opt-in filter actions; clicking the icon never issues a sort request. */
|
||||||
public void setFilterActions(
|
public void setFilterActions(
|
||||||
Set<String> columns, java.util.function.BiConsumer<String, Node> handler) {
|
Set<String> columns, java.util.function.BiConsumer<String, Node> handler) {
|
||||||
@@ -196,8 +232,12 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String columnHeader(String id) {
|
||||||
|
return definitions.get(id).header();
|
||||||
|
}
|
||||||
|
|
||||||
private String headerText(String id) {
|
private String headerText(String id) {
|
||||||
return definitions.get(id).header()
|
return columnHeader(id)
|
||||||
+ sortKeys.stream()
|
+ sortKeys.stream()
|
||||||
.filter(k -> k.columnId().equals(id))
|
.filter(k -> k.columnId().equals(id))
|
||||||
.map(k -> k.direction() == SortKey.Direction.ASCENDING ? " ↑" : " ↓")
|
.map(k -> k.direction() == SortKey.Direction.ASCENDING ? " ↑" : " ↓")
|
||||||
@@ -337,7 +377,8 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
Math.clamp(e.value(), c.minimumWidth(), c.maximumWidth()))
|
Math.clamp(e.value(), c.minimumWidth(), c.maximumWidth()))
|
||||||
: width);
|
: width);
|
||||||
}
|
}
|
||||||
var nextHeader = headerNodes(nextOrder, preparedWidths);
|
var visibleOrder = visibleOrder(nextOrder);
|
||||||
|
var nextHeader = headerNodes(visibleOrder, preparedWidths);
|
||||||
result = List.copyOf(result);
|
result = List.copyOf(result);
|
||||||
Set<K> keys = new HashSet<>();
|
Set<K> keys = new HashSet<>();
|
||||||
for (var row : result)
|
for (var row : result)
|
||||||
@@ -365,7 +406,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
next.add(new Entry<>(row, view, click, key));
|
next.add(new Entry<>(row, view, click, key));
|
||||||
validateRow(view);
|
validateRow(view);
|
||||||
view.root().getStyleClass().add("result-row");
|
view.root().getStyleClass().add("result-row");
|
||||||
layoutRow(view, nextOrder, preparedWidths);
|
layoutRow(view, visibleOrder, preparedWidths);
|
||||||
view.root().addEventHandler(MouseEvent.MOUSE_CLICKED, click);
|
view.root().addEventHandler(MouseEvent.MOUSE_CLICKED, click);
|
||||||
view.root().setFocusTraversable(true);
|
view.root().setFocusTraversable(true);
|
||||||
view.root().addEventHandler(KeyEvent.KEY_PRESSED, key);
|
view.root().addEventHandler(KeyEvent.KEY_PRESSED, key);
|
||||||
@@ -379,7 +420,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
order = nextOrder;
|
order = nextOrder;
|
||||||
widths.clear();
|
widths.clear();
|
||||||
widths.putAll(preparedWidths);
|
widths.putAll(preparedWidths);
|
||||||
header.getChildren().setAll(nextHeader);
|
replaceHeader(nextHeader);
|
||||||
captured = nextCaptured;
|
captured = nextCaptured;
|
||||||
groupTree = nextTree;
|
groupTree = nextTree;
|
||||||
grouping = nextGrouping.columns();
|
grouping = nextGrouping.columns();
|
||||||
@@ -396,8 +437,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
validateOrder(ids);
|
validateOrder(ids);
|
||||||
order = ids;
|
order = ids;
|
||||||
drawHeader();
|
drawHeader();
|
||||||
entries.forEach(e -> layoutRow(e.view()));
|
applyWidths(widths);
|
||||||
resizeGroupHeadings();
|
|
||||||
layoutCommitted.run();
|
layoutCommitted.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +495,15 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void drawHeader() {
|
private void drawHeader() {
|
||||||
header.getChildren().setAll(headerNodes(order, widths));
|
replaceHeader(headerNodes(visibleOrder(order), widths));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void replaceHeader(List<Node> cells) {
|
||||||
|
if (headerMenu != null) {
|
||||||
|
headerMenu.hide();
|
||||||
|
headerMenu = null;
|
||||||
|
}
|
||||||
|
header.getChildren().setAll(cells);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Node> headerNodes(List<String> ordering, Map<String, ColumnWidth> sizes) {
|
private List<Node> headerNodes(List<String> ordering, Map<String, ColumnWidth> sizes) {
|
||||||
@@ -501,6 +549,14 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
if (columnSeparators && !id.equals(ordering.getLast()))
|
if (columnSeparators && !id.equals(ordering.getLast()))
|
||||||
cell.getChildren().add(ResultColumnSeparators.forHeader(cell));
|
cell.getChildren().add(ResultColumnSeparators.forHeader(cell));
|
||||||
gestures.header(cell, label, handle, id, () -> sortRequest.accept(id));
|
gestures.header(cell, label, handle, id, () -> sortRequest.accept(id));
|
||||||
|
cell.setOnContextMenuRequested(event -> {
|
||||||
|
if (headerMenuFactory == null) return;
|
||||||
|
if (headerMenu != null) headerMenu.hide();
|
||||||
|
headerMenu = headerMenuFactory.apply(id, cell);
|
||||||
|
if (event.isKeyboardTrigger()) headerMenu.show(cell, Side.BOTTOM, 0, 0);
|
||||||
|
else headerMenu.show(cell, event.getScreenX(), event.getScreenY());
|
||||||
|
event.consume();
|
||||||
|
});
|
||||||
size(cell, width(id, sizes));
|
size(cell, width(id, sizes));
|
||||||
nodes.add(cell);
|
nodes.add(cell);
|
||||||
}
|
}
|
||||||
@@ -513,10 +569,6 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
region.setMaxWidth(width);
|
region.setMaxWidth(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void layoutRow(ResultRow view) {
|
|
||||||
layoutRow(view, order, widths);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void layoutRow(ResultRow view, List<String> ordering, Map<String, ColumnWidth> sizes) {
|
private void layoutRow(ResultRow view, List<String> ordering, Map<String, ColumnWidth> sizes) {
|
||||||
Set<Region> fields = Collections.newSetFromMap(new IdentityHashMap<>());
|
Set<Region> fields = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||||
fields.addAll(view.fields().values());
|
fields.addAll(view.fields().values());
|
||||||
@@ -532,7 +584,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
else if (!fields.contains(child)) children.add(child);
|
else if (!fields.contains(child)) children.add(child);
|
||||||
}
|
}
|
||||||
if (columnSeparators) {
|
if (columnSeparators) {
|
||||||
if (separators == null)
|
if (separators == null || !separators.matchesColumnCount(ordering.size()))
|
||||||
separators = new ResultColumnSeparators(view.root(), ordering.size());
|
separators = new ResultColumnSeparators(view.root(), ordering.size());
|
||||||
separators.position(ordering.stream().mapToDouble(id -> width(id, sizes)).toArray());
|
separators.position(ordering.stream().mapToDouble(id -> width(id, sizes)).toArray());
|
||||||
children.add(separators);
|
children.add(separators);
|
||||||
@@ -543,7 +595,10 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
view.root().getScene() == null ? null : view.root().getScene().getFocusOwner();
|
view.root().getScene() == null ? null : view.root().getScene().getFocusOwner();
|
||||||
boolean restore = focus != null && descendant(view.root(), focus);
|
boolean restore = focus != null && descendant(view.root(), focus);
|
||||||
view.root().getChildren().setAll(children);
|
view.root().getChildren().setAll(children);
|
||||||
if (restore) focus.requestFocus();
|
if (restore) {
|
||||||
|
if (descendant(view.root(), focus)) focus.requestFocus();
|
||||||
|
else view.root().requestFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,6 +817,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
.getChildren()
|
.getChildren()
|
||||||
.getFirst()
|
.getFirst()
|
||||||
.requestFocus();
|
.requestFocus();
|
||||||
|
else if (headerAccessory != null) headerAccessory.requestFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resizeGroupHeadings();
|
resizeGroupHeadings();
|
||||||
@@ -862,8 +918,13 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void resizeGroupHeadings() {
|
private void resizeGroupHeadings() {
|
||||||
double total = order.stream().mapToDouble(this::width).sum();
|
resizeGroupHeadings(visibleOrder(order), widths);
|
||||||
disclosure.values().forEach(button -> size(button, total));
|
}
|
||||||
|
|
||||||
|
private void resizeGroupHeadings(List<String> visible, Map<String, ColumnWidth> sizes) {
|
||||||
|
double total = visible.stream().mapToDouble(id -> width(id, sizes)).sum();
|
||||||
|
disclosure.values().forEach(
|
||||||
|
button -> size(button, visible.isEmpty() ? Region.USE_COMPUTED_SIZE : total));
|
||||||
}
|
}
|
||||||
|
|
||||||
void previewWidth(String id, ColumnWidth value) {
|
void previewWidth(String id, ColumnWidth value) {
|
||||||
@@ -875,9 +936,9 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
private void applyWidths(Map<String, ColumnWidth> sizes) {
|
private void applyWidths(Map<String, ColumnWidth> sizes) {
|
||||||
for (Node node : header.getChildren())
|
for (Node node : header.getChildren())
|
||||||
size((Region) node, width((String) node.getUserData(), sizes));
|
size((Region) node, width((String) node.getUserData(), sizes));
|
||||||
entries.forEach(e -> layoutRow(e.view(), order, sizes));
|
var visible = visibleOrder(order);
|
||||||
double total = order.stream().mapToDouble(id -> width(id, sizes)).sum();
|
entries.forEach(e -> layoutRow(e.view(), visible, sizes));
|
||||||
disclosure.values().forEach(button -> size(button, total));
|
resizeGroupHeadings(visible, sizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void release(List<Entry<K, T>> retired) {
|
private void release(List<Entry<K, T>> retired) {
|
||||||
@@ -913,7 +974,7 @@ public final class TableResults<K, T> implements AutoCloseable {
|
|||||||
var old = entries;
|
var old = entries;
|
||||||
entries = List.of();
|
entries = List.of();
|
||||||
body.getChildren().clear();
|
body.getChildren().clear();
|
||||||
header.getChildren().clear();
|
replaceHeader(List.of());
|
||||||
body.setOnMouseClicked(null);
|
body.setOnMouseClicked(null);
|
||||||
selectedKey.set(null);
|
selectedKey.set(null);
|
||||||
selectedElement.set(null);
|
selectedElement.set(null);
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.SequencedSet;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.collections.ListChangeListener;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
|
||||||
|
/** Tracks the resources installed by one View or one of its dynamic children. */
|
||||||
|
final class ViewLifetime implements AutoCloseable {
|
||||||
|
|
||||||
|
private final ViewModelContext models;
|
||||||
|
private final SequencedSet<Runnable> cleanup = new LinkedHashSet<>();
|
||||||
|
private boolean closed;
|
||||||
|
|
||||||
|
ViewLifetime(ViewModelContext models) {
|
||||||
|
this.models = models;
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewModelContext models() {
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean managed() {
|
||||||
|
return models != ViewModels.LEGACY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void own(Runnable removal) {
|
||||||
|
if (managed()) {
|
||||||
|
if (closed) {
|
||||||
|
removal.run();
|
||||||
|
} else {
|
||||||
|
cleanup.addLast(removal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ownController(Object controller) {
|
||||||
|
if (controller instanceof AutoCloseable closeable) {
|
||||||
|
own(() -> {
|
||||||
|
try {
|
||||||
|
closeable.close();
|
||||||
|
} catch (RuntimeException failure) {
|
||||||
|
throw failure;
|
||||||
|
} catch (Exception failure) {
|
||||||
|
throw new IllegalStateException("Could not close " + controller.getClass().getName(), failure);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<T> void listen(ObservableValue<T> observable, ChangeListener<? super T> listener) {
|
||||||
|
observable.addListener(listener);
|
||||||
|
own(() -> observable.removeListener(listener));
|
||||||
|
}
|
||||||
|
|
||||||
|
<T> void listen(ObservableList<T> observable, ListChangeListener<? super T> listener) {
|
||||||
|
observable.addListener(listener);
|
||||||
|
own(() -> observable.removeListener(listener));
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewLifetime child() {
|
||||||
|
ViewLifetime child = new ViewLifetime(models);
|
||||||
|
Runnable closeChild = child::close;
|
||||||
|
own(closeChild);
|
||||||
|
child.own(() -> cleanup.remove(closeChild));
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
if (closed) return;
|
||||||
|
closed = true;
|
||||||
|
Throwable failure = null;
|
||||||
|
while (!cleanup.isEmpty()) {
|
||||||
|
try {
|
||||||
|
cleanup.removeLast().run();
|
||||||
|
} catch (RuntimeException | Error next) {
|
||||||
|
if (failure == null) {
|
||||||
|
failure = next;
|
||||||
|
} else if (failure != next) {
|
||||||
|
failure.addSuppressed(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (failure instanceof RuntimeException runtime) throw runtime;
|
||||||
|
if (failure instanceof Error error) throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Cleans up an incomplete load while preserving its original failure. */
|
||||||
|
void rollback(Throwable failure) {
|
||||||
|
try {
|
||||||
|
close();
|
||||||
|
} catch (RuntimeException | Error cleanupFailure) {
|
||||||
|
if (failure != cleanupFailure) failure.addSuppressed(cleanupFailure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -77,14 +77,33 @@ public final class ViewLoader {
|
|||||||
* @throws IllegalArgumentException when a Direct binding names a path that is not a read-write Attribute
|
* @throws IllegalArgumentException when a Direct binding names a path that is not a read-write Attribute
|
||||||
*/
|
*/
|
||||||
public static LoadedView load(URL fxml, Object model, ApplicationContext context) {
|
public static LoadedView load(URL fxml, Object model, ApplicationContext context) {
|
||||||
|
return load(fxml, model, context, new ViewLifetime(ViewModels.LEGACY));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a View with a fresh Controller and Components in an explicitly owned Model context.
|
||||||
|
* Close the result when its UI is removed, or close the Model context to close all its Views.
|
||||||
|
*
|
||||||
|
* @param fxml the FXML document
|
||||||
|
* @param model the Model instance
|
||||||
|
* @param context the container for Controllers and services
|
||||||
|
* @param models the Model context shared by this View and related Views
|
||||||
|
* @return the loaded View
|
||||||
|
*/
|
||||||
|
public static LoadedView load(URL fxml, Object model, ApplicationContext context, ViewModelContext models) {
|
||||||
|
return load(fxml, model, context, models.openView());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LoadedView load(URL fxml, Object model, ApplicationContext context, ViewLifetime lifetime) {
|
||||||
|
LoadSession session = LoadSession.nest();
|
||||||
|
try {
|
||||||
Class<?> controllerType = FxmlControllers.controllerClass(fxml);
|
Class<?> controllerType = FxmlControllers.controllerClass(fxml);
|
||||||
Class<?> viewModelClass = ViewModels.namedOn(controllerType);
|
Class<?> viewModelClass = ViewModels.namedOn(controllerType);
|
||||||
Object viewModel = ViewModels.of(model, viewModelClass);
|
Object viewModel = ViewModels.of(lifetime.models(), model, viewModelClass);
|
||||||
LoadSession session = LoadSession.open();
|
|
||||||
try {
|
|
||||||
FXMLLoader loader = new FXMLLoader(fxml, resources(context, fxml, controllerType));
|
FXMLLoader loader = new FXMLLoader(fxml, resources(context, fxml, controllerType));
|
||||||
loader.setControllerFactory(type -> controller(context, type));
|
FxmlHandlers.observe(loader, lifetime);
|
||||||
loader.setBuilderFactory(type -> Components.builder(type, context));
|
loader.setControllerFactory(type -> createController(context, type, lifetime));
|
||||||
|
loader.setBuilderFactory(type -> Components.builder(type, context, lifetime));
|
||||||
Object loaded = loader.load();
|
Object loaded = loader.load();
|
||||||
if (!(loaded instanceof Parent root)) {
|
if (!(loaded instanceof Parent root)) {
|
||||||
throw new IllegalArgumentException("View root must be a parent");
|
throw new IllegalArgumentException("View root must be a parent");
|
||||||
@@ -96,18 +115,31 @@ public final class ViewLoader {
|
|||||||
if (controller instanceof HasViewModel hasViewModel && viewModel instanceof ViewModel bound) {
|
if (controller instanceof HasViewModel hasViewModel && viewModel instanceof ViewModel bound) {
|
||||||
hasViewModel.setViewModel(bound);
|
hasViewModel.setViewModel(bound);
|
||||||
}
|
}
|
||||||
|
CommandBindingApplier.validate(session.bindingLists(), loader.getNamespace());
|
||||||
for (BindingList bindingList : session.bindingLists()) {
|
for (BindingList bindingList : session.bindingLists()) {
|
||||||
bindingList.apply(loader.getNamespace(), viewModel, controller, root, context);
|
bindingList.apply(loader.getNamespace(), viewModel, controller, root, context, lifetime);
|
||||||
}
|
}
|
||||||
Table.openAll(root, viewModel, context);
|
Table.openAll(root, viewModel, context, lifetime);
|
||||||
return new LoadedView(root, viewModel);
|
session.checkFailure();
|
||||||
|
return new LoadedView(root, viewModel, lifetime);
|
||||||
} catch (IOException failure) {
|
} catch (IOException failure) {
|
||||||
|
lifetime.rollback(failure);
|
||||||
throw new IllegalStateException("Could not load view " + fxml, failure);
|
throw new IllegalStateException("Could not load view " + fxml, failure);
|
||||||
|
} catch (RuntimeException | Error failure) {
|
||||||
|
lifetime.rollback(failure);
|
||||||
|
throw failure;
|
||||||
} finally {
|
} finally {
|
||||||
LoadSession.close();
|
LoadSession.unnest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Object createController(ApplicationContext context, Class<?> type, ViewLifetime lifetime) {
|
||||||
|
if (!lifetime.managed()) return context.getComponent(type);
|
||||||
|
Object controller = context.createComponent(type);
|
||||||
|
lifetime.ownController(controller);
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
static Messages resources(ApplicationContext context, URL fxml, Class<?> type) {
|
static Messages resources(ApplicationContext context, URL fxml, Class<?> type) {
|
||||||
Localizer languages;
|
Localizer languages;
|
||||||
try {
|
try {
|
||||||
@@ -118,14 +150,4 @@ public final class ViewLoader {
|
|||||||
return languages.forView(fxml, type);
|
return languages.forView(fxml, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Asks the container for the Controller class named by the document.
|
|
||||||
*
|
|
||||||
* @param context the container
|
|
||||||
* @param type the Controller class
|
|
||||||
* @return the Controller
|
|
||||||
*/
|
|
||||||
private static Object controller(ApplicationContext context, Class<?> type) {
|
|
||||||
return context.getComponent(type.asSubclass(Object.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public class ViewModel {
|
|||||||
* The Model instance this ViewModel was built for.
|
* The Model instance this ViewModel was built for.
|
||||||
*/
|
*/
|
||||||
private final Object model;
|
private final Object model;
|
||||||
|
private final ViewModelContext models;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JavaFX properties keyed by Attribute name.
|
* JavaFX properties keyed by Attribute name.
|
||||||
@@ -136,7 +137,8 @@ public class ViewModel {
|
|||||||
*/
|
*/
|
||||||
protected ViewModel(Object model) {
|
protected ViewModel(Object model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
ViewModels.register(model, this);
|
models = ViewModels.constructingContext();
|
||||||
|
models.viewModels().put(model, this);
|
||||||
for (PropertyDescriptor descriptor : descriptors(model.getClass())) {
|
for (PropertyDescriptor descriptor : descriptors(model.getClass())) {
|
||||||
Method getter = descriptor.getReadMethod();
|
Method getter = descriptor.getReadMethod();
|
||||||
Method setter = descriptor.getWriteMethod();
|
Method setter = descriptor.getWriteMethod();
|
||||||
@@ -218,9 +220,9 @@ public class ViewModel {
|
|||||||
* @param listener the listener
|
* @param listener the listener
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void addAttributeListener(ChangeListener<Object> listener) {
|
void addAttributeListener(ViewLifetime lifetime, ChangeListener<Object> listener) {
|
||||||
for (Property<?> property : properties.values()) {
|
for (Property<?> property : properties.values()) {
|
||||||
((Property<Object>) property).addListener(listener);
|
lifetime.listen((Property<Object>) property, listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,7 +431,7 @@ public class ViewModel {
|
|||||||
* Attaching the change listener reads the value. That read is ignored until
|
* Attaching the change listener reads the value. That read is ignored until
|
||||||
* {@link #attached()} so a Component annotation can name the class first.
|
* {@link #attached()} so a Component annotation can name the class first.
|
||||||
*/
|
*/
|
||||||
private static final class LazyComplex extends SimpleObjectProperty<Object> {
|
private final class LazyComplex extends SimpleObjectProperty<Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Model instance, kept until the nested ViewModel is built.
|
* The Model instance, kept until the nested ViewModel is built.
|
||||||
@@ -464,7 +466,7 @@ public class ViewModel {
|
|||||||
public Object get() {
|
public Object get() {
|
||||||
if (!attaching && !realized) {
|
if (!attaching && !realized) {
|
||||||
realized = true;
|
realized = true;
|
||||||
super.set(current == null ? null : ViewModels.of(current));
|
super.set(current == null ? null : ViewModels.of(models, current, null));
|
||||||
}
|
}
|
||||||
return super.get();
|
return super.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Owns the ViewModel identity and loaded Views for a window, document or archive session.
|
||||||
|
* Use this context on the JavaFX application thread. Closing it closes its remaining Views and
|
||||||
|
* releases its Model registrations. Close an individual {@link LoadedView} earlier to detach it
|
||||||
|
* while its Model remains available to other Views in this context.
|
||||||
|
*/
|
||||||
|
public final class ViewModelContext implements AutoCloseable {
|
||||||
|
|
||||||
|
private final Map<Object, Object> viewModels = new IdentityHashMap<>();
|
||||||
|
private final ViewLifetime views = new ViewLifetime(this);
|
||||||
|
private boolean closed;
|
||||||
|
|
||||||
|
ViewLifetime openView() {
|
||||||
|
checkOpen();
|
||||||
|
return views.child();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Object, Object> viewModels() {
|
||||||
|
checkOpen();
|
||||||
|
return viewModels;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkOpen() {
|
||||||
|
if (closed) throw new IllegalStateException("ViewModelContext is closed");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
if (closed) return;
|
||||||
|
closed = true;
|
||||||
|
try {
|
||||||
|
views.close();
|
||||||
|
} finally {
|
||||||
|
viewModels.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ package de.neitzel.fx.view;
|
|||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.IdentityHashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +14,10 @@ final class ViewModels {
|
|||||||
/**
|
/**
|
||||||
* ViewModels already built, keyed by Model identity.
|
* ViewModels already built, keyed by Model identity.
|
||||||
*/
|
*/
|
||||||
private static final Map<Object, Object> BY_INSTANCE = new IdentityHashMap<>();
|
static final ViewModelContext LEGACY = new ViewModelContext();
|
||||||
|
|
||||||
|
// Preserve the single-argument constructor used by custom and generated ViewModels.
|
||||||
|
private static final ThreadLocal<ViewModelContext> CONSTRUCTING = new ThreadLocal<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevents instantiation.
|
* Prevents instantiation.
|
||||||
@@ -23,32 +25,26 @@ final class ViewModels {
|
|||||||
private ViewModels() {
|
private ViewModels() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ViewModel for a Model instance, building the generic one when none exists yet.
|
|
||||||
*
|
|
||||||
* @param model the Model instance
|
|
||||||
* @return the ViewModel for that instance, or a replacement that exposes JavaFX properties by name
|
|
||||||
*/
|
|
||||||
static Object of(Object model) {
|
static Object of(Object model) {
|
||||||
return of(model, null);
|
return of(model, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ViewModel for a Model instance.
|
|
||||||
* <p>
|
|
||||||
* Selects a registered default or compatible explicit class before construction. Without
|
|
||||||
* a registered default, a null class or {@link ViewModel} itself uses the generic ViewModel.
|
|
||||||
* An unregistered replacement may expose JavaFX properties by name. The container does not
|
|
||||||
* create it. The first View fixes the instance; later compatible superclass/interface requests
|
|
||||||
* reuse it, while incompatible requests fail. A View naming no class reuses the instance.
|
|
||||||
*
|
|
||||||
* @param model the Model instance
|
|
||||||
* @param viewModelClass the class named by {@link ViewModelClass}, or {@code null}
|
|
||||||
* @return the ViewModel for that instance, or the replacement
|
|
||||||
*/
|
|
||||||
static Object of(Object model, Class<?> viewModelClass) {
|
static Object of(Object model, Class<?> viewModelClass) {
|
||||||
|
return of(LEGACY, model, viewModelClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ViewModelContext constructingContext() {
|
||||||
|
ViewModelContext context = CONSTRUCTING.get();
|
||||||
|
return context == null ? LEGACY : context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or builds the ViewModel for this Model identity in the caller's context.
|
||||||
|
*/
|
||||||
|
static Object of(ViewModelContext context, Object model, Class<?> viewModelClass) {
|
||||||
|
Map<Object, Object> instances = context.viewModels();
|
||||||
Class<?> selected = ViewModelDefaults.select(model.getClass(), viewModelClass, model.getClass().getClassLoader());
|
Class<?> selected = ViewModelDefaults.select(model.getClass(), viewModelClass, model.getClass().getClassLoader());
|
||||||
Object existing = BY_INSTANCE.get(model);
|
Object existing = instances.get(model);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
if (viewModelClass != null && viewModelClass != ViewModel.class
|
if (viewModelClass != null && viewModelClass != ViewModel.class
|
||||||
&& !selected.isInstance(existing)) {
|
&& !selected.isInstance(existing)) {
|
||||||
@@ -58,8 +54,22 @@ final class ViewModels {
|
|||||||
}
|
}
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
if (selected == ViewModel.class) return new ViewModel(model);
|
ViewModelContext previous = CONSTRUCTING.get();
|
||||||
return construct(model, selected);
|
CONSTRUCTING.set(context);
|
||||||
|
try {
|
||||||
|
Object created = selected == ViewModel.class ? new ViewModel(model) : construct(model, selected);
|
||||||
|
instances.put(model, created);
|
||||||
|
return created;
|
||||||
|
} catch (RuntimeException | Error failure) {
|
||||||
|
instances.remove(model);
|
||||||
|
throw failure;
|
||||||
|
} finally {
|
||||||
|
if (previous == null) {
|
||||||
|
CONSTRUCTING.remove();
|
||||||
|
} else {
|
||||||
|
CONSTRUCTING.set(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,8 +93,7 @@ final class ViewModels {
|
|||||||
/**
|
/**
|
||||||
* Constructs a ViewModel or a replacement with the Model instance.
|
* Constructs a ViewModel or a replacement with the Model instance.
|
||||||
* <p>
|
* <p>
|
||||||
* A result that is not a {@link ViewModel} is registered here. A {@link ViewModel} registers
|
* A {@link ViewModel} registers itself from its constructor, before its Attributes are walked.
|
||||||
* itself from its constructor, before its Attributes are walked.
|
|
||||||
*
|
*
|
||||||
* @param model the Model instance
|
* @param model the Model instance
|
||||||
* @param viewModelClass the class to construct
|
* @param viewModelClass the class to construct
|
||||||
@@ -94,13 +103,8 @@ final class ViewModels {
|
|||||||
Constructor<?> constructor = constructor(model, viewModelClass);
|
Constructor<?> constructor = constructor(model, viewModelClass);
|
||||||
constructor.setAccessible(true);
|
constructor.setAccessible(true);
|
||||||
try {
|
try {
|
||||||
Object created = constructor.newInstance(model);
|
return constructor.newInstance(model);
|
||||||
if (!(created instanceof ViewModel)) {
|
|
||||||
register(model, created);
|
|
||||||
}
|
|
||||||
return created;
|
|
||||||
} catch (InvocationTargetException failure) {
|
} catch (InvocationTargetException failure) {
|
||||||
BY_INSTANCE.remove(model);
|
|
||||||
if (failure.getCause() instanceof RuntimeException runtime) {
|
if (failure.getCause() instanceof RuntimeException runtime) {
|
||||||
throw runtime;
|
throw runtime;
|
||||||
}
|
}
|
||||||
@@ -138,13 +142,4 @@ final class ViewModels {
|
|||||||
return chosen;
|
return chosen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Records a ViewModel before its Attributes are walked, so a cycle reuses it.
|
|
||||||
*
|
|
||||||
* @param model the Model instance
|
|
||||||
* @param viewModel the ViewModel under construction
|
|
||||||
*/
|
|
||||||
static void register(Object model, Object viewModel) {
|
|
||||||
BY_INSTANCE.put(model, viewModel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
.grouping-chip { -fx-padding: 4 8; -fx-alignment: center-left; -fx-background-color: #e8eff7; -fx-border-color: #8a9eb5; -fx-cursor: open-hand; }
|
.grouping-chip { -fx-padding: 4 8; -fx-alignment: center-left; -fx-background-color: #e8eff7; -fx-border-color: #8a9eb5; -fx-cursor: open-hand; }
|
||||||
.data-grid .column-cell { -fx-alignment: center-left; -fx-min-height: 32; }
|
.data-grid .column-cell { -fx-alignment: center-left; -fx-min-height: 32; }
|
||||||
.data-grid .column-header { -fx-padding: 5 6; }
|
.data-grid .column-header { -fx-padding: 5 6; }
|
||||||
|
.data-grid .data-grid-column-menu, .data-grid .data-grid-column-menu > .label { -fx-padding: 0; }
|
||||||
|
.data-grid .data-grid-column-menu > .arrow-button { -fx-padding: 0 8; }
|
||||||
|
.neitzel-theme .data-grid .data-grid-column-menu:focused { -fx-border-color: -nl-focus; }
|
||||||
.data-grid .column-resize:hover { -fx-background-color: #3776b6; }
|
.data-grid .column-resize:hover { -fx-background-color: #3776b6; }
|
||||||
.group-heading { -fx-background-color: #e8eff7; -fx-text-fill: #182b3b; -fx-border-color: transparent transparent #b4c4d5 transparent; -fx-background-radius: 0; -fx-alignment: center-left; }
|
.group-heading { -fx-background-color: #e8eff7; -fx-text-fill: #182b3b; -fx-border-color: transparent transparent #b4c4d5 transparent; -fx-background-radius: 0; -fx-alignment: center-left; }
|
||||||
.group-heading:focused { -fx-border-color: #3776b6; -fx-border-width: 2; }
|
.group-heading:focused { -fx-border-color: #3776b6; -fx-border-width: 2; }
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import de.neitzel.fx.view.command.CommandController;
|
||||||
|
import de.neitzel.injection.ApplicationContext;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.MenuBar;
|
||||||
|
import javafx.scene.control.MenuItem;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class BindCommandTest {
|
||||||
|
|
||||||
|
@TempDir
|
||||||
|
Path directory;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void start() throws InterruptedException {
|
||||||
|
FxThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void connectsOneCommandToButtonMenuAndKeyboardUntilClosed() throws Exception {
|
||||||
|
var url = view("commands.fxml", """
|
||||||
|
<CommandBinding control="button" path="clear"/>
|
||||||
|
<CommandBinding control="item" path="clear"/>
|
||||||
|
""");
|
||||||
|
FxThread.onFx(() -> {
|
||||||
|
try (var models = new ViewModelContext()) {
|
||||||
|
var view = ViewLoader.load(url, new CommandController.Subject(), services(), models);
|
||||||
|
var model = (CommandController.Model) view.getViewModel();
|
||||||
|
var button = (Button) view.getRoot().lookup("#button");
|
||||||
|
var menu = ((MenuBar) view.getRoot().lookup("#menu")).getMenus().getFirst();
|
||||||
|
var item = menu.getItems().getFirst();
|
||||||
|
var dynamic = new MenuItem();
|
||||||
|
try (var registration = CommandBindings.bind(dynamic, model.getClear())) {
|
||||||
|
assertTrue(button.isDisable());
|
||||||
|
assertTrue(item.isDisable());
|
||||||
|
item.fire();
|
||||||
|
model.getClear().execute();
|
||||||
|
assertEquals(0, model.getCalls());
|
||||||
|
|
||||||
|
model.getEnabled().set(true);
|
||||||
|
assertFalse(button.isDisable());
|
||||||
|
assertFalse(item.isDisable());
|
||||||
|
button.fire();
|
||||||
|
item.fire();
|
||||||
|
model.getClear().execute();
|
||||||
|
dynamic.fire();
|
||||||
|
assertEquals(4, model.getCalls());
|
||||||
|
}
|
||||||
|
dynamic.fire();
|
||||||
|
assertEquals(4, model.getCalls());
|
||||||
|
|
||||||
|
view.close();
|
||||||
|
assertNull(button.getOnAction());
|
||||||
|
assertNull(item.getOnAction());
|
||||||
|
model.getEnabled().set(false);
|
||||||
|
assertFalse(button.isDisable());
|
||||||
|
assertFalse(item.isDisable());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void rejectsUnknownTargetsAndConflictingOwners() throws Exception {
|
||||||
|
var scenarios = new String[][] {
|
||||||
|
{"<CommandBinding control='unknown' path='clear'/>", "unknown"},
|
||||||
|
{"<CommandBinding control='button' path='unknown'/>", "unknown"},
|
||||||
|
{"<CommandBinding control='menu' path='clear'/>", "ButtonBase or MenuItem"},
|
||||||
|
{"<CommandBinding control='button' path='clear'/><CommandBinding control='button' path='clear'/>", "duplicate"},
|
||||||
|
{"<CommandBinding control='button' path='clear'/><ComputedBinding control='button' property='disable' method='#unused'/>", "disable"}
|
||||||
|
};
|
||||||
|
for (var scenario : scenarios) {
|
||||||
|
var url = view("invalid-command.fxml", scenario[0]);
|
||||||
|
FxThread.onFx(() -> {
|
||||||
|
try (var models = new ViewModelContext()) {
|
||||||
|
var failure = assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> ViewLoader.load(url, new CommandController.Subject(), services(), models));
|
||||||
|
assertTrue(failure.getMessage().contains("invalid-command.fxml"));
|
||||||
|
assertTrue(failure.getMessage().contains(scenario[1]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApplicationContext services() {
|
||||||
|
return new ApplicationContext("de.neitzel.fx.view.command");
|
||||||
|
}
|
||||||
|
|
||||||
|
private java.net.URL view(String name, String bindings) throws Exception {
|
||||||
|
return Files.writeString(directory.resolve(name), """
|
||||||
|
<?import de.neitzel.fx.view.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
<VBox xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.neitzel.fx.view.command.CommandController">
|
||||||
|
<fx:define><BindingList>%s</BindingList></fx:define>
|
||||||
|
<Button fx:id="button"/>
|
||||||
|
<MenuBar fx:id="menu"><menus><Menu><items><MenuItem fx:id="item"/></items></Menu></menus></MenuBar>
|
||||||
|
</VBox>
|
||||||
|
""".formatted(bindings)).toUri().toURL();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import de.neitzel.fx.view.fixture.Person;
|
||||||
|
import de.neitzel.fx.view.readable.ReadableSourcesController.Sources;
|
||||||
|
import de.neitzel.injection.ApplicationContext;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/** DirectBinding reads declared observables toward the view. */
|
||||||
|
class BindReadOnlySourcesTest {
|
||||||
|
private static final URL DOCUMENT = BindReadOnlySourcesTest.class.getResource("readable-sources.fxml");
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void startJavaFx() throws InterruptedException {
|
||||||
|
FxThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void followsOnlyDependenciesOfTheViewModelSource() throws Exception {
|
||||||
|
FxThread.onFx(() -> {
|
||||||
|
LoadedView view = ViewLoader.load(DOCUMENT, new Person("Ada"), context());
|
||||||
|
Sources sources = (Sources) view.getViewModel();
|
||||||
|
Button commit = (Button) view.getRoot().lookup("#commit");
|
||||||
|
Label title = (Label) view.getRoot().lookup("#title");
|
||||||
|
Label caption = (Label) view.getRoot().lookup("#caption");
|
||||||
|
TextField unrelated = (TextField) view.getRoot().lookup("#unrelated");
|
||||||
|
|
||||||
|
assertTrue(commit.isDisable());
|
||||||
|
assertEquals("First", title.getText());
|
||||||
|
assertEquals("Caption: First", caption.getText());
|
||||||
|
assertNull(view.property("title"));
|
||||||
|
int evaluations = sources.getEvaluations();
|
||||||
|
unrelated.setText("A change outside the binding's dependencies");
|
||||||
|
assertEquals(evaluations, sources.getEvaluations());
|
||||||
|
|
||||||
|
sources.getChoices().add("A");
|
||||||
|
assertFalse(commit.isDisable());
|
||||||
|
sources.getChoices().clear();
|
||||||
|
assertTrue(commit.isDisable());
|
||||||
|
assertEquals(evaluations + 2, sources.getEvaluations());
|
||||||
|
|
||||||
|
title.setText("A local edit");
|
||||||
|
assertEquals("First", sources.titleProperty().get());
|
||||||
|
sources.setTitle("");
|
||||||
|
assertEquals("", title.getText());
|
||||||
|
assertEquals("Caption: First", caption.getText());
|
||||||
|
assertEquals("observableTitle", sources.getLatestMessage().getSource());
|
||||||
|
sources.setTitle("Second");
|
||||||
|
assertEquals("Second", title.getText());
|
||||||
|
assertEquals("Caption: Second", caption.getText());
|
||||||
|
assertNull(sources.getLatestMessage());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"both", "model"})
|
||||||
|
void identifiesAnInvalidWriteBackWithItsDocumentAndEndpoints(String direction, @TempDir Path temporary)
|
||||||
|
throws Exception {
|
||||||
|
Path invalid = temporary.resolve("invalid-" + direction + ".fxml");
|
||||||
|
String fxml = Files.readString(Path.of(DOCUMENT.toURI()));
|
||||||
|
Files.writeString(invalid, fxml.replace("path=\"observableTitle\" direction=\"view\"",
|
||||||
|
"path=\"observableTitle\" direction=\"" + direction + "\""));
|
||||||
|
FxThread.onFx(() -> {
|
||||||
|
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> ViewLoader.load(invalid.toUri().toURL(), new Person("Ada"), context()));
|
||||||
|
assertTrue(failure.getMessage().contains("Read-only source"), failure.getMessage());
|
||||||
|
assertTrue(failure.getMessage().contains("observableTitle"), failure.getMessage());
|
||||||
|
assertTrue(failure.getMessage().contains("caption.text"), failure.getMessage());
|
||||||
|
assertTrue(failure.getMessage().contains(invalid.getFileName().toString()), failure.getMessage());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ApplicationContext context() {
|
||||||
|
return new ApplicationContext("de.neitzel.fx.view.readable");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,13 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
import de.neitzel.grid.*;
|
import de.neitzel.grid.*;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.input.ContextMenuEvent;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.Window;
|
||||||
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
@@ -95,6 +99,137 @@ class DataGridGroupingTest {
|
|||||||
return new GroupPath(List.of(new GroupPath.Segment("type", new FilterValue.Text(type))));
|
return new GroupPath(List.of(new GroupPath.Segment("type", new FilterValue.Text(type))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void headerMenusChangeVisibilityWithoutReplacingRowsOrLosingLayout() throws Exception {
|
||||||
|
var reads = new AtomicInteger();
|
||||||
|
var disposed = new AtomicInteger();
|
||||||
|
Map<Long, TextField> fields = new HashMap<>();
|
||||||
|
var grid = fx(() -> grid(reads, disposed, fields));
|
||||||
|
var stage = fx(Stage::new);
|
||||||
|
try {
|
||||||
|
fx(grid::loadAsync).toCompletableFuture().get(5, TimeUnit.SECONDS);
|
||||||
|
fx(() -> {
|
||||||
|
stage.setScene(grid.getScene());
|
||||||
|
stage.show();
|
||||||
|
grid.setExpanded(path("A"), true);
|
||||||
|
grid.setColumnOrder(List.of("status", "type"));
|
||||||
|
grid.setColumnWidth("type", new ColumnWidth.Explicit(235));
|
||||||
|
var editor = fields.get(1L);
|
||||||
|
editor.setText("unfinished draft");
|
||||||
|
var row = (HBox) editor.getParent();
|
||||||
|
assertSame(editor, row.getChildren().get(1));
|
||||||
|
var menu = (MenuButton) grid.lookup(".data-grid-column-menu");
|
||||||
|
var header = (HBox) grid.lookup(".column-header-row");
|
||||||
|
long visibility = grid.columnVisibilityRevisionProperty().get();
|
||||||
|
var context = showColumnContextMenu(header.getChildren().get(1), false);
|
||||||
|
context.getItems().getLast().fire();
|
||||||
|
assertEquals(++visibility, grid.columnVisibilityRevisionProperty().get());
|
||||||
|
grid.setColumnVisible("type", false);
|
||||||
|
assertEquals(visibility, grid.columnVisibilityRevisionProperty().get());
|
||||||
|
assertFalse(context.isShowing());
|
||||||
|
assertFalse(grid.isColumnVisible("type"));
|
||||||
|
assertNull(editor.getParent());
|
||||||
|
assertEquals(1, header.getChildren().size());
|
||||||
|
assertEquals(List.of("type"), grid.groupingColumns());
|
||||||
|
|
||||||
|
menu.show();
|
||||||
|
assertTrue(menu.isShowing());
|
||||||
|
var status = (CheckMenuItem) menu.getItems().getFirst();
|
||||||
|
var type = (CheckMenuItem) menu.getItems().getLast();
|
||||||
|
assertEquals("Status", status.getText());
|
||||||
|
assertTrue(status.isSelected());
|
||||||
|
assertEquals("Type", type.getText());
|
||||||
|
assertFalse(type.isSelected());
|
||||||
|
status.setSelected(false);
|
||||||
|
status.fire();
|
||||||
|
menu.hide();
|
||||||
|
assertTrue(header.getChildren().isEmpty());
|
||||||
|
assertTrue(menu.isVisible());
|
||||||
|
menu.show();
|
||||||
|
type = (CheckMenuItem) menu.getItems().getLast();
|
||||||
|
type.setSelected(true);
|
||||||
|
type.fire();
|
||||||
|
menu.hide();
|
||||||
|
assertEquals(visibility + 2, grid.columnVisibilityRevisionProperty().get());
|
||||||
|
assertSame(editor, row.getChildren().getFirst());
|
||||||
|
assertEquals(235, editor.getPrefWidth());
|
||||||
|
assertEquals("unfinished draft", editor.getText());
|
||||||
|
assertEquals(0, disposed.get());
|
||||||
|
assertEquals(1, reads.get());
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
fx(() -> {
|
||||||
|
var header = (HBox) grid.lookup(".column-header-row");
|
||||||
|
var context = showColumnContextMenu(header.getChildren().getFirst(), true);
|
||||||
|
context.getItems().stream()
|
||||||
|
.filter(item -> "Sort descending".equals(item.getText()))
|
||||||
|
.findFirst().orElseThrow().fire();
|
||||||
|
context.hide();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
DataGridTest.drain();
|
||||||
|
fx(() -> {
|
||||||
|
assertEquals(List.of(new SortKey("type", SortKey.Direction.DESCENDING)),
|
||||||
|
grid.stateProperty().get().displayed().sort());
|
||||||
|
assertFalse(grid.isColumnVisible("status"));
|
||||||
|
assertTrue(grid.isColumnVisible("type"));
|
||||||
|
assertEquals(1, ((HBox) grid.lookup(".column-header-row")).getChildren().size());
|
||||||
|
assertEquals(2, reads.get());
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
fx(() -> {
|
||||||
|
grid.close();
|
||||||
|
stage.close();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ContextMenu showColumnContextMenu(Node cell, boolean fromKeyboard) {
|
||||||
|
var point = cell.localToScreen(0, 0);
|
||||||
|
cell.fireEvent(new ContextMenuEvent(ContextMenuEvent.CONTEXT_MENU_REQUESTED,
|
||||||
|
0, 0, point.getX(), point.getY(), fromKeyboard, null));
|
||||||
|
return Window.getWindows().stream()
|
||||||
|
.filter(ContextMenu.class::isInstance).map(ContextMenu.class::cast)
|
||||||
|
.filter(ContextMenu::isShowing).findFirst().orElseThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectorStaysFixedAndHeadersAlignAtTheRightScrollEdge() throws Exception {
|
||||||
|
var fields = new HashMap<Long, TextField>();
|
||||||
|
var grid = fx(() -> grid(new AtomicInteger(), new AtomicInteger(), fields));
|
||||||
|
try {
|
||||||
|
fx(grid::loadAsync).toCompletableFuture().get(5, TimeUnit.SECONDS);
|
||||||
|
fx(() -> {
|
||||||
|
grid.setExpanded(path("A"), true);
|
||||||
|
grid.setColumnWidth("type", new ColumnWidth.Explicit(400));
|
||||||
|
grid.setColumnWidth("status", new ColumnWidth.Explicit(400));
|
||||||
|
var root = grid.getScene().getRoot();
|
||||||
|
root.resize(640, 500);
|
||||||
|
root.layout();
|
||||||
|
var menu = grid.lookup(".data-grid-column-menu");
|
||||||
|
double menuX = menu.localToScene(0, 0).getX();
|
||||||
|
var scroll = (ScrollPane) grid.lookup(".table-scroll");
|
||||||
|
var header = (HBox) grid.lookup(".column-header-row");
|
||||||
|
scroll.setHvalue(1);
|
||||||
|
root.layout();
|
||||||
|
assertEquals(menuX, menu.localToScene(0, 0).getX(), .5);
|
||||||
|
var type = fields.get(1L);
|
||||||
|
assertEquals(type.localToScene(0, 0).getX(),
|
||||||
|
header.getChildren().getFirst().localToScene(0, 0).getX(), 1);
|
||||||
|
var last = header.getChildren().getLast();
|
||||||
|
assertEquals(menuX, last.localToScene(last.getBoundsInLocal()).getMaxX(), 1);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
fx(() -> {
|
||||||
|
grid.close();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void presentationChangesPreserveComponentsDraftsAndHiddenSelectionWithoutQueries()
|
void presentationChangesPreserveComponentsDraftsAndHiddenSelectionWithoutQueries()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|||||||
@@ -326,7 +326,10 @@ class DataGridNativeInteractionTest {
|
|||||||
ScrollPane scroll = fx(() -> (ScrollPane) grid.lookup(".table-scroll"));
|
ScrollPane scroll = fx(() -> (ScrollPane) grid.lookup(".table-scroll"));
|
||||||
var original = order();
|
var original = order();
|
||||||
begin(fx(() -> label("name")));
|
begin(fx(() -> label("name")));
|
||||||
Bounds viewport = fx(() -> scroll.localToScreen(scroll.getViewportBounds()));
|
Bounds viewport = fx(() -> {
|
||||||
|
var headerScroll = grid.lookup(".table-header-scroll");
|
||||||
|
return headerScroll.localToScreen(headerScroll.getBoundsInLocal());
|
||||||
|
});
|
||||||
move(new Point2D(viewport.getMaxX() - 10, point(fx(() -> header("type")), .5, .5).getY()));
|
move(new Point2D(viewport.getMaxX() - 10, point(fx(() -> header("type")), .5, .5).getY()));
|
||||||
waitFor(() -> scroll.getHvalue() > .1, "Native edge hover scrolls");
|
waitFor(() -> scroll.getHvalue() > .1, "Native edge hover scrolls");
|
||||||
capture("edge-scroll");
|
capture("edge-scroll");
|
||||||
|
|||||||
@@ -0,0 +1,154 @@
|
|||||||
|
package de.neitzel.fx.view;
|
||||||
|
|
||||||
|
import de.neitzel.fx.view.fixture.Address;
|
||||||
|
import de.neitzel.fx.view.fixture.Host;
|
||||||
|
import de.neitzel.fx.view.fixture.Person;
|
||||||
|
import de.neitzel.fx.view.fixture.Visit;
|
||||||
|
import de.neitzel.fx.view.managed.ViewController;
|
||||||
|
import de.neitzel.injection.ApplicationContext;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javafx.scene.control.ScrollPane;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
class ManagedViewTest {
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void start() throws InterruptedException {
|
||||||
|
FxThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sharesViewModelWithinContextAndClosesOnlyTheRequestedView() throws Exception {
|
||||||
|
FxThread.onFx(() -> {
|
||||||
|
var model = new Person("Ada");
|
||||||
|
var injection = new ApplicationContext("de.neitzel.fx.view.managed");
|
||||||
|
try (var models = new ViewModelContext(); var otherModels = new ViewModelContext()) {
|
||||||
|
var first = ViewLoader.load(fxml("managed-view.fxml"), model, injection, models);
|
||||||
|
var second = ViewLoader.load(fxml("managed-view.fxml"), model, injection, models);
|
||||||
|
var other = ViewLoader.load(fxml("managed-view.fxml"), model, injection, otherModels);
|
||||||
|
assertSame(first.getViewModel(), second.getViewModel());
|
||||||
|
assertNotSame(first.getViewModel(), other.getViewModel());
|
||||||
|
|
||||||
|
var firstInput = field(first.getRoot(), "#name");
|
||||||
|
var secondInput = field(second.getRoot(), "#name");
|
||||||
|
assertNotSame(firstInput, secondInput);
|
||||||
|
var firstController = (ViewController) firstInput.getUserData();
|
||||||
|
var secondController = (ViewController) secondInput.getUserData();
|
||||||
|
assertNotSame(firstController, secondController);
|
||||||
|
|
||||||
|
firstInput.setText("Grace");
|
||||||
|
assertEquals("Grace", secondInput.getText());
|
||||||
|
first.close();
|
||||||
|
first.close();
|
||||||
|
|
||||||
|
firstInput.setText("Detached");
|
||||||
|
assertEquals("Grace", model.getName());
|
||||||
|
secondInput.setText("Lin");
|
||||||
|
assertEquals("Lin", model.getName());
|
||||||
|
assertEquals("Detached", firstInput.getText());
|
||||||
|
assertEquals(1, firstController.getCloseCount());
|
||||||
|
assertEquals(0, secondController.getCloseCount());
|
||||||
|
models.close();
|
||||||
|
|
||||||
|
secondInput.setText("Also detached");
|
||||||
|
assertEquals("Lin", model.getName());
|
||||||
|
assertEquals(1, secondController.getCloseCount());
|
||||||
|
assertThrows(IllegalStateException.class,
|
||||||
|
() -> ViewLoader.load(fxml("managed-view.fxml"), model, injection, models));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void failedBindingClosesControllerAndRollsBackEarlierBinding() throws Exception {
|
||||||
|
FxThread.onFx(() -> {
|
||||||
|
var model = new Person("Ada");
|
||||||
|
var injection = new ApplicationContext("de.neitzel.fx.view.managed");
|
||||||
|
try (var models = new ViewModelContext()) {
|
||||||
|
var registry = injection.getComponent(ViewController.Registry.class);
|
||||||
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> ViewLoader.load(fxml("managed-invalid.fxml"), model, injection, models));
|
||||||
|
var abandoned = registry.getLastCreated();
|
||||||
|
assertEquals(1, abandoned.getCloseCount());
|
||||||
|
assertNull(abandoned.getInput().getOnAction());
|
||||||
|
abandoned.getInput().setText("Detached");
|
||||||
|
assertEquals("Ada", model.getName());
|
||||||
|
|
||||||
|
var loaded = ViewLoader.load(fxml("managed-view.fxml"), model, injection, models);
|
||||||
|
field(loaded.getRoot(), "#name").setText("Working");
|
||||||
|
assertEquals("Detached", abandoned.getInput().getText());
|
||||||
|
assertEquals("Working", model.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void removingARepeatChildDetachesItsBindings() throws Exception {
|
||||||
|
FxThread.onFx(() -> {
|
||||||
|
var person = new Person("Ada");
|
||||||
|
var first = new Address("Main");
|
||||||
|
var second = new Address("Water");
|
||||||
|
person.setAddresses(new ArrayList<>(List.of(first, second)));
|
||||||
|
try (var models = new ViewModelContext()) {
|
||||||
|
var context = new ApplicationContext("de.neitzel.fx.view.component");
|
||||||
|
var loaded = ViewLoader.load(fxml("repeat-addresses.fxml"), person, context, models);
|
||||||
|
var pane = (VBox) loaded.getRoot().lookup("#addressPane");
|
||||||
|
var detached = field(pane.getChildren().getFirst(), "#streetField");
|
||||||
|
var active = field(pane.getChildren().getLast(), "#streetField");
|
||||||
|
person.getAddresses().removeFirst();
|
||||||
|
detached.setText("Detached");
|
||||||
|
active.setText("Still active");
|
||||||
|
assertEquals("Main", first.getStreet());
|
||||||
|
assertEquals("Still active", second.getStreet());
|
||||||
|
|
||||||
|
loaded.close();
|
||||||
|
person.getAddresses().add(new Address("New"));
|
||||||
|
assertEquals(0, pane.getChildren().size());
|
||||||
|
active.setText("Also detached");
|
||||||
|
assertEquals("Still active", second.getStreet());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void removingATableRowDetachesItsBindings() throws Exception {
|
||||||
|
FxThread.onFx(() -> {
|
||||||
|
var host = new Host();
|
||||||
|
var visit = new Visit("Main", "Darmstadt");
|
||||||
|
host.setVisits(new ArrayList<>(List.of(visit)));
|
||||||
|
try (var models = new ViewModelContext()) {
|
||||||
|
var context = new ApplicationContext("de.neitzel.fx.view.component");
|
||||||
|
var loaded = ViewLoader.load(fxml("show-visits.fxml"), host, context, models);
|
||||||
|
var table = (Table) loaded.getRoot().lookup("#visitsTable");
|
||||||
|
var scroll = (ScrollPane) table.lookup("." + Table.SCROLL_STYLE);
|
||||||
|
var input = field(scroll.getContent(), "#streetField");
|
||||||
|
host.getVisits().clear();
|
||||||
|
input.setText("Detached");
|
||||||
|
assertEquals("Main", visit.getStreet());
|
||||||
|
|
||||||
|
loaded.close();
|
||||||
|
host.getVisits().add(visit);
|
||||||
|
assertEquals(0, ((VBox) scroll.getContent()).getChildren().size());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static URL fxml(String path) {
|
||||||
|
return ManagedViewTest.class.getResource(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TextField field(javafx.scene.Node root, String id) {
|
||||||
|
return (TextField) root.lookup(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package de.neitzel.fx.view.command;
|
||||||
|
|
||||||
|
import de.neitzel.fx.view.Command;
|
||||||
|
import de.neitzel.fx.view.ViewModel;
|
||||||
|
import de.neitzel.fx.view.ViewModelClass;
|
||||||
|
import jakarta.inject.Named;
|
||||||
|
import javafx.beans.property.BooleanProperty;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Named
|
||||||
|
@ViewModelClass(CommandController.Model.class)
|
||||||
|
public final class CommandController {
|
||||||
|
|
||||||
|
public static final class Subject { }
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static final class Model extends ViewModel {
|
||||||
|
private final BooleanProperty enabled = new SimpleBooleanProperty();
|
||||||
|
private int calls;
|
||||||
|
private final Command clear = new Command(enabled, () -> calls++);
|
||||||
|
|
||||||
|
public Model(Subject bean) {
|
||||||
|
super(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package de.neitzel.fx.view.managed;
|
||||||
|
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import jakarta.inject.Singleton;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class ViewController implements AutoCloseable {
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class Registry {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private ViewController lastCreated;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public Registry() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Registry registry;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@Getter
|
||||||
|
private TextField input;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private int closeCount;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ViewController(Registry registry) {
|
||||||
|
this.registry = registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
registry.lastCreated = this;
|
||||||
|
input.setUserData(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void onAction() {
|
||||||
|
input.setText("Handled");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
closeCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package de.neitzel.fx.view.readable;
|
||||||
|
|
||||||
|
import de.neitzel.fx.view.Converter;
|
||||||
|
import de.neitzel.fx.view.ViewModel;
|
||||||
|
import de.neitzel.fx.view.ViewModelClass;
|
||||||
|
import jakarta.inject.Singleton;
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.binding.BooleanBinding;
|
||||||
|
import javafx.beans.property.ReadOnlyStringProperty;
|
||||||
|
import javafx.beans.property.ReadOnlyStringWrapper;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/** Controller and presentation state for the read-only DirectBinding fixture. */
|
||||||
|
@Singleton
|
||||||
|
@ViewModelClass(ReadableSourcesController.Sources.class)
|
||||||
|
public class ReadableSourcesController {
|
||||||
|
|
||||||
|
/** Sources include a JavaFX binding, a read-only property, and an observable-typed accessor. */
|
||||||
|
public static class Sources extends ViewModel {
|
||||||
|
@Getter
|
||||||
|
private final ObservableList<String> choices = FXCollections.observableArrayList();
|
||||||
|
@Getter
|
||||||
|
private int evaluations;
|
||||||
|
private final BooleanBinding disabled = Bindings.createBooleanBinding(() -> {
|
||||||
|
evaluations++;
|
||||||
|
return choices.isEmpty();
|
||||||
|
}, choices);
|
||||||
|
private final ReadOnlyStringWrapper title = new ReadOnlyStringWrapper("First");
|
||||||
|
|
||||||
|
public Sources(Object model) {
|
||||||
|
super(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanBinding disabledProperty() {
|
||||||
|
return disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyStringProperty titleProperty() {
|
||||||
|
return title.getReadOnlyProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableValue<String> observableTitleProperty() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String value) {
|
||||||
|
title.set(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A display-only converter, with an invalid title for testing Message reporting. */
|
||||||
|
@Singleton
|
||||||
|
public static class Caption implements Converter {
|
||||||
|
@Override
|
||||||
|
public Object toControlValue(Object value) {
|
||||||
|
if ("".equals(value)) {
|
||||||
|
throw new IllegalArgumentException("Caption is required");
|
||||||
|
}
|
||||||
|
return "Caption: " + value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?import de.neitzel.fx.view.BindingList?>
|
||||||
|
<?import de.neitzel.fx.view.DirectBinding?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
<VBox xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.neitzel.fx.view.managed.ViewController">
|
||||||
|
<fx:define>
|
||||||
|
<BindingList>
|
||||||
|
<DirectBinding control="input" property="text" path="name" direction="both"/>
|
||||||
|
<DirectBinding control="missing" property="text" path="name" direction="both"/>
|
||||||
|
</BindingList>
|
||||||
|
</fx:define>
|
||||||
|
<TextField fx:id="input" id="name" onAction="#onAction"/>
|
||||||
|
</VBox>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?import de.neitzel.fx.view.BindingList?>
|
||||||
|
<?import de.neitzel.fx.view.DirectBinding?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
<VBox xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.neitzel.fx.view.managed.ViewController">
|
||||||
|
<fx:define>
|
||||||
|
<BindingList>
|
||||||
|
<DirectBinding control="input" property="text" path="name" direction="both"/>
|
||||||
|
</BindingList>
|
||||||
|
</fx:define>
|
||||||
|
<TextField fx:id="input" id="name" onAction="#onAction"/>
|
||||||
|
</VBox>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?import de.neitzel.fx.view.BindingList?>
|
||||||
|
<?import de.neitzel.fx.view.DirectBinding?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
|
<VBox xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="de.neitzel.fx.view.readable.ReadableSourcesController">
|
||||||
|
<fx:define>
|
||||||
|
<BindingList>
|
||||||
|
<DirectBinding control="commit" property="disable" path="disabled" direction="view"/>
|
||||||
|
<DirectBinding control="title" property="text" path="title" direction="view"/>
|
||||||
|
<DirectBinding control="caption" property="text" path="observableTitle" direction="view"
|
||||||
|
converter="de.neitzel.fx.view.readable.ReadableSourcesController$Caption"/>
|
||||||
|
</BindingList>
|
||||||
|
</fx:define>
|
||||||
|
<Button fx:id="commit" text="Commit"/>
|
||||||
|
<Label fx:id="title"/>
|
||||||
|
<Label fx:id="caption"/>
|
||||||
|
<TextField fx:id="unrelated"/>
|
||||||
|
</VBox>
|
||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
|
|||||||
+2
-2
@@ -8,13 +8,13 @@ The worked example is the person desk in `fx-example`, package `de.neitzel.fx.ex
|
|||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
|
|
||||||
Depend on the module. It brings Reflections 0.10.2 and `jakarta.inject-api` 2.0.1 (plus shared logging dependencies). The parent artifact is `de.neitzel.lib:neitzellib:1.0.2`. Java 25.
|
Depend on the module. It brings Reflections 0.10.2 and `jakarta.inject-api` 2.0.1 (plus shared logging dependencies). The parent artifact is `de.neitzel.lib:neitzellib:1.0.4`. Java 25.
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>injection</artifactId>
|
<artifactId>injection</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>injection</artifactId>
|
<artifactId>injection</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>net</artifactId>
|
<artifactId>net</artifactId>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>de.neitzel.lib</groupId>
|
<groupId>de.neitzel.lib</groupId>
|
||||||
<artifactId>neitzellib</artifactId>
|
<artifactId>neitzellib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>quarkus</artifactId>
|
<artifactId>quarkus</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user