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;
}
}
}
@@ -0,0 +1,317 @@
package qualification;
import static qualification.WorkflowProbe.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.vfs.*;
import de.neitzel.fxdesigner.kit.DesignerPane;
import java.nio.file.*;
import java.util.*;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.control.*;
import javafx.scene.image.*;
import javax.imageio.ImageIO;
import org.w3c.dom.Element;
/** Drives the inspector, native document and target preview in a disposable Archiver checkout. */
public final class GridDockWorkflowProbe implements StartupActivity.DumbAware {
private DesignerPane pane;
private VirtualFile file;
private Project project;
public void runActivity(Project project) {
if (!started.compareAndSet(false, true)) return;
this.project = project;
ApplicationManager.getApplication()
.executeOnPooledThread(
() -> {
try {
verify();
} catch (Throwable ex) {
try {
var trace = new java.io.StringWriter();
ex.printStackTrace(new java.io.PrintWriter(trace));
if (pane != null)
trace.append(
fx(
() ->
pane.lookupAll(".label").stream()
.filter(Label.class::isInstance)
.map(n -> ((Label) n).getText())
.filter(Objects::nonNull)
.toList()
.toString()));
Files.writeString(output.resolve("FAILURE.txt"), trace.toString());
} catch (Exception e) {
ex.printStackTrace();
}
}
});
}
private void step(String text) throws Exception {
Files.writeString(
output.resolve("steps.txt"),
text + "\n",
StandardOpenOption.CREATE,
StandardOpenOption.APPEND);
}
private String source() throws Exception {
return edt(() -> FileDocumentManager.getInstance().getDocument(file).getText());
}
private void open(Path path) throws Exception {
file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path));
pane = openDesigner(project, file);
step("Opened " + file.getName());
}
private void inspector(boolean expanded) throws Exception {
fx(
() -> {
var panel =
(TitledPane)
pane.lookupAll(".titled-pane").stream()
.filter(n -> n instanceof TitledPane t && t.getText().equals("Bindings"))
.findFirst()
.orElseThrow();
panel.setAnimated(false);
panel.setExpanded(expanded);
var tabs = (TabPane) panel.getContent();
tabs.getSelectionModel()
.select(
tabs.getTabs().stream()
.filter(t -> t.getText().equals("DataGrid / Docking"))
.findFirst()
.orElseThrow());
pane.applyCss();
pane.layout();
return null;
});
}
private void select(String name, String id) throws Exception {
fx(
() -> {
var tree = (TreeView<Element>) pane.lookup("#declaration-tree");
for (int i = 0; i < tree.getExpandedItemCount(); i++) {
var item = tree.getTreeItem(i);
var e = item.getValue();
String tag = e.getTagName();
if ((tag.equals(name) || tag.endsWith("." + name))
&& (id.isEmpty()
|| e.getAttribute("id").equals(id)
|| e.getAttribute("destinationId").equals(id))) {
tree.getSelectionModel().select(item);
return null;
}
}
throw new AssertionError("Missing " + name + " " + id);
});
}
private void combo(String name, String text) throws Exception {
fx(
() -> {
var box = (ComboBox<String>) pane.lookup("#" + name);
box.setValue(text);
return null;
});
}
private void edit(String button, String expected) throws Exception {
String before = source();
click(pane, button);
await(
() -> {
String now = source();
var msg = fx(() -> ((Label) pane.lookup("#declaration-message")).getText());
if (!msg.isEmpty()) throw new AssertionError(msg);
return !now.equals(before)
&& now.contains(expected)
&& fx(
() ->
((TextArea) pane.lookup("#fxml-source")) == null
|| ((TextArea) pane.lookup("#fxml-source")).getText().equals(now));
});
fx(pane::flush).toCompletableFuture().get();
step(button + " · " + expected);
}
private void set(String field, String value) throws Exception {
combo("declaration-property", field);
fx(
() -> {
((ComboBox<?>) pane.lookup("#declaration-value")).getEditor().setText(value);
return null;
});
edit("Apply setting", field + "=\"" + value + "\"");
}
private void roundtrip(String previous) throws Exception {
String now = source();
click(pane, "Undo");
await(() -> source().equals(previous));
click(pane, "Redo");
await(() -> source().equals(now));
Path path = Path.of(file.getPath());
click(pane, "Save");
await(() -> Files.readString(path).equals(now));
edt(
() -> {
FileEditorManager.getInstance(project).closeFile(file);
return null;
});
open(path);
if (!source().equals(now)) throw new AssertionError("Reopened source differs");
}
private void checkPreviewState() {
var state = (Label) pane.lookup("#preview-state");
if (state != null
&& (state.getText().startsWith("Preview failed")
|| state.getText().startsWith("Preview unavailable")
|| state.getText().startsWith("Preview blocked")))
throw new AssertionError(state.getText());
}
private void preview(String id, boolean build) throws Exception {
step("Preview " + id);
click(pane, "Form preview");
click(pane, build ? "Build and Refresh" : "Preview last successful");
await(
() ->
fx(
() -> {
checkPreviewState();
return !((ComboBox<?>) pane.lookup("#preview-example")).getItems().isEmpty();
}));
fx(
() -> {
((ComboBox<?>) pane.lookup("#preview-example")).getSelectionModel().selectFirst();
((Spinner<?>) pane.lookup("#preview-height")).increment(5);
return null;
});
await(
() ->
fx(
() -> {
checkPreviewState();
var image = (ImageView) pane.lookup("#full-preview-image");
return image != null
&& image.getImage() != null
&& image.getImage().getHeight() == 720;
}));
fx(
() -> {
var image = ((ImageView) pane.lookup("#full-preview-image")).getImage();
ImageIO.write(
SwingFXUtils.fromFXImage(image, null), "png", output.resolve(id + ".png").toFile());
return null;
});
Files.writeString(output.resolve("attempt"), id);
click(pane, "Interactive preview");
await(
() -> {
if (Files.exists(output.resolve("target-error.txt")))
throw new AssertionError(Files.readString(output.resolve("target-error.txt")));
return Files.exists(output.resolve("result-" + id));
});
click(pane, "Stop preview");
step(Files.readString(output.resolve("result-" + id)));
}
private void verify() throws Exception {
Path root = Path.of(project.getBasePath()),
views = root.resolve("src/main/resources/de/neitzel/archiver/ui");
open(root.resolve("src/main/resources/ReferenceWorkspace.fxml"));
inspector(true);
select("DockGroupDefinition", "editors");
select("DockGroupDefinition", "changes");
open(views.resolve("FolderTab.fxml"));
inspector(true);
select("DataGrid", "");
combo("declaration-property", "items");
click(pane, "Edit data binding");
fx(
() -> {
if (!((TextField) pane.lookup("#direct-path")).getText().equals("rows"))
throw new AssertionError("Missing grid.items binding");
return null;
});
inspector(true);
select("DataGrid", "");
combo("declaration-property", "source");
click(pane, "Edit data binding");
fx(
() -> {
if (!((TextField) pane.lookup("#direct-property")).getText().equals("source"))
throw new AssertionError("Missing source binding input");
return null;
});
inspector(true);
select("DataGrid", "");
set("keyAttribute", "path");
set("selectionMode", "SINGLE");
set("pageSize", "25");
set("groupBy", "folder");
select("DataGridColumn", "path");
set("id", "document");
set("header", "Archivdatei");
set("width", "245");
set("kind", "TEXT");
set("filterable", "false");
edit("Later", "Archivdatei");
select("DataGridColumn", "document");
edit("Earlier", "Archivdatei");
edit("Add column", "id=\"column\"");
select("DataGridColumn", "column");
set("attribute", "folder");
set("checklist", "CURRENT_PAGE");
String before = source();
edit("Delete column", "Archivdatei");
roundtrip(before);
preview("folder", true);
open(views.resolve("ArchiveWindow.fxml"));
preview("right", false);
inspector(true);
select("right", "");
combo("dock-area", "bottom");
edit("Move area", "<bottom><DockGroupDefinition");
select("DockGroupDefinition", "details");
set("destinationId", "beleg");
set("visibleWhenEmpty", "true");
select("DockPane", "");
combo("dock-area", "left");
edit("Add area with group", "destinationId=\"left\"");
select("DockGroupDefinition", "messages");
edit("Split branch", "destinationId=\"split\"");
select("DockSplitDefinition", "split");
String horizontal = source();
set("orientation", "VERTICAL");
roundtrip(horizontal);
inspector(true);
select("DockSplitDefinition", "split");
select("DockGroupDefinition", "messages");
select("DockGroupDefinition", "beleg");
inspector(false);
preview("bottom", false);
fx(
() -> {
ImageIO.write(
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
"png",
output.resolve("intellij.png").toFile());
return null;
});
Files.writeString(
output.resolve("SUCCESS.txt"),
"PASS registered IntelliJ DataGrid and Docking inspectors, reference workspace, native"
+ " edits/undo/redo/save/reopen, loaded Archiver rows and stable selection, two sample"
+ " contents moved from right to bottom.\n");
}
}