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
@@ -46,6 +46,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
if (bindingEditor != null) bindingEditor.selectControl(id);
if (computedEditor != null) computedEditor.selectControl(id);
if (repeatEditor != null) repeatEditor.selectControl(id);
if (commandEditor != null) commandEditor.selectControl(id);
if (tableEditor != null) tableEditor.selectControl(id);
if (referenceEditor != null) referenceEditor.selectIndex(projection.sourceIndex(id));
if (id == null || !projection.components().containsKey(id)) return;
@@ -120,7 +121,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
private DesignerWorkflow bindingWorkflow;
private ViewGenerationPane viewGeneration;
private BindingBrowser bindingBrowser;
private BindingEditor bindingEditor, computedEditor, repeatEditor;
private BindingEditor bindingEditor, computedEditor, repeatEditor, commandEditor;
private TableEditor tableEditor;
private ReferenceEditor referenceEditor;
private DiagnosticsPane diagnosticsPane;
@@ -194,36 +195,10 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
launch.maven(),
launch.tools(),
this::log);
bindingEditor =
new BindingEditor(
BindingDocument.Kind.DIRECT,
this::editBinding,
id -> {
if (kit.editor().getFxomDocument() == null) return;
var target = new FXOMFxIdIndex(kit.editor().getFxomDocument()).lookup(id);
if (target != null) kit.editor().getSelection().select(target);
},
values -> validateBindings(values, false));
computedEditor =
new BindingEditor(
BindingDocument.Kind.COMPUTED,
this::editBinding,
id -> {
if (kit.editor().getFxomDocument() == null) return;
var target = new FXOMFxIdIndex(kit.editor().getFxomDocument()).lookup(id);
if (target != null) kit.editor().getSelection().select(target);
},
values -> validateBindings(values, false));
repeatEditor =
new BindingEditor(
BindingDocument.Kind.REPEAT,
this::editBinding,
id -> {
if (kit.editor().getFxomDocument() == null) return;
var target = new FXOMFxIdIndex(kit.editor().getFxomDocument()).lookup(id);
if (target != null) kit.editor().getSelection().select(target);
},
values -> validateBindings(values, false));
bindingEditor = editor(BindingDocument.Kind.DIRECT);
computedEditor = editor(BindingDocument.Kind.COMPUTED);
repeatEditor = editor(BindingDocument.Kind.REPEAT);
commandEditor = editor(BindingDocument.Kind.COMMAND);
tableEditor =
new TableEditor(
this::editTable, this::navigateComponent, values -> validateBindings(values, false));
@@ -379,6 +354,8 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
directBindingTab.setClosable(false);
var computedTab = new Tab("Computed bindings", computedEditor);
computedTab.setClosable(false);
var commandTab = new Tab("Command bindings", commandEditor);
commandTab.setClosable(false);
var repeatTab = new Tab("Repeat bindings", repeatEditor);
repeatTab.setClosable(false);
var tableTab = new Tab("Table / Columns", tableEditor);
@@ -396,6 +373,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
new TabPane(
directBindingTab,
computedTab,
commandTab,
repeatTab,
tableTab,
structureTab,
@@ -546,6 +524,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
bindingEditor.load(value.text(), value.writable());
computedEditor.load(value.text(), value.writable());
repeatEditor.load(value.text(), value.writable());
commandEditor.load(value.text(), value.writable());
tableEditor.load(value.text(), value.writable());
referenceEditor.load(value.text(), value.writable());
submittedSource = null;
@@ -578,6 +557,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
bindingEditor.load(value.text(), value.writable());
computedEditor.load(value.text(), value.writable());
repeatEditor.load(value.text(), value.writable());
commandEditor.load(value.text(), value.writable());
tableEditor.load(value.text(), value.writable());
referenceEditor.load(value.text(), value.writable());
if (!source.getText().equals(value.text())) {
@@ -750,6 +730,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
bindingWorkflow.cancel();
bindingBrowser.invalidate(message);
repeatEditor.invalidateDiscovery();
commandEditor.invalidateDiscovery();
tableEditor.invalidateDiscovery();
}
@@ -846,6 +827,10 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
if (!draft.writable()) throw new IllegalStateException("Document is read-only");
if (!draft.text().equals(intent.source()))
throw new IllegalStateException("Document changed; select the source object again");
if (!intent.change().importedCommandTargets().isEmpty()) {
validateCommandPaste(intent);
return;
}
if (intent.validate())
pendingReferenceValidation = apply(draft.text(), intent.change().edits());
submit(intent.change().edits(), intent.label());
@@ -855,6 +840,58 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
});
}
/** Validate imported Command paths against the destination snapshot before the first write. */
private void validateCommandPaste(ReferenceEditor.Intent intent) {
var original = draft;
String proposed = apply(original.text(), intent.change().edits());
var candidate =
new DocumentSnapshot(
original.document(), original.revision(), proposed, original.writable(), true);
bindingWorkflow
.bindingDetails(last, candidate, "", "view", "", "")
.whenComplete(
(metadata, error) ->
fx(
() -> {
if (closed) return;
if (error != null) {
referenceEditor.error(
"Cannot validate the destination Commands: " + error.getMessage());
return;
}
if (draft.revision() != original.revision()
|| !source.getText().equals(original.text())) {
referenceEditor.error(
"Destination changed. Select the destination and paste again.");
return;
}
if (!metadata
.commandTargets()
.containsAll(intent.change().importedCommandTargets())) {
referenceEditor.error(
"The destination build could not resolve the copied Command targets.");
return;
}
var conflicts =
metadata.problems().stream()
.filter(
p ->
p.severity().equals("ERROR")
&& intent
.change()
.importedCommandTargets()
.contains(p.control()))
.map(p -> p.message())
.toList();
if (!conflicts.isEmpty()) {
referenceEditor.error(String.join("; ", conflicts));
return;
}
pendingReferenceValidation = proposed;
submit(intent.change().edits(), intent.label());
}));
}
private void editTable(TableEditor.Intent intent) {
withDraft(
() -> {
@@ -869,6 +906,19 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
});
}
private BindingEditor editor(BindingDocument.Kind kind) {
return new BindingEditor(
kind,
this::editBinding,
id -> {
var document = kit.editor().getFxomDocument();
if (document == null) return;
var selection = new FXOMFxIdIndex(document).lookup(id);
if (selection != null) kit.editor().getSelection().select(selection);
},
values -> validateBindings(kind == BindingDocument.Kind.COMMAND ? null : values, false));
}
private void editBinding(BindingEditor.Intent intent) {
withDraft(
() -> {
@@ -891,7 +941,9 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
? repeatEditor
: intent.kind() == BindingDocument.Kind.COMPUTED
? computedEditor
: bindingEditor)
: intent.kind() == BindingDocument.Kind.COMMAND
? commandEditor
: bindingEditor)
.error(error.getMessage());
}
});
@@ -979,6 +1031,10 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
: "Current successful build")
+ " · draft revision "
+ captured.revision());
commandEditor.metadata(
metadata,
values,
last ? "Retained build" : "Current successful build");
repeatEditor.metadata(
metadata,
values,
@@ -1159,7 +1215,11 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
return;
}
var selected = examples.getValue();
if (selected == null || projection == null) return;
if (selected == null) {
status.setText("Select a preview example after Build and Refresh.");
return;
}
if (projection == null && !interactiveRequested) return;
long ticket = renderSequence.incrementAndGet();
host.documents()
.snapshots()
@@ -1191,7 +1251,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
new DocumentSnapshot(
draft.document(),
draft.revision(),
projection.previewText(),
projection == null ? draft.text() : projection.previewText(),
draft.writable(),
draft.dirty()));
renderComponents(List.copyOf(drafts.values()), selected.id(), ticket);
@@ -1202,7 +1262,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
private void renderComponents(List<DocumentSnapshot> drafts, String example, long ticket) {
if (ticket != renderSequence.get() || closed) return;
var nodes = new LinkedHashMap<String, DesignerWorkflow.Size>();
for (String id : projection.components().keySet()) {
for (String id : projection == null ? Set.<String>of() : projection.components().keySet()) {
var region = proxy(id);
if (region == null) continue;
int
@@ -1246,7 +1306,10 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
}));
}
if (nodes.isEmpty()) {
status.setText("No embedded Components; use Interactive preview for this View");
status.setText(
projection == null
? "Canvas projection unavailable; interactive preview uses the FXML draft"
: "No embedded Components; use Interactive preview for this View");
return;
}
workflow