Edit DataGrid columns and dock layout declarations in the designer

This commit is contained in:
2026-11-24 15:59:08 +01:00
parent 43267824d7
commit b04bd9d7ef
14 changed files with 1148 additions and 17 deletions
@@ -0,0 +1,119 @@
package qualification;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.stage.Window;
/**
* Measures the real Archiver controls in the interactive worker launched by the registered editor.
*/
public final class GridDockTargetProbe {
public static void premain(String dir) {
if (!System.getProperty("sun.java.command", "")
.startsWith("de.neitzel.fxdesigner.target.WorkerMain ")) return;
Thread.ofPlatform().daemon().start(() -> Probe.observe(Path.of(dir)));
}
private static final class Probe {
private static void observe(Path dir) {
try {
while (true) {
Thread.sleep(200);
var check = new FutureTask<>(() -> inspect(dir));
try {
Platform.runLater(check);
} catch (IllegalStateException starting) {
continue;
}
if (check.get(10, TimeUnit.SECONDS)) return;
}
} catch (Throwable e) {
try {
Files.writeString(dir.resolve("target-error.txt"), e + " " + e.getCause());
} catch (Exception ignored) {
e.printStackTrace();
}
}
}
private static boolean inspect(Path dir) throws Exception {
var windows = Window.getWindows().stream().filter(Window::isShowing).toList();
if (windows.isEmpty() || !Files.exists(dir.resolve("attempt"))) return false;
var root = windows.getFirst().getScene().getRoot();
String attempt = Files.readString(dir.resolve("attempt"));
if (attempt.equals("folder")) {
var grid = root.lookup("#grid");
if (grid == null) return false;
var grouping = (ChoiceBox<?>) root.lookup("#grouping");
if (!"Nach Ordner".equals(String.valueOf(grouping.getValue())))
throw new AssertionError("Wrong grouping choice: " + grouping.getValue());
var type = grid.getClass();
var cols = (List<?>) type.getMethod("getColumns").invoke(grid);
var first = cols.getFirst();
if (!"Archivdatei".equals(first.getClass().getMethod("getHeader").invoke(first)))
throw new AssertionError("Unexpected first column");
var texts =
root.lookupAll("*").stream()
.filter(Labeled.class::isInstance)
.map(n -> ((Labeled) n).getText())
.filter(Objects::nonNull)
.toList();
for (String expected : List.of("Archivdatei", "Musterrechnung.pdf", "Lieferbrief.txt"))
if (!texts.contains(expected))
throw new AssertionError("Missing " + expected + " in " + texts);
type.getMethod("select", Object.class).invoke(grid, "Musterrechnung.pdf");
Object key =
((ObservableValue<?>) type.getMethod("selectedKeyProperty").invoke(grid)).getValue();
Object row =
((ObservableValue<?>) type.getMethod("selectedElementProperty").invoke(grid))
.getValue();
if (!"Musterrechnung.pdf".equals(key)
|| !key.equals(row.getClass().getMethod("path").invoke(row)))
throw new AssertionError("Unstable selection " + key);
Files.writeString(
dir.resolve("result-folder"),
"Archivdatei · Musterrechnung.pdf · Lieferbrief.txt · selectedKey=" + key);
} else {
Node doc = null, details = null;
for (var n : root.lookupAll(".label"))
if (n instanceof Label label) {
if ("Dokument im Beispielarchiv".equals(label.getText())) doc = n;
if ("Belegnummer RE-2026-042".equals(label.getText())) details = n;
}
if (doc == null || details == null)
throw new AssertionError("Missing visible example content");
if (attempt.equals("bottom")) {
var pane = root.lookup("#dockPane");
var layout = pane.getClass().getMethod("getInitialLayout").invoke(pane);
var center = layout.getClass().getMethod("getCenter").invoke(layout);
var bottom = layout.getClass().getMethod("getBottom").invoke(layout);
if (!"VERTICAL"
.equals(center.getClass().getMethod("getOrientation").invoke(center).toString())
|| !"beleg".equals(bottom.getClass().getMethod("getDestinationId").invoke(bottom)))
throw new AssertionError("Target did not load the edited split and destination");
}
var a = doc.localToScene(doc.getBoundsInLocal());
var b = details.localToScene(details.getBoundsInLocal());
if (attempt.equals("right") ? b.getMinX() <= a.getMaxX() : b.getMinY() <= a.getMaxY())
throw new AssertionError("Wrong " + attempt + " arrangement: " + a + " / " + b);
Files.writeString(
dir.resolve("result-" + attempt),
"Dokument ("
+ (int) a.getMinX()
+ ","
+ (int) a.getMinY()
+ "), Belegnummer ("
+ (int) b.getMinX()
+ ","
+ (int) b.getMinY()
+ ")");
}
return true;
}
}
}