Edit form controls and render localized application previews in the IntelliJ designer
This commit is contained in:
@@ -0,0 +1,348 @@
|
||||
package qualification;
|
||||
|
||||
import static qualification.WorkflowProbe.*;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
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;
|
||||
|
||||
/** Drives the registered editor against a disposable copy of the real Archiver form. */
|
||||
public final class ConnectionWorkflowProbe implements StartupActivity.DumbAware {
|
||||
private DesignerPane pane;
|
||||
private VirtualFile file;
|
||||
|
||||
public void runActivity(Project project) {
|
||||
if (!started.compareAndSet(false, true)) return;
|
||||
ApplicationManager.getApplication()
|
||||
.executeOnPooledThread(
|
||||
() -> {
|
||||
try {
|
||||
verify(project);
|
||||
} 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 -> Objects.toString(((Label) n).getText(), ""))
|
||||
.filter(s -> !s.isEmpty())
|
||||
.toList()
|
||||
.toString()));
|
||||
Files.writeString(output.resolve("FAILURE.txt"), trace.toString());
|
||||
} catch (Exception failure) {
|
||||
failure.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void step(String message) throws Exception {
|
||||
Files.writeString(
|
||||
output.resolve("steps.txt"),
|
||||
message + "\n",
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.APPEND);
|
||||
}
|
||||
|
||||
private String source() throws Exception {
|
||||
return edt(() -> FileDocumentManager.getInstance().getDocument(file).getText());
|
||||
}
|
||||
|
||||
private void controls(boolean expanded) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var panel =
|
||||
(TitledPane)
|
||||
pane.lookupAll(".titled-pane").stream()
|
||||
.filter(n -> n instanceof TitledPane t && t.getText().equals("Form controls"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
panel.setAnimated(false);
|
||||
panel.setExpanded(expanded);
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void choose(String selector, String text) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var combo = (ComboBox<?>) pane.lookup("#" + selector);
|
||||
for (int i = 0; i < combo.getItems().size(); i++) {
|
||||
if (combo.getItems().get(i).toString().equals(text)) {
|
||||
combo.getSelectionModel().select(i);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < combo.getItems().size(); i++) {
|
||||
String label = combo.getItems().get(i).toString();
|
||||
if (label.equals(text) || label.contains(text)) {
|
||||
combo.getSelectionModel().select(i);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
throw new AssertionError(selector + " missing " + text + " in " + combo.getItems());
|
||||
});
|
||||
}
|
||||
|
||||
private void edited(String before, String expected) throws Exception {
|
||||
await(
|
||||
() -> {
|
||||
String now = source();
|
||||
String error =
|
||||
fx(
|
||||
() -> {
|
||||
var label = (Label) pane.lookup("#form-message");
|
||||
return label == null ? "" : label.getText();
|
||||
});
|
||||
if (!error.isEmpty()) throw new AssertionError(error);
|
||||
return !before.equals(now)
|
||||
&& now.contains(expected)
|
||||
&& fx(
|
||||
() ->
|
||||
((TextArea) pane.lookup("#fxml-source")) == null
|
||||
|| ((TextArea) pane.lookup("#fxml-source")).getText().equals(now));
|
||||
});
|
||||
// Both the native document and visual selection are refreshed asynchronously.
|
||||
fx(pane::flush).toCompletableFuture().get(10, java.util.concurrent.TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void add(String type, String destination, String id) throws Exception {
|
||||
step("Inserting " + type + " as " + id);
|
||||
choose("form-palette", type);
|
||||
choose("form-destination", destination);
|
||||
String before = source();
|
||||
click(pane, "Insert control");
|
||||
edited(before, "fx:id=\"" + id + "\"");
|
||||
step("Inserted " + type + " into " + destination);
|
||||
}
|
||||
|
||||
private void set(String name, String value, String expected) throws Exception {
|
||||
choose("form-property", name);
|
||||
fx(
|
||||
() -> {
|
||||
((TextArea) pane.lookup("#form-value")).setText(value);
|
||||
return null;
|
||||
});
|
||||
String before = source();
|
||||
click(pane, "Set property");
|
||||
edited(before, expected);
|
||||
}
|
||||
|
||||
private void bind(String name, String path) throws Exception {
|
||||
choose("form-property", name);
|
||||
click(pane, "Bind property");
|
||||
fx(
|
||||
() -> {
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
return null;
|
||||
});
|
||||
fx(
|
||||
() -> {
|
||||
((TextField) pane.lookup("#direct-path")).setText(path);
|
||||
return null;
|
||||
});
|
||||
String before = source();
|
||||
click(pane, "Apply binding");
|
||||
edited(before, "path=\"" + path + "\"");
|
||||
controls(true);
|
||||
}
|
||||
|
||||
private void example(String id) throws Exception {
|
||||
choose("preview-example", "connection-" + id);
|
||||
}
|
||||
|
||||
private void frame(String id, int width) throws Exception {
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() -> {
|
||||
var image = (ImageView) pane.lookup("#full-preview-image");
|
||||
var status = ((Label) pane.lookup("#preview-state")).getText();
|
||||
return image.getImage() != null
|
||||
&& image.getImage().getWidth() == width
|
||||
&& image.getImage().getHeight() == 720
|
||||
&& status.contains(id.toUpperCase(Locale.ROOT));
|
||||
}));
|
||||
fx(
|
||||
() -> {
|
||||
ImageIO.write(
|
||||
SwingFXUtils.fromFXImage(
|
||||
((ImageView) pane.lookup("#full-preview-image")).getImage(), null),
|
||||
"png",
|
||||
output.resolve(id + ".png").toFile());
|
||||
return null;
|
||||
});
|
||||
step("In-editor " + id + " target frame " + width + " × 720");
|
||||
}
|
||||
|
||||
private void awaitTarget(String name) throws Exception {
|
||||
await(
|
||||
() -> {
|
||||
var error = output.resolve("target-error.txt");
|
||||
if (Files.exists(error)) throw new AssertionError(Files.readString(error));
|
||||
return Files.exists(output.resolve(name));
|
||||
});
|
||||
}
|
||||
|
||||
private void verify(Project project) throws Exception {
|
||||
var path =
|
||||
Path.of(
|
||||
project.getBasePath(), "src/main/resources/de/neitzel/archiver/ui/ConnectionForm.fxml");
|
||||
file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path));
|
||||
pane = openDesigner(project, file);
|
||||
step("Opened registered Neitzel Designer");
|
||||
controls(true);
|
||||
String grid = "GridPane [0] / children";
|
||||
add("StatusBar", grid, "statusBar");
|
||||
add("Label", "StatusBar #statusBar / leftItems", "label");
|
||||
bind("text", "user");
|
||||
add("Label", "StatusBar #statusBar / rightItems", "label2");
|
||||
set("text", "Kontostatus", "Kontostatus");
|
||||
choose("form-destination", "StatusBar #statusBar / leftItems");
|
||||
String before = source();
|
||||
click(pane, "Move to destination");
|
||||
edited(before, "Kontostatus");
|
||||
String moved = source();
|
||||
click(pane, "Undo");
|
||||
await(() -> source().equals(before));
|
||||
click(pane, "Redo");
|
||||
await(() -> source().equals(moved));
|
||||
add("TextField", grid, "textField");
|
||||
fx(
|
||||
() -> {
|
||||
var index =
|
||||
new com.oracle.javafx.scenebuilder.kit.fxom.FXOMFxIdIndex(
|
||||
pane.kit().editor().getFxomDocument());
|
||||
pane.kit().editor().getSelection().select(index.lookup("endpoint"));
|
||||
pane.kit().editor().getSelection().select(index.lookup("textField"));
|
||||
if (!((ComboBox<?>) pane.lookup("#form-control"))
|
||||
.getValue()
|
||||
.toString()
|
||||
.equals("TextField #textField"))
|
||||
throw new AssertionError("Canvas selection did not reach the form inspector");
|
||||
return null;
|
||||
});
|
||||
set("promptText", "Verbindung prüfen", "Verbindung prüfen");
|
||||
set("styleClass", "connection-input", "connection-input");
|
||||
set("padding", "2 3 4 5", "right=\"3.0\"");
|
||||
set("GridPane.columnIndex", "1", "GridPane.columnIndex=\"1\"");
|
||||
add("NonNegativeIntegerSpinner", grid, "nonNegativeIntegerSpinner");
|
||||
set("maximum", "365", "maximum=\"365\"");
|
||||
set("initialValue", "14", "initialValue=\"14\"");
|
||||
set("minimum", "1", "minimum=\"1\"");
|
||||
add("TagChip", grid, "tagChip");
|
||||
set("removable", "true", "removable=\"true\"");
|
||||
set("onRemove", "#removeTag", "onRemove=\"#removeTag\"");
|
||||
click(pane, "Reset property");
|
||||
await(() -> !source().contains("onRemove="));
|
||||
add("ToolBarPane", grid, "toolBarPane");
|
||||
set("dismissible", "true", "dismissible=\"true\"");
|
||||
set("dismissText", "Schließen", "dismissText=\"Schließen\"");
|
||||
set("onDismiss", "#dismiss", "onDismiss=\"#dismiss\"");
|
||||
click(pane, "Reset property");
|
||||
await(() -> !source().contains("onDismiss="));
|
||||
add("ToolBar", grid, "toolBar");
|
||||
add("Button", "ToolBarPane #toolBarPane / items", "button");
|
||||
choose("form-destination", "ToolBar #toolBar / items");
|
||||
String toolbar = source();
|
||||
click(pane, "Move to destination");
|
||||
edited(toolbar, "fx:id=\"button\"");
|
||||
add("AutoCompleteTextField", grid, "autoCompleteTextField");
|
||||
set("suggestions", "INBOX\nRechnungen", "fx:value=\"Rechnungen\"");
|
||||
bind("text", "user");
|
||||
String edited = source();
|
||||
click(pane, "Save");
|
||||
await(() -> Files.readString(path).equals(edited));
|
||||
if (!edited.contains("%server.protocol"))
|
||||
throw new AssertionError("Resource key was overwritten");
|
||||
edt(
|
||||
() -> {
|
||||
FileEditorManager.getInstance(project).closeFile(file);
|
||||
return null;
|
||||
});
|
||||
pane = openDesigner(project, file);
|
||||
if (!source().equals(edited)) throw new AssertionError("Reopen changed source");
|
||||
step("Native undo, redo, save and reopen preserved form, lists and bindings");
|
||||
click(pane, "Form preview");
|
||||
click(pane, "Build and Refresh");
|
||||
await(() -> fx(() -> ((ComboBox<?>) pane.lookup("#preview-example")).getItems().size() == 2));
|
||||
step("Built and discovered both connection examples");
|
||||
example("imap");
|
||||
fx(
|
||||
() -> {
|
||||
((Spinner<?>) pane.lookup("#preview-height")).increment(5);
|
||||
return null;
|
||||
});
|
||||
frame("imap", 760);
|
||||
byte[] initialImage = Files.readAllBytes(output.resolve("imap.png"));
|
||||
controls(true);
|
||||
choose("form-control", "Label #label2");
|
||||
set("text", "Kontoprüfung", "Kontoprüfung");
|
||||
controls(false);
|
||||
frame("imap", 760);
|
||||
if (java.util.Arrays.equals(initialImage, Files.readAllBytes(output.resolve("imap.png"))))
|
||||
throw new AssertionError("Visual label edit produced the previous frame");
|
||||
step("Current draft rendered a changed status label without a Save action");
|
||||
Files.writeString(output.resolve("attempt"), "imap");
|
||||
click(pane, "Interactive preview");
|
||||
awaitTarget("result-imap");
|
||||
var otherPath = path.resolveSibling("ArchiveWindow.fxml");
|
||||
var other = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(otherPath));
|
||||
edt(
|
||||
() -> {
|
||||
FileEditorManager.getInstance(project).openFile(other, false);
|
||||
var doc = FileDocumentManager.getInstance().getDocument(other);
|
||||
WriteCommandAction.runWriteCommandAction(
|
||||
project, () -> doc.insertString(doc.getTextLength(), "\n"));
|
||||
FileDocumentManager.getInstance().saveDocument(doc);
|
||||
return null;
|
||||
});
|
||||
Files.writeString(output.resolve("unrelated-saved"), "yes");
|
||||
awaitTarget("retained-imap");
|
||||
long originalPid = Long.parseLong(Files.readString(output.resolve("retained-imap")));
|
||||
if (!ProcessHandle.of(originalPid).map(ProcessHandle::isAlive).orElse(false))
|
||||
throw new AssertionError("Saving a different view stopped the IMAP worker");
|
||||
step("Interactive IMAP input reached bound Label and survived unrelated save");
|
||||
Files.writeString(output.resolve("attempt"), "jmap");
|
||||
example("jmap");
|
||||
fx(
|
||||
() -> {
|
||||
((Spinner<?>) pane.lookup("#preview-width")).increment();
|
||||
return null;
|
||||
});
|
||||
frame("jmap", 800);
|
||||
awaitTarget("result-jmap");
|
||||
step("Interactive JMAP started with fresh sample data and reversed account/port enablement");
|
||||
fx(
|
||||
() -> {
|
||||
ImageIO.write(
|
||||
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
|
||||
"png",
|
||||
output.resolve("intellij.png").toFile());
|
||||
return null;
|
||||
});
|
||||
click(pane, "Stop preview");
|
||||
Files.writeString(
|
||||
output.resolve("SUCCESS.txt"),
|
||||
"PASS registered IntelliJ connection form, palette and inspector edits, named lists,"
|
||||
+ " bindings, native undo/redo/reopen, localized IMAP/JMAP frames and interactive"
|
||||
+ " write-back\n");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user