Edit and exercise Archiver CommandBindings in the IntelliJ designer

This commit is contained in:
2026-11-24 14:42:35 +01:00
parent 54e202014e
commit 98d37c6c3d
38 changed files with 1304 additions and 190 deletions
@@ -0,0 +1,32 @@
package fixture.components;
@jakarta.inject.Singleton
@de.neitzel.fx.view.ViewModelClass(CommandCard.Model.class)
public class CommandCard extends javafx.scene.layout.VBox {
private final javafx.beans.property.ObjectProperty<fixture.model.Address> model =
new javafx.beans.property.SimpleObjectProperty<>();
public javafx.beans.property.ObjectProperty<fixture.model.Address> modelProperty() {
return model;
}
public static class Model extends de.neitzel.fx.view.ViewModel {
private final de.neitzel.fx.view.Command run;
public Model(fixture.model.Address model) {
super(model);
var enabled = new javafx.beans.property.SimpleBooleanProperty(true);
run =
new de.neitzel.fx.view.Command(
enabled,
() -> {
model.setStreet("Command executed");
enabled.set(false);
});
}
public de.neitzel.fx.view.Command getRun() {
return run;
}
}
}
@@ -15,6 +15,7 @@ public class PersonController implements de.neitzel.fx.view.HasViewModel {
return "Uncertain";
}
public static PersonController boundController;
public final Greeting greeting;
public de.neitzel.fx.view.ViewModel received;
@@ -25,6 +26,7 @@ public class PersonController implements de.neitzel.fx.view.HasViewModel {
public void setViewModel(de.neitzel.fx.view.ViewModel vm) {
received = vm;
boundController = this;
}
public void action() {
@@ -0,0 +1,8 @@
<?neitzel-model fixture.model.Address?>
<?import javafx.scene.control.Button?>
<?import de.neitzel.fx.view.BindingList?>
<?import de.neitzel.fx.view.CommandBinding?>
<fx:root xmlns:fx="http://javafx.com/fxml/1" type="javafx.scene.layout.VBox">
<fx:define><BindingList><CommandBinding control="run" path="run"/></BindingList></fx:define>
<Button fx:id="run" text="Run"/>
</fx:root>
@@ -52,7 +52,8 @@ public final class PreviewChecks {
if (mode.equals("unstable")
|| mode.equals("full")
|| mode.equals("full-empty")
|| mode.equals("card")) {
|| mode.equals("card")
|| mode.equals("command-card")) {
StageChecks.run(mode);
return;
}
@@ -345,7 +346,7 @@ public final class PreviewChecks {
() -> {
var view = ready.loadedView();
check(view.getViewModel() instanceof PersonViewModel, "Named ViewModel not selected");
var controller = Examples.context.getComponent(PersonController.class);
var controller = PersonController.boundController;
check(controller.received == view.getViewModel(), "Controller ViewModel handoff");
check(controller.greeting == Examples.service, "Configured service not injected");
var card = (Card) view.getRoot().lookup("#card");
@@ -20,17 +20,25 @@ public final class StageChecks {
if (!started.await(10, TimeUnit.SECONDS)) throw new AssertionError("FX startup");
var descriptor =
ExampleCatalog.discover(StageChecks.class.getClassLoader()).stream()
.filter(e -> e.id().equals(mode.equals("unstable") ? "full" : mode))
.filter(
e ->
e.id()
.equals(
mode.equals("unstable")
? "full"
: mode.equals("command-card") ? "card" : mode))
.findFirst()
.orElseThrow();
if (mode.equals("unstable"))
if (mode.equals("unstable") || mode.equals("command-card"))
descriptor =
new de.neitzel.fxdesigner.preview.ExampleDescriptor(
descriptor.id(),
descriptor.label(),
descriptor.modelType(),
descriptor.providerClass(),
"fixture/components/Unstable.fxml",
mode.equals("unstable")
? "fixture/components/Unstable.fxml"
: "fixture/components/CommandCard.fxml",
descriptor.componentPackage());
var preview =
TargetPreview.open(descriptor, StageChecks.class.getClassLoader(), Duration.ofSeconds(15));
@@ -55,7 +63,15 @@ public final class StageChecks {
PreviewChecks.fx(
() -> {
var root = ready.loadedView().getRoot();
if (mode.equals("card")) {
if (mode.equals("command-card")) {
var button = (Button) root.lookup("#run");
var model = (fixture.model.Address) ((CommandCard) root).modelProperty().get();
button.fire();
PreviewChecks.check(
model.getStreet().equals("Command executed"), "Component command");
PreviewChecks.check(
button.isDisabled(), "Component command disabled after execution");
} else if (mode.equals("card")) {
var card = (Card) root;
PreviewChecks.check(
card.street().getText().equals("Independent Card sample"),