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
@@ -0,0 +1,89 @@
package qualification;
import java.nio.file.*;
import java.util.concurrent.*;
import javafx.application.Platform;
import javafx.scene.control.*;
import javafx.stage.Window;
/** In the disposable target JVM, inspect the controls that the IDE actually launched. */
public final class ConnectionTargetProbe {
public static void premain(String directory) {
if (!System.getProperty("sun.java.command", "")
.startsWith("de.neitzel.fxdesigner.target.WorkerMain ")) return;
Thread.ofPlatform().daemon().start(() -> Probe.observe(Path.of(directory)));
}
private static final class Probe {
private static void observe(Path directory) {
try {
while (true) {
Thread.sleep(200);
var result = new FutureTask<>(() -> inspect(directory));
try {
Platform.runLater(result);
} catch (IllegalStateException starting) {
continue;
}
if (result.get(10, TimeUnit.SECONDS)) return;
}
} catch (Throwable ex) {
try {
Files.writeString(directory.resolve("target-error.txt"), ex + " " + ex.getCause());
} catch (Exception writeError) {
ex.printStackTrace();
}
}
}
private static boolean changed;
private static boolean inspect(Path directory) throws Exception {
var window =
Window.getWindows().stream()
.filter(Window::isShowing)
.filter(w -> w.getScene().lookup("#protocol") instanceof ComboBox)
.findFirst();
if (window.isEmpty()) return false;
var root = window.get().getScene().getRoot();
var user = (TextField) root.lookup("#user");
var mirror = (Label) root.lookup("#label");
var auto = (TextField) root.lookup("#autoCompleteTextField");
if (changed) {
if (!Files.exists(directory.resolve("unrelated-saved"))) return false;
if (!"changed@example.org".equals(user.getText())
|| !user.getText().equals(mirror.getText()))
throw new AssertionError("Unrelated save reset interactive state");
Files.writeString(directory.resolve("retained-imap"), "" + ProcessHandle.current().pid());
return true;
}
var protocol = ((ComboBox<?>) root.lookup("#protocol")).getValue().toString();
boolean imap = protocol.equals("IMAP");
String id = imap ? "imap" : "jmap";
if (!Files.readString(directory.resolve("attempt")).equals(id))
throw new AssertionError("Wrong example " + id);
if (!root.lookupAll(".label").stream()
.anyMatch(n -> n instanceof Label l && l.getText().equals("Protokoll")))
throw new AssertionError("Missing localized protocol label");
if (!((Label) root.lookup("#label2")).getText().equals("Kontoprüfung")
|| !((TextField) root.lookup("#endpoint"))
.getText()
.equals(imap ? "imap.example.org" : "https://mail.example.org/.well-known/jmap")
|| !user.getText().equals(imap ? "anna@example.org" : "ben@example.org")
|| !user.getText().equals(mirror.getText())
|| !user.getText().equals(auto.getText())
|| root.lookup("#port").isDisabled() == imap
|| root.lookup("#account").isDisabled() != imap
|| !((Spinner<?>) root.lookup("#nonNegativeIntegerSpinner")).getValue().equals(14))
throw new AssertionError("Unexpected rendered data or field enablement in " + protocol);
user.setText("changed@example.org");
if (!user.getText().equals(mirror.getText()) || !user.getText().equals(auto.getText()))
throw new AssertionError("Missing model write-back");
changed = true;
Files.writeString(
directory.resolve("result-" + id),
protocol + " · Protokoll · " + ProcessHandle.current().pid());
return !imap;
}
}
}