Author HTML and typed suggestion bindings in the IntelliJ designer
This commit is contained in:
@@ -5,6 +5,7 @@ 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.protocol.BindingMetadata.Target;
|
||||
import java.nio.file.*;
|
||||
import javafx.embed.swing.SwingFXUtils;
|
||||
import javafx.scene.control.*;
|
||||
@@ -48,20 +49,43 @@ public final class SavedDocumentWorkflowProbe extends FormWorkflowProbe {
|
||||
.getText()
|
||||
.contains("no writable JavaFX property")))
|
||||
throw new AssertionError("Static collection was offered as a direct binding target");
|
||||
var current = source();
|
||||
if (source().contains("property=\"suggestionsSource\"")
|
||||
|| source().contains("property=\"html\""))
|
||||
throw new AssertionError("Expected two unbound targets before visual authoring");
|
||||
String current = normalized(source());
|
||||
click(pane, "Save");
|
||||
await(() -> Files.readString(path).equals(current));
|
||||
await(() -> normalized(Files.readString(path)).equals(current));
|
||||
edt(
|
||||
() -> {
|
||||
FileEditorManager.getInstance(project).closeFile(file);
|
||||
return null;
|
||||
});
|
||||
pane = openDesigner(project, file);
|
||||
if (!source().equals(current)) throw new AssertionError("Reopen lost document settings");
|
||||
if (!normalized(source()).equals(current))
|
||||
throw new AssertionError("Reopen lost document settings");
|
||||
step("Edited four media labels, visibility and fixed suggestions; saved and reopened");
|
||||
click(pane, "Form preview");
|
||||
click(pane, "Build and Refresh");
|
||||
await(() -> fx(() -> ((ComboBox<?>) pane.lookup("#preview-example")).getItems().size() == 2));
|
||||
bindFromModel("html", "article", "html");
|
||||
bindFromModel("tags", "dynamic", "suggestionsSource");
|
||||
String bound = normalized(source());
|
||||
click(pane, "Save");
|
||||
await(() -> normalized(Files.readString(path)).equals(bound));
|
||||
edt(
|
||||
() -> {
|
||||
FileEditorManager.getInstance(project).closeFile(file);
|
||||
return null;
|
||||
});
|
||||
pane = openDesigner(project, file);
|
||||
if (!normalized(source()).equals(bound))
|
||||
throw new AssertionError("Reopen lost direct bindings");
|
||||
Files.copy(path, output.resolve("saved-bindings.fxml"));
|
||||
checkSavedBinding("HtmlViewer #article", "html", "html");
|
||||
checkSavedBinding("AutoCompleteTextField #dynamic", "suggestionsSource", "tags");
|
||||
click(pane, "Form preview");
|
||||
click(pane, "Build and Refresh");
|
||||
await(() -> fx(() -> ((ComboBox<?>) pane.lookup("#preview-example")).getItems().size() == 2));
|
||||
choose("preview-example", "saved-invoice");
|
||||
frame("invoice", "Rechnung", 0xff294973);
|
||||
click(pane, "Interactive preview");
|
||||
@@ -83,6 +107,98 @@ public final class SavedDocumentWorkflowProbe extends FormWorkflowProbe {
|
||||
+ " frames, document replacement, error recovery and live suggestion popups.\n");
|
||||
}
|
||||
|
||||
// IntelliJ can strip indentation from empty lines left by element removal on save.
|
||||
private static String normalized(String source) {
|
||||
return source.replaceAll("(?m)^[ \t]+$", "");
|
||||
}
|
||||
|
||||
private void checkSavedBinding(String control, String property, String path) throws Exception {
|
||||
controls(true);
|
||||
choose("form-control", control);
|
||||
choose("form-property", property);
|
||||
click(pane, "Bind property");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((TextField) pane.lookup("#direct-property")).getText().equals(property)
|
||||
&& ((TextField) pane.lookup("#direct-path")).getText().equals(path)
|
||||
&& ((ComboBox<?>) pane.lookup("#direct-direction"))
|
||||
.getValue()
|
||||
.equals("view")));
|
||||
}
|
||||
|
||||
private void bindFromModel(String path, String control, String property) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var group =
|
||||
(TitledPane)
|
||||
pane.lookupAll(".titled-pane").stream()
|
||||
.filter(n -> n instanceof TitledPane t && t.getText().equals("Bindings"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
group.setAnimated(false);
|
||||
group.setExpanded(true);
|
||||
var tabs = (TabPane) group.getContent();
|
||||
tabs.getSelectionModel()
|
||||
.select(
|
||||
tabs.getTabs().stream()
|
||||
.filter(t -> t.getText().equals("Discover targets"))
|
||||
.findFirst()
|
||||
.orElseThrow());
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
return null;
|
||||
});
|
||||
click(pane, "Discover bindings");
|
||||
await(() -> fx(() -> !((ComboBox<?>) pane.lookup("#binding-path")).getItems().isEmpty()));
|
||||
choose("binding-direction", "view");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((ComboBox<?>) pane.lookup("#binding-path"))
|
||||
.getItems().stream().anyMatch(a -> a.toString().startsWith(path + " : "))));
|
||||
choose("binding-path", path + " : ");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
var targets = (TableView<Target>) pane.lookup("#binding-targets");
|
||||
var target =
|
||||
targets.getItems().stream()
|
||||
.filter(
|
||||
t ->
|
||||
t.control().equals(control)
|
||||
&& t.property().equals(property)
|
||||
&& t.status().equals("COMPATIBLE"))
|
||||
.findFirst();
|
||||
if (target.isEmpty()) return false;
|
||||
targets.getSelectionModel().select(target.get());
|
||||
return true;
|
||||
}));
|
||||
click(pane, "Use selected target");
|
||||
if (!fx(
|
||||
() ->
|
||||
((TextField) pane.lookup("#direct-path")).getText().equals(path)
|
||||
&& ((ComboBox<?>) pane.lookup("#direct-direction")).getValue().equals("view")))
|
||||
throw new AssertionError("Wrong source or direction for " + property);
|
||||
fx(
|
||||
() -> {
|
||||
var editor = pane.lookup("#direct-bindings").getParent();
|
||||
ImageIO.write(
|
||||
SwingFXUtils.fromFXImage(editor.snapshot(null, null), null),
|
||||
"png",
|
||||
output.resolve("binding-" + control + ".png").toFile());
|
||||
return null;
|
||||
});
|
||||
click(pane, "Apply binding");
|
||||
await(() -> source().contains("property=\"" + property + "\""));
|
||||
step(
|
||||
"Created " + control + "." + property + " from compatible source " + path + " toward view");
|
||||
}
|
||||
|
||||
private void frame(String id, String title, int accent) throws Exception {
|
||||
await(
|
||||
() ->
|
||||
|
||||
Reference in New Issue
Block a user