Edit DataGrid columns and dock layout declarations in the designer
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user