Edit single content slots, tab and split layouts, and grid setup declarations

This commit is contained in:
2026-11-25 09:40:39 +01:00
parent 95d26eb88b
commit dc3dd6b6be
12 changed files with 970 additions and 20 deletions
@@ -0,0 +1,336 @@
package qualification;
import static qualification.WorkflowProbe.*;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
import de.neitzel.fxdesigner.workflow.DesignerWorkflow.Example;
import java.nio.file.*;
import java.util.*;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javax.imageio.ImageIO;
import org.w3c.dom.Element;
/** Edits original Archiver forms in the registered IntelliJ designer. */
public final class MediaLayoutGridWorkflowProbe extends FormWorkflowProbe {
private Project project;
void verify(Project project) throws Exception {
this.project = project;
open("HtmlDocument");
controls(true);
choose("form-control", "HtmlViewer #article");
set("mediaLoadText", "Belegbilder laden", "mediaLoadText=\"Belegbilder laden\"");
reopen("HtmlDocument", "Belegbilder laden");
build("html-invoice");
interactive("html-invoice", "offline");
details();
trash();
window();
folder();
Files.writeString(output.resolve("SUCCESS.txt"), Files.readString(output.resolve("steps.txt")));
}
private void insert(String type, String slot, int position, String id) throws Exception {
choose("form-palette", type);
choose("form-destination", slot);
if (position >= 0)
fx(
() -> {
((Spinner<Integer>) pane.lookup("#form-position")).getValueFactory().setValue(position);
return null;
});
String before = source();
click(pane, "Insert control");
edited(before, "fx:id=\"" + id + "\"");
}
private void reject(String type, String slot, String reason) throws Exception {
choose("form-palette", type);
choose("form-destination", slot);
String before = source();
click(pane, "Insert control");
if (!before.equals(source())
|| !fx(() -> ((Label) pane.lookup("#form-message")).getText()).contains(reason))
throw new AssertionError("Expected " + reason);
}
private void history(String before, String after) throws Exception {
click(pane, "Undo");
await(() -> source().equals(before));
click(pane, "Redo");
await(() -> source().equals(after));
fx(pane::flush).toCompletableFuture().get();
}
private List<String> declarations() throws Exception {
return source()
.lines()
.map(String::trim)
.filter(
l ->
l.startsWith("<DirectBinding ")
|| l.startsWith("<CommandBinding ")
|| l.startsWith("<Repeat "))
.toList();
}
private void details() throws Exception {
open("DocumentDetails");
controls(true);
var original = declarations();
reject("Label", "TabPane [", "TabPane.tabs accepts Tab");
reject("Label", "ScrollPane [", "Occupied");
insert("Tab", "TabPane [", -1, "tab");
choose("form-control", "Tab #tab");
set("text", "Belegprüfung", "text=\"Belegprüfung\"");
insert("ScrollPane", "Tab #tab / content", 0, "scrollPane");
choose("form-control", "HBox [");
choose("form-destination", "ScrollPane #scrollPane / content");
String before = source();
click(pane, "Move to destination");
edited(before, "onAction=\"#addTag\"");
history(before, source());
reopen("DocumentDetails", "Belegprüfung");
if (!original.equals(declarations())) throw new AssertionError("Moved bindings");
build("details-invoice");
interactive("details-invoice", "details");
}
private void trash() throws Exception {
open("TrashPane");
controls(true);
insert("Label", "SplitPane [", 1, "label");
choose("form-control", "Label #label");
set("text", "Dateien der Auswahl", "text=\"Dateien der Auswahl\"");
reopen("TrashPane", "Dateien der Auswahl");
build("trash-full");
interactive("trash-full", "trash");
}
private void window() throws Exception {
open("ArchiveWindow");
controls(true);
String left =
fx(
() ->
((ComboBox<?>) pane.lookup("#form-destination"))
.getItems().stream()
.map(Object::toString)
.filter(v -> v.startsWith("BorderPane [") && v.endsWith(" / left"))
.findFirst()
.orElseThrow());
String owner = left.substring(0, left.lastIndexOf(" / "));
for (String region : List.of("center", "top", "bottom", "left", "right")) {
choose("form-destination", owner + " / " + region);
}
reject("Label", owner + " / center", "Occupied");
insert("Label", left, 0, "label");
choose("form-control", "Label #label");
set("text", "Medienprüfung", "text=\"Medienprüfung\"");
reopen("ArchiveWindow", "Medienprüfung");
build("archive-window-media");
interactive("archive-window-media", "media");
}
private void folder() throws Exception {
open("FolderTab");
inspector(true);
var original = declarations();
select("DataGrid", "grid");
gridSet("setupId", "archiver-pruefung");
gridSet("setupVersion", "2");
for (var pair :
List.of(List.of("setupId", "archiver-pruefung"), List.of("setupVersion", "2"))) {
String before = source();
combo("declaration-property", pair.getFirst());
fx(
() -> {
((ComboBox<?>) pane.lookup("#declaration-value")).getEditor().clear();
return null;
});
click(pane, "Apply setting");
await(() -> !source().contains(pair.getFirst() + "=\""));
click(pane, "Undo");
await(() -> source().equals(before));
}
gridSet("groupBy", "folder");
select("DataGridColumn", "folder");
gridSet("fixedPosition", "1");
combo("declaration-property", "groupLabels");
fx(
() -> {
((ComboBox<?>) pane.lookup("#group-label-key")).getEditor().setText("Post");
((TextField) pane.lookup("#group-label-text")).setText("Posteingang");
return null;
});
String before = source();
edit("Set group label", "Post=\"Posteingang\"");
String grouped = source();
history(before, grouped);
combo("declaration-property", "groupLabels");
choose("group-label-key", "Post");
click(pane, "Remove group label");
await(() -> !source().contains("Post=\"Posteingang\""));
click(pane, "Undo");
await(() -> source().equals(grouped));
reopen("FolderTab", "Posteingang");
if (!original.equals(declarations())) throw new AssertionError("Grid bindings");
inspector(true);
select("DataGridColumn", "folder");
combo("declaration-property", "groupLabels");
if (!fx(() -> ((TextField) pane.lookup("#group-label-text")).getText().equals("Posteingang")))
throw new AssertionError("Reopened mapping");
fx(
() -> {
ImageIO.write(
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
"png",
output.resolve("intellij.png").toFile());
return null;
});
build("archive-folder");
interactive("archive-folder", "grid");
}
private void open(String name) throws Exception {
var path =
Path.of(project.getBasePath(), "src/main/resources/de/neitzel/archiver/ui", name + ".fxml");
file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path));
pane = openDesigner(project, file);
if (!source().contains("<?neitzel-model de.neitzel.archiver.ui."))
throw new AssertionError(name);
}
private void build(String id) throws Exception {
click(pane, "Form preview");
click(pane, "Build and Refresh");
await(
() ->
fx(
() ->
((ComboBox<?>) pane.lookup("#preview-example"))
.getItems().stream().anyMatch(item -> item.toString().contains(id))));
}
private void interactive(String id, String attempt) throws Exception {
choose("preview-example", id);
await(
() ->
fx(
() -> {
var state = ((Label) pane.lookup("#preview-state")).getText();
if (state.startsWith("Preview failed")
|| state.startsWith("Preview blocked")
|| state.startsWith("Preview unavailable"))
throw new AssertionError(id + " · " + state);
var choice = (Example) ((ComboBox<?>) pane.lookup("#preview-example")).getValue();
return ((ImageView) pane.lookup("#full-preview-image")).getImage() != null
&& state.contains(choice.label());
}));
Files.writeString(output.resolve("layout-case"), attempt);
click(pane, "Interactive preview");
String name = "result-" + attempt;
awaitTarget(name);
step(id + " · " + Files.readString(output.resolve(name)));
click(pane, "Stop preview");
}
private void reopen(String form, String saved) throws Exception {
click(pane, "Save");
await(() -> Files.readString(Path.of(file.getPath())).contains(saved));
edt(
() -> {
FileEditorManager.getInstance(project).closeFile(file);
return null;
});
open(form);
if (!source().contains(saved)) throw new AssertionError("Reopened " + form);
}
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("fx:id").equals(id)
|| 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 gridSet(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 + "\"");
}
}