Edit control properties and verify controller event handlers in IntelliJ
This commit is contained in:
@@ -876,6 +876,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
validatingSource = null;
|
||||
validationPreview = false;
|
||||
bindingWorkflow.cancel();
|
||||
formEditor.eventHandlers(Optional.empty());
|
||||
bindingBrowser.invalidate(message);
|
||||
repeatEditor.invalidateDiscovery();
|
||||
commandEditor.invalidateDiscovery();
|
||||
@@ -1163,6 +1164,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
}
|
||||
validatedSource = captured.text();
|
||||
bindingProblems = metadata.problems();
|
||||
formEditor.eventHandlers(metadata.actionEventHandlers());
|
||||
publishDiagnostics(
|
||||
last
|
||||
? "Explicit retained build (outdated)"
|
||||
@@ -1243,6 +1245,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
}
|
||||
validatedSource = captured.text();
|
||||
bindingProblems = metadata.problems();
|
||||
formEditor.eventHandlers(metadata.actionEventHandlers());
|
||||
publishDiagnostics(
|
||||
last
|
||||
? "Explicit retained build (outdated)"
|
||||
|
||||
@@ -316,6 +316,12 @@ final class FormDocument {
|
||||
List<Field> fields(Item item) {
|
||||
var e = element(item);
|
||||
var fields = new LinkedHashMap<String, Field>();
|
||||
field(fields, "accessibleText", "String", "");
|
||||
if (Set.of("TextField", "PasswordField", "AutoCompleteTextField").contains(item.type()))
|
||||
field(fields, "prefColumnCount", "Integer", "12");
|
||||
if (Set.of(
|
||||
"TextField", "PasswordField", "AutoCompleteTextField", "Button", "CheckBox", "ComboBox")
|
||||
.contains(item.type())) field(fields, "onAction", "Event handler", "");
|
||||
field(fields, "styleClass", "CSS classes", "control default");
|
||||
field(fields, "padding", "Insets", item.type().equals("StatusBar") ? "4 8 4 8" : "0");
|
||||
field(fields, "style", "CSS", "");
|
||||
|
||||
@@ -13,6 +13,8 @@ final class FormEditor extends VBox {
|
||||
private final Spinner<Integer> position = new Spinner<>(0, 0, 0);
|
||||
private final ComboBox<FormDocument.Item> selected = combo("form-control");
|
||||
private final ComboBox<FormDocument.Field> field = combo("form-property");
|
||||
private final ComboBox<String> handlers = combo("form-event-handlers");
|
||||
private Optional<List<String>> verifiedHandlers = Optional.empty();
|
||||
private final TextArea value = new TextArea();
|
||||
private final Label details = new Label(), message = new Label();
|
||||
private final Consumer<FormDocument.Edit> submit;
|
||||
@@ -30,6 +32,13 @@ final class FormEditor extends VBox {
|
||||
palette.setValue("Label");
|
||||
position.setId("form-position");
|
||||
position.setPrefWidth(74);
|
||||
handlers.setPromptText("Choose controller method");
|
||||
handlers.managedProperty().bind(handlers.visibleProperty());
|
||||
handlers.setVisible(false);
|
||||
handlers.setOnAction(
|
||||
e -> {
|
||||
if (handlers.getValue() != null) value.setText(handlers.getValue());
|
||||
});
|
||||
value.setId("form-value");
|
||||
value.setPrefRowCount(2);
|
||||
details.setId("form-field-type");
|
||||
@@ -79,18 +88,25 @@ final class FormEditor extends VBox {
|
||||
destination.getValue(),
|
||||
position.getValue())))),
|
||||
row(new Label("Property"), field, details),
|
||||
handlers,
|
||||
value,
|
||||
row(
|
||||
button(
|
||||
"Set property",
|
||||
() ->
|
||||
perform(
|
||||
() ->
|
||||
form.set(
|
||||
selected.getValue(),
|
||||
field.getValue(),
|
||||
value.getText(),
|
||||
false))),
|
||||
() -> {
|
||||
if (eventSelected()
|
||||
&& verifiedHandlers.isPresent()
|
||||
&& !verifiedHandlers.get().contains(value.getText()))
|
||||
throw new IllegalArgumentException(
|
||||
"No accessible controller method "
|
||||
+ value.getText()
|
||||
+ " for ActionEvent. Choose a listed method with no"
|
||||
+ " argument or a compatible event argument.");
|
||||
return form.set(
|
||||
selected.getValue(), field.getValue(), value.getText(), false);
|
||||
})),
|
||||
button(
|
||||
"Reset property",
|
||||
() -> perform(() -> form.set(selected.getValue(), field.getValue(), "", true))),
|
||||
@@ -168,7 +184,27 @@ final class FormEditor extends VBox {
|
||||
showValue();
|
||||
}
|
||||
|
||||
void eventHandlers(Optional<List<String>> names) {
|
||||
verifiedHandlers = names;
|
||||
handlers.getItems().setAll(names.orElse(List.of()));
|
||||
handlers.setDisable(names.isEmpty());
|
||||
if (eventSelected()) showHandlerStatus();
|
||||
}
|
||||
|
||||
private boolean eventSelected() {
|
||||
return field.getValue() != null && field.getValue().type().equals("Event handler");
|
||||
}
|
||||
|
||||
private void showHandlerStatus() {
|
||||
details.setText(
|
||||
verifiedHandlers.isEmpty()
|
||||
? "ActionEvent · Build and Refresh to check controller methods"
|
||||
: "ActionEvent · methods from the compiled controller");
|
||||
}
|
||||
|
||||
private void showValue() {
|
||||
handlers.setVisible(eventSelected());
|
||||
handlers.getSelectionModel().clearSelection();
|
||||
var f = field.getValue();
|
||||
var item = selected.getValue();
|
||||
if (form == null || item == null || f == null) {
|
||||
@@ -184,6 +220,7 @@ final class FormEditor extends VBox {
|
||||
+ (f.type().equals("ObservableList<String>")
|
||||
? "bind to a model list"
|
||||
: f.editable() ? "editable" : "read only"));
|
||||
if (eventSelected()) showHandlerStatus();
|
||||
value.setEditable(f.editable());
|
||||
value.setText(form.value(item, f));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user