Add shared source-preserving Table and Column authoring
This commit is contained in:
@@ -675,6 +675,146 @@ public final class ProjectionHostChecks {
|
||||
await(() -> fx(() -> source(pane).getText().equals(after)));
|
||||
}
|
||||
|
||||
private static void tableField(DesignerPane pane, String field, String value) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
((TextField) pane.lookup("#table-" + field)).setText(value);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private static void tableSelect(DesignerPane pane, String list, int index) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
((ListView<?>) pane.lookup("#table-" + list)).getSelectionModel().select(index);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private static void tableEdits(DesignerPane pane, DocumentSession document, String full)
|
||||
throws Exception {
|
||||
set(document, full);
|
||||
await(() -> fx(() -> source(pane).getText().equals(full)));
|
||||
bindingTab(pane, "Table / Columns");
|
||||
tableSelect(pane, "bindings", 0);
|
||||
tableSelect(pane, "columns", 0);
|
||||
tableField(pane, "header", "Street & address");
|
||||
tableField(pane, "width", "180");
|
||||
check(documentText(document).equals(full), "Table form changed source before Apply");
|
||||
click(pane, "Apply Column");
|
||||
await(() -> !documentText(document).equals(full));
|
||||
String edited = documentText(document);
|
||||
check(
|
||||
edited.contains("header=\"Street & address\"") && edited.contains("width=\"180\""),
|
||||
"Column fields missing");
|
||||
repeatHistory(pane, document, full, edited);
|
||||
// A temporary duplicate is saveable, but cannot start a new preview.
|
||||
tableSelect(pane, "bindings", 0);
|
||||
click(pane, "New Column");
|
||||
tableField(pane, "attribute", "street");
|
||||
tableField(pane, "header", "Second");
|
||||
click(pane, "Apply Column");
|
||||
await(() -> !documentText(document).equals(edited));
|
||||
String duplicate = documentText(document);
|
||||
repeatHistory(pane, document, edited, duplicate);
|
||||
document
|
||||
.save(document.snapshot().toCompletableFuture().get().revision())
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
check(
|
||||
java.nio.file.Files.readString(
|
||||
java.nio.file.Path.of(document.snapshot().toCompletableFuture().get().document()))
|
||||
.equals(duplicate),
|
||||
"Table invalid draft not saved");
|
||||
click(pane, "Render drafts");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
pane.lookupAll(".label").stream()
|
||||
.anyMatch(
|
||||
n ->
|
||||
n instanceof Label l
|
||||
&& l.getText() != null
|
||||
&& l.getText().startsWith("Preview blocked:")
|
||||
&& l.getText().contains("Duplicate Column"))));
|
||||
tableSelect(pane, "bindings", 0);
|
||||
tableSelect(pane, "columns", 1);
|
||||
click(pane, "Column up");
|
||||
await(() -> !documentText(document).equals(duplicate));
|
||||
String moved = documentText(document);
|
||||
repeatHistory(pane, document, duplicate, moved);
|
||||
check(
|
||||
moved.indexOf("header=\"Second\"") < moved.indexOf("header=\"Street & address\""),
|
||||
"Column order not changed");
|
||||
tableSelect(pane, "bindings", 0);
|
||||
tableSelect(pane, "columns", 0);
|
||||
click(pane, "Column down");
|
||||
await(() -> documentText(document).equals(duplicate));
|
||||
repeatHistory(pane, document, moved, duplicate);
|
||||
tableSelect(pane, "bindings", 0);
|
||||
tableSelect(pane, "columns", 1);
|
||||
click(pane, "Remove Column");
|
||||
await(() -> !documentText(document).equals(duplicate));
|
||||
String removed = documentText(document);
|
||||
repeatHistory(pane, document, duplicate, removed);
|
||||
tableSelect(pane, "bindings", 0);
|
||||
tableField(pane, "row", "fixture.components.AddressForm");
|
||||
click(pane, "Apply Table");
|
||||
await(() -> !documentText(document).equals(removed));
|
||||
String configured = documentText(document);
|
||||
repeatHistory(pane, document, removed, configured);
|
||||
tableSelect(pane, "bindings", 0);
|
||||
click(pane, "Remove Table");
|
||||
await(() -> !documentText(document).equals(configured));
|
||||
String noTable = documentText(document);
|
||||
repeatHistory(pane, document, configured, noTable);
|
||||
click(pane, "New Table");
|
||||
tableField(pane, "collection", "visits");
|
||||
tableField(pane, "row", "fixture.components.VisitRow");
|
||||
click(pane, "Apply Table");
|
||||
await(() -> !documentText(document).equals(noTable));
|
||||
String created = documentText(document);
|
||||
repeatHistory(pane, document, noTable, created);
|
||||
tableSelect(pane, "bindings", 0);
|
||||
click(pane, "New Column");
|
||||
tableField(pane, "attribute", "street");
|
||||
tableField(pane, "header", "Street");
|
||||
tableField(pane, "width", "160");
|
||||
click(pane, "Apply Column");
|
||||
await(() -> !documentText(document).equals(created));
|
||||
String valid = documentText(document);
|
||||
repeatHistory(pane, document, created, valid);
|
||||
document
|
||||
.save(document.snapshot().toCompletableFuture().get().revision())
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
check(
|
||||
java.nio.file.Files.readString(
|
||||
java.nio.file.Path.of(document.snapshot().toCompletableFuture().get().document()))
|
||||
.equals(valid),
|
||||
"Table save changed source");
|
||||
click(pane, "Interactive preview");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
pane.lookupAll(".label").stream()
|
||||
.anyMatch(
|
||||
n ->
|
||||
n instanceof Label l
|
||||
&& "Interactive preview running from captured drafts"
|
||||
.equals(l.getText()))));
|
||||
check(pane.interactivePid() > 0, "Table preview worker missing");
|
||||
click(pane, "Stop preview");
|
||||
await(() -> pane.interactivePid() < 0);
|
||||
set(document, full);
|
||||
await(() -> fx(() -> source(pane).getText().equals(full)));
|
||||
System.out.println(
|
||||
"PASS Table/Column inspector: CRUD, reorder, exact undo/redo, invalid save, preview gating"
|
||||
+ " and target load");
|
||||
}
|
||||
|
||||
private static void repeatBindingEdits(DesignerPane pane, DocumentSession document, String full)
|
||||
throws Exception {
|
||||
String base =
|
||||
@@ -1273,6 +1413,7 @@ public final class ProjectionHostChecks {
|
||||
directBindingEdits(pane, document, full);
|
||||
computedBindingEdits(pane, document, full);
|
||||
repeatBindingEdits(pane, document, full);
|
||||
tableEdits(pane, document, full);
|
||||
document
|
||||
.save(document.snapshot().toCompletableFuture().get().revision())
|
||||
.toCompletableFuture()
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package de.neitzel.fxdesigner.kit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import de.neitzel.fxdesigner.contracts.*;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class TableDocumentTest {
|
||||
private static final String START =
|
||||
"<?neitzel-model app.Person?>\r\n"
|
||||
+ "<?import de.neitzel.fx.view.*?><?import javafx.scene.layout.VBox?><VBox"
|
||||
+ " xmlns:f='http://javafx.com/fxml/1'><!-- keep --><Table f:id='t' collection = 'visits'"
|
||||
+ " row='app.Row' custom='keep'><columns><!-- before --><Column header = 'Street'"
|
||||
+ " attribute='street' width='80' custom='keep'/><!-- between --><Column header='Number'"
|
||||
+ " attribute='number'/></columns></Table><Label text='untouched'/></VBox>";
|
||||
|
||||
private String apply(String text, List<EditBatch.Replacement> edits) throws Exception {
|
||||
var result =
|
||||
new EditBatch(1, "Table edit", edits)
|
||||
.applyTo(new DocumentSnapshot(URI.create("file:///view.fxml"), 1, text, true, false));
|
||||
new TableDocument(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
void editsOnlyChangedRangesAndRemovesOptionalWidth() throws Exception {
|
||||
var d = new TableDocument(START);
|
||||
int t = d.tables.getFirst().index();
|
||||
int c = d.columns(t).getFirst().index();
|
||||
assertEquals(
|
||||
START.replace("collection = 'visits'", "collection = 'other'"),
|
||||
apply(START, d.configure(t, "other", "app.Row")));
|
||||
assertTrue(d.configure(t, "visits", "app.Row").isEmpty());
|
||||
var changed = apply(START, d.writeColumn(t, c, "street", "A'&<", ""));
|
||||
assertEquals(
|
||||
START.replace("header = 'Street'", "header = 'A'&<'").replace("width='80'", ""),
|
||||
changed);
|
||||
}
|
||||
|
||||
@Test
|
||||
void reordersExactElementsWithoutMovingCommentsOrRowSource() throws Exception {
|
||||
var d = new TableDocument(START);
|
||||
int t = d.tables.getFirst().index();
|
||||
int c = d.columns(t).getFirst().index();
|
||||
String moved = apply(START, d.moveColumn(t, c, 1));
|
||||
assertTrue(
|
||||
moved.contains(
|
||||
"<!-- before --><Column header='Number' attribute='number'/><!-- between --><Column"
|
||||
+ " header = 'Street' attribute='street' width='80' custom='keep'/>"));
|
||||
var next = new TableDocument(moved);
|
||||
assertEquals(START, apply(moved, next.moveColumn(t, next.columns(t).getFirst().index(), 1)));
|
||||
assertTrue(d.moveColumn(t, c, -1).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createsAndRemovesTablesAndColumnsInSupportedContainers() throws Exception {
|
||||
for (String root :
|
||||
List.of(
|
||||
"<VBox/>",
|
||||
"<VBox><children/></VBox>",
|
||||
"<VBox><children><!--keep--></children></VBox>")) {
|
||||
var d = new TableDocument(root);
|
||||
String created = apply(root, d.create("visits", "app.Row"));
|
||||
var n = new TableDocument(created);
|
||||
int t = n.tables.getFirst().index();
|
||||
String withColumn = apply(created, n.writeColumn(t, null, "street", "Street", "120"));
|
||||
var c = new TableDocument(withColumn);
|
||||
assertTrue(c.errors().isEmpty());
|
||||
assertTrue(apply(withColumn, c.removeTable(t)).contains("VBox"));
|
||||
String removed = apply(withColumn, c.removeColumn(t, c.columns(t).getFirst().index()));
|
||||
assertTrue(
|
||||
new TableDocument(removed).errors().stream().anyMatch(e -> e.contains("at least one")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void preservesNestedDeclarationsAndRejectsAmbiguousContainers() throws Exception {
|
||||
String text =
|
||||
START.replace("width='80' custom='keep'/>", "width='80'><header>Nested</header></Column>");
|
||||
var d = new TableDocument(text);
|
||||
int t = d.tables.getFirst().index();
|
||||
assertFalse(d.columns(t).getFirst().editable());
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> d.writeColumn(t, d.columns(t).getFirst().index(), "street", "X", ""));
|
||||
var mixed =
|
||||
new TableDocument(
|
||||
START.replace("<columns>", "<Column header='Other' attribute='other'/><columns>"));
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> mixed.columns(mixed.tables.getFirst().index()));
|
||||
var root = new TableDocument("<de.neitzel.fx.view.Table collection='visits' row='app.Row'/>");
|
||||
assertThrows(IllegalArgumentException.class, () -> root.removeTable(0));
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new TableDocument("<Label/>").create("visits", "app.Row"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void diagnosesInvalidDeclarationsWithoutPreventingEdits() throws Exception {
|
||||
for (String width : List.of("0", "-2", "NaN", "Infinity", "oops")) {
|
||||
var d = new TableDocument(START);
|
||||
int t = d.tables.getFirst().index();
|
||||
var changed =
|
||||
new TableDocument(
|
||||
apply(START, d.writeColumn(t, d.columns(t).getFirst().index(), "number", "", width)));
|
||||
assertTrue(changed.errors().stream().anyMatch(e -> e.contains("Duplicate")));
|
||||
assertTrue(changed.errors().stream().anyMatch(e -> e.contains("positive and finite")));
|
||||
assertTrue(changed.errors().stream().anyMatch(e -> e.contains("header")));
|
||||
}
|
||||
var invalid =
|
||||
new TableDocument(START.replace("collection = 'visits'", "collection='invalid path'"));
|
||||
assertFalse(invalid.errors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void ignoresUnrelatedImportedNames() throws Exception {
|
||||
assertTrue(new TableDocument("<?import app.Table?><VBox><Table/></VBox>").tables.isEmpty());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user