Edit form controls and render localized application previews in the IntelliJ designer

This commit is contained in:
2026-11-24 15:13:31 +01:00
parent 73da1f985e
commit 93a9f04b11
18 changed files with 1623 additions and 63 deletions
@@ -23,6 +23,7 @@ public final class BindingDiscovery {
private final Map<String, String> generatedElements = new HashMap<>();
private ControllerMetadata owner;
private final List<Problem> selectionProblems = new ArrayList<>();
private final Set<String> readOnlySources = new HashSet<>();
private final Map<String, Class<?>> paths = new TreeMap<>();
private final List<Attribute> attributes = new ArrayList<>();
@@ -350,6 +351,9 @@ public final class BindingDiscovery {
if (!Property.class.isAssignableFrom(m.getReturnType())) {
status = "INCOMPATIBLE";
reason = "Runtime bindings require a writable JavaFX Property accessor.";
} else if (readOnlySources.contains(selected) && !direction.equals("view")) {
status = "INCOMPATIBLE";
reason = "Read-only source requires direction=view.";
} else if (source == null
|| source == Object.class
|| value == null
@@ -382,7 +386,6 @@ public final class BindingDiscovery {
}
targets.add(
new Target(id, property, value == null ? "?" : value.getName(), status, reason));
if (targets.size() > 2048) throw new IOException("Too many binding targets");
}
} catch (ClassNotFoundException | LinkageError ex) {
diagnostics.add(id + ": unavailable target type: " + ex.getMessage());
@@ -395,6 +398,15 @@ public final class BindingDiscovery {
.indexOf(t.status()))
.thenComparing(Target::control)
.thenComparing(Target::property));
// Validate every declaration. Bound only the suggestions sent to the editor.
if (targets.size() > 2048) {
targets.sort(Comparator.comparing(t -> !t.control().equals(selectedControl)));
diagnostics.add(
"Showing 2048 of "
+ targets.size()
+ " target properties. Select a control in the form inspector to edit its bindings.");
targets.subList(2048, targets.size()).clear();
}
var converters = new ConverterDiscovery(loader);
var chosen = targetTypes.get(selectedControl + "." + selectedProperty);
var candidates =
@@ -500,7 +512,8 @@ public final class BindingDiscovery {
for (Method m : vm.getMethods()) {
if (m.getParameterCount() != 0
|| !m.getName().endsWith("Property")
|| !Property.class.isAssignableFrom(m.getReturnType())
|| !ObservableValue.class.isAssignableFrom(m.getReturnType())
|| Modifier.isStatic(m.getModifiers())
|| m.isBridge()
|| m.isSynthetic()) continue;
String name = m.getName().substring(0, m.getName().length() - 8);
@@ -510,12 +523,16 @@ public final class BindingDiscovery {
if (value == Number.class && getter != null && Number.class.isAssignableFrom(box(getter)))
value = getter;
else if (value != null && getter != null && box(value) != box(getter)) value = null;
boolean readOnly = !Property.class.isAssignableFrom(m.getReturnType());
if (readOnly) readOnlySources.add(name);
paths.put(name, value == null ? Object.class : value);
attributes.add(
new Attribute(
name,
value == null ? "?" : value.getName(),
value == null || value == Object.class ? "UNRESOLVED" : "VIEWMODEL",
readOnly
? "READ_ONLY"
: value == null || value == Object.class ? "UNRESOLVED" : "VIEWMODEL",
""));
if (attributes.size() > 256) throw new IOException("Too many ViewModel properties");
}
@@ -669,6 +686,9 @@ public final class BindingDiscovery {
} else if (!target.writable()) {
severity = "ERROR";
message = "Runtime requires a writable JavaFX Property";
} else if (readOnlySources.contains(path) && !direction.equals("view")) {
severity = "ERROR";
message = "Read-only source " + path + " requires direction=view";
} else if (source == null) {
severity = incompleteModel ? "WARNING" : "ERROR";
message = "Unknown or unresolved Model path: " + path;
@@ -216,7 +216,21 @@ class ViewModelComputedTest {
assertEquals(String.class.getName(), types.get("badge"));
assertEquals(String.class.getName(), types.get("name"));
assertEquals(String.class.getName(), types.get("latestMessage"));
assertFalse(types.containsKey("readOnly"));
assertEquals(String.class.getName(), types.get("readOnly"));
assertTrue(
result.attributes().stream()
.anyMatch(a -> a.path().equals("readOnly") && a.kind().equals("READ_ONLY")));
for (String direction : List.of("view", "model", "both")) {
var validation =
inspect(
xml(
Controller.class,
direct("readOnly").replace("direction='view'", "direction='" + direction + "'")));
assertEquals(
!direction.equals("view"),
validation.problems().stream()
.anyMatch(p -> p.message().contains("requires direction=view")));
}
assertEquals(Custom.class.getName(), result.viewModel());
assertTrue(result.problems().isEmpty(), result.problems().toString());
for (String key : List.of("vm.metadata.initialized", "controller.metadata.initialized"))