Add shared source-preserving Computed binding inspector
This commit is contained in:
@@ -43,6 +43,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
if (hit == null) return;
|
||||
String id = hit.getFxId();
|
||||
if (bindingEditor != null) bindingEditor.selectControl(id);
|
||||
if (computedEditor != null) computedEditor.selectControl(id);
|
||||
if (id == null || !projection.components().containsKey(id)) return;
|
||||
componentInspector.getChildren().add(new Label(projection.components().get(id) + " · " + id));
|
||||
componentInspector
|
||||
@@ -114,7 +115,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
private DesignerWorkflow interactiveWorkflow;
|
||||
private DesignerWorkflow bindingWorkflow;
|
||||
private BindingBrowser bindingBrowser;
|
||||
private DirectBindingEditor bindingEditor;
|
||||
private BindingEditor bindingEditor, computedEditor;
|
||||
private String validatedSource, validatingSource;
|
||||
private boolean validationPreview;
|
||||
private java.util.List<de.neitzel.fxdesigner.protocol.BindingMetadata.Problem> bindingProblems =
|
||||
@@ -180,7 +181,18 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
launch.tools(),
|
||||
this::log);
|
||||
bindingEditor =
|
||||
new DirectBindingEditor(
|
||||
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;
|
||||
@@ -334,7 +346,10 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
discoveryTab.setClosable(false);
|
||||
directBindingTab = new Tab("Direct bindings", bindingEditor);
|
||||
directBindingTab.setClosable(false);
|
||||
var bindings = new TitledPane("Bindings", new TabPane(directBindingTab, discoveryTab));
|
||||
var computedTab = new Tab("Computed bindings", computedEditor);
|
||||
computedTab.setClosable(false);
|
||||
var bindings =
|
||||
new TitledPane("Bindings", new TabPane(directBindingTab, computedTab, discoveryTab));
|
||||
bindings.setExpanded(false);
|
||||
center.setBottom(new VBox(properties, bindings));
|
||||
output.setEditable(false);
|
||||
@@ -475,6 +490,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
}
|
||||
draft = value;
|
||||
bindingEditor.load(value.text(), value.writable());
|
||||
computedEditor.load(value.text(), value.writable());
|
||||
submittedSource = null;
|
||||
commitSource();
|
||||
return;
|
||||
@@ -497,6 +513,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
String selectedId = hit == null ? null : hit.getFxId();
|
||||
draft = value;
|
||||
bindingEditor.load(value.text(), value.writable());
|
||||
computedEditor.load(value.text(), value.writable());
|
||||
if (!source.getText().equals(value.text())) {
|
||||
int anchor = source.getAnchor(), caret = source.getCaretPosition();
|
||||
var edits =
|
||||
@@ -651,14 +668,14 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
bindingBrowser.invalidate(message);
|
||||
}
|
||||
|
||||
private void editBinding(DirectBindingEditor.Intent intent) {
|
||||
private void editBinding(BindingEditor.Intent intent) {
|
||||
withDraft(
|
||||
() -> {
|
||||
try {
|
||||
if (!draft.writable()) throw new IllegalStateException("Document is read-only");
|
||||
if (!draft.text().equals(intent.source()))
|
||||
throw new IllegalStateException("Document changed; select the binding again");
|
||||
var bindings = new DirectBindingDocument(draft.text());
|
||||
var bindings = new BindingDocument(draft.text(), intent.kind());
|
||||
var edits =
|
||||
intent.remove()
|
||||
? bindings.remove(java.util.Objects.requireNonNull(intent.index()))
|
||||
@@ -666,17 +683,18 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
submit(
|
||||
edits,
|
||||
intent.remove()
|
||||
? "Remove DirectBinding"
|
||||
: intent.index() == null ? "Create DirectBinding" : "Edit DirectBinding");
|
||||
? "Remove " + intent.kind().element()
|
||||
: (intent.index() == null ? "Create " : "Edit ") + intent.kind().element());
|
||||
} catch (Exception error) {
|
||||
bindingEditor.error(error.getMessage());
|
||||
(intent.kind() == BindingDocument.Kind.COMPUTED ? computedEditor : bindingEditor)
|
||||
.error(error.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean bindingPreviewAllowed() {
|
||||
try {
|
||||
var errors = new DirectBindingDocument(draft.text()).errors();
|
||||
var errors = new BindingDocument(draft.text()).errors();
|
||||
if (errors.isEmpty()) return true;
|
||||
status.setText("Preview blocked: " + String.join("; ", errors));
|
||||
if (projection != null)
|
||||
@@ -690,7 +708,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void validateBindings(DirectBindingDocument.Values values, boolean preview) {
|
||||
private void validateBindings(BindingDocument.Values values, boolean preview) {
|
||||
withDraft(
|
||||
() -> {
|
||||
if (preview && draft.text().equals(validatingSource)) {
|
||||
@@ -735,6 +753,14 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
: "Current successful build")
|
||||
+ " · draft revision "
|
||||
+ captured.revision());
|
||||
computedEditor.metadata(
|
||||
metadata,
|
||||
values,
|
||||
(last
|
||||
? "Explicit retained build (outdated)"
|
||||
: "Current successful build")
|
||||
+ " · draft revision "
|
||||
+ captured.revision());
|
||||
status.setText(
|
||||
"Binding validation complete: "
|
||||
+ metadata.problems().size()
|
||||
|
||||
Reference in New Issue
Block a user