Start working on active tables, fix testing bug

This commit is contained in:
Grahame Grieve 2019-12-14 07:54:48 +11:00
parent a09da2eb2c
commit 415193a792
7 changed files with 67 additions and 42 deletions

View File

@ -1155,7 +1155,7 @@ public class ProfileUtilities {
public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, ed.getId());
boolean deep = false;
boolean vdeep = false;
@ -1419,7 +1419,7 @@ public class ProfileUtilities {
public XhtmlNode generateTable(String defFile, StructureDefinition profile, boolean diff, String imageFolder, boolean inlineGraphics, String profileBaseFileName, boolean snapshot, String corePath, Set<String> outputTracker) throws IOException, FHIRException {
assert(diff != snapshot);// check it's ok to get rid of one of these
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, profile.getId()+(diff ? "d" : "s"));
List<ElementDefinition> list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement();
List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
profiles.add(profile);

View File

@ -1156,7 +1156,7 @@ public class ProfileUtilities {
public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, ed.getId());
boolean deep = false;
boolean vdeep = false;
@ -1418,7 +1418,7 @@ public class ProfileUtilities {
public XhtmlNode generateTable(String defFile, StructureDefinition profile, boolean diff, String imageFolder, boolean inlineGraphics, String profileBaseFileName, boolean snapshot, String corePath, boolean logicalModel, Set<String> outputTracker) throws IOException, FHIRException {
assert(diff != snapshot);// check it's ok to get rid of one of these
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, profile.getId()+(diff ? "d" : "s"));
List<ElementDefinition> list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement();
List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
profiles.add(profile);

View File

@ -1593,7 +1593,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, String imagePath, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
gen.setTranslator(getTranslator());
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, ed.getId());
boolean deep = false;
String m = "";
@ -1962,7 +1962,7 @@ public class ProfileUtilities extends TranslatingUtilities {
assert(diff != snapshot);// check it's ok to get rid of one of these
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
gen.setTranslator(getTranslator());
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, profile.getId()+(diff ? "d" : "s"));
List<ElementDefinition> list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement();
List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
profiles.add(profile);
@ -1978,7 +1978,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public XhtmlNode generateGrid(String defFile, StructureDefinition profile, String imageFolder, boolean inlineGraphics, String profileBaseFileName, String corePath, String imagePath, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
gen.setTranslator(getTranslator());
TableModel model = gen.initGridTable(corePath);
TableModel model = gen.initGridTable(corePath, profile.getId());
List<ElementDefinition> list = profile.getSnapshot().getElement();
List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
profiles.add(profile);
@ -3455,7 +3455,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public XhtmlNode generateSpanningTable(StructureDefinition profile, String imageFolder, boolean onlyConstraints, String constraintPrefix, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, false);
gen.setTranslator(getTranslator());
TableModel model = initSpanningTable(gen, "", false);
TableModel model = initSpanningTable(gen, "", false, profile.getId());
Set<String> processed = new HashSet<String>();
SpanEntry span = buildSpanningTable("(focus)", "", profile, processed, onlyConstraints, constraintPrefix);
@ -3607,8 +3607,8 @@ public class ProfileUtilities extends TranslatingUtilities {
}
public TableModel initSpanningTable(HierarchicalTableGenerator gen, String prefix, boolean isLogical) {
TableModel model = gen.new TableModel();
public TableModel initSpanningTable(HierarchicalTableGenerator gen, String prefix, boolean isLogical, String id) {
TableModel model = gen.new TableModel(id);
model.setDocoImg(prefix+"help16.png");
model.setDocoRef(prefix+"formats.html#table"); // todo: change to graph definition

View File

@ -2120,7 +2120,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, String imagePath, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics, true);
gen.setTranslator(getTranslator());
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, ed.getId());
boolean deep = false;
String m = "";
@ -2490,7 +2490,7 @@ public class ProfileUtilities extends TranslatingUtilities {
assert(diff != snapshot);// check it's ok to get rid of one of these
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics, true);
gen.setTranslator(getTranslator());
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, profile.getId()+(diff ? "d" : "s"));
List<ElementDefinition> list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement();
List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
profiles.add(profile);
@ -2511,7 +2511,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public XhtmlNode generateGrid(String defFile, StructureDefinition profile, String imageFolder, boolean inlineGraphics, String profileBaseFileName, String corePath, String imagePath, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics, true);
gen.setTranslator(getTranslator());
TableModel model = gen.initGridTable(corePath);
TableModel model = gen.initGridTable(corePath, profile.getId());
List<ElementDefinition> list = profile.getSnapshot().getElement();
List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
profiles.add(profile);
@ -4441,7 +4441,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public XhtmlNode generateSpanningTable(StructureDefinition profile, String imageFolder, boolean onlyConstraints, String constraintPrefix, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, false, true);
gen.setTranslator(getTranslator());
TableModel model = initSpanningTable(gen, "", false);
TableModel model = initSpanningTable(gen, "", false, profile.getId());
Set<String> processed = new HashSet<String>();
SpanEntry span = buildSpanningTable("(focus)", "", profile, processed, onlyConstraints, constraintPrefix);
@ -4594,8 +4594,8 @@ public class ProfileUtilities extends TranslatingUtilities {
}
public TableModel initSpanningTable(HierarchicalTableGenerator gen, String prefix, boolean isLogical) {
TableModel model = gen.new TableModel();
public TableModel initSpanningTable(HierarchicalTableGenerator gen, String prefix, boolean isLogical, String id) {
TableModel model = gen.new TableModel(id);
model.setDocoImg(prefix+"help16.png");
model.setDocoRef(prefix+"formats.html#table"); // todo: change to graph definition

View File

@ -2467,7 +2467,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, String imagePath, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics, true);
gen.setTranslator(getTranslator());
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, ed.getId());
boolean deep = false;
String m = "";
@ -2597,7 +2597,7 @@ public class ProfileUtilities extends TranslatingUtilities {
StructureDefinition bsd = context.fetchResource(StructureDefinition.class, profile.getBaseDefinition());
if (bsd != null) {
if (bsd.hasUserData("path")) {
c.getPieces().add(gen.new Piece(bsd.getUserString("path"), bsd.getName(), null));
c.getPieces().add(gen.new Piece(Utilities.isAbsoluteUrl(bsd.getUserString("path")) ? bsd.getUserString("path") : corePath +bsd.getUserString("path"), bsd.getName(), null));
} else {
c.getPieces().add(gen.new Piece(null, bsd.getName(), null));
}
@ -2848,7 +2848,7 @@ public class ProfileUtilities extends TranslatingUtilities {
assert(diff != snapshot);// check it's ok to get rid of one of these
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics, true);
gen.setTranslator(getTranslator());
TableModel model = gen.initNormalTable(corePath, false, true);
TableModel model = gen.initNormalTable(corePath, false, true, profile.getId()+(diff ? "d" : "s"));
List<ElementDefinition> list = new ArrayList<>();
if (diff)
list.addAll(profile.getDifferential().getElement());
@ -2921,7 +2921,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public XhtmlNode generateGrid(String defFile, StructureDefinition profile, String imageFolder, boolean inlineGraphics, String profileBaseFileName, String corePath, String imagePath, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics, true);
gen.setTranslator(getTranslator());
TableModel model = gen.initGridTable(corePath);
TableModel model = gen.initGridTable(corePath, profile.getId());
List<ElementDefinition> list = profile.getSnapshot().getElement();
List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
profiles.add(profile);
@ -4925,7 +4925,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public XhtmlNode generateSpanningTable(StructureDefinition profile, String imageFolder, boolean onlyConstraints, String constraintPrefix, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, false, true);
gen.setTranslator(getTranslator());
TableModel model = initSpanningTable(gen, "", false);
TableModel model = initSpanningTable(gen, "", false, profile.getId());
Set<String> processed = new HashSet<String>();
SpanEntry span = buildSpanningTable("(focus)", "", profile, processed, onlyConstraints, constraintPrefix);
@ -5078,8 +5078,8 @@ public class ProfileUtilities extends TranslatingUtilities {
}
public TableModel initSpanningTable(HierarchicalTableGenerator gen, String prefix, boolean isLogical) {
TableModel model = gen.new TableModel();
public TableModel initSpanningTable(HierarchicalTableGenerator gen, String prefix, boolean isLogical, String id) {
TableModel model = gen.new TableModel(id);
model.setDocoImg(prefix+"help16.png");
model.setDocoRef(prefix+"formats.html#table"); // todo: change to graph definition

View File

@ -175,9 +175,9 @@ public class SnapShotGenerationTests {
if (!Utilities.noString(include))
included = (StructureDefinition) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", include+".xml"));
if (!Utilities.noString(register)) {
try {
if (TestingUtilities.findTestResource("r5", "snapshot-generation", register+".xml")) {
included = (StructureDefinition) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", register+".xml"));
} catch (Exception e) {
} else {
included = (StructureDefinition) new JsonParser().parse(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", register+".json"));
}
}

View File

@ -98,6 +98,7 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
public static final int NEW_SLICE = 4;
public static final int CONTINUE_SLICE = 5;
private static final String BACKGROUND_ALT_COLOR = "#F7F7F7";
private static final boolean ACTIVE_TABLE = false;
private static Map<String, String> files = new HashMap<String, String>();
@ -377,6 +378,7 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
private String hint;
private String color;
private int lineColor;
private String id;
public List<Row> getSubRows() {
return subRows;
@ -414,16 +416,26 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
assert lineColor <= 2;
this.lineColor = lineColor;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
public class TableModel {
private String id;
private List<Title> titles = new ArrayList<HierarchicalTableGenerator.Title>();
private List<Row> rows = new ArrayList<HierarchicalTableGenerator.Row>();
private String docoRef;
private String docoImg;
private boolean alternating;
public TableModel(String id) {
super();
this.id = id;
}
public List<Title> getTitles() {
return titles;
}
@ -442,6 +454,9 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
public void setDocoImg(String docoImg) {
this.docoImg = docoImg;
}
public String getId() {
return id;
}
}
@ -476,8 +491,8 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
this.makeTargets = makeTargets;
}
public TableModel initNormalTable(String prefix, boolean isLogical, boolean alternating) {
TableModel model = new TableModel();
public TableModel initNormalTable(String prefix, boolean isLogical, boolean alternating, String id) {
TableModel model = new TableModel(id);
model.alternating = alternating;
model.setDocoImg(prefix+"help16.png");
@ -494,8 +509,8 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
}
public TableModel initGridTable(String prefix) {
TableModel model = new TableModel();
public TableModel initGridTable(String prefix, String id) {
TableModel model = new TableModel(id);
model.getTitles().add(new Title(null, model.getDocoRef(), translate("sd.head", "Name"), translate("sd.hint", "The name of the element (Slice name in brackets). Mouse-over provides definition"), null, 0));
model.getTitles().add(new Title(null, model.getDocoRef(), translate("sd.head", "Card."), translate("sd.hint", "Minimum and Maximum # of times the the element can appear in the instance. Super-scripts indicate additional constraints on appearance"), null, 0));
@ -548,6 +563,7 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
color = BACKGROUND_ALT_COLOR;
tr.setAttribute("style", "border: " + border + "px #F0F0F0 solid; padding:0px; vertical-align: top; background-color: "+color+";");
tr.setAttribute("id", model.getId()+r.getId());
boolean first = true;
for (Cell t : r.getCells()) {
renderCell(tr, t, "td", first ? r.getIcon() : null, first ? r.getHint() : null, first ? indents : null, !r.getSubRows().isEmpty(), first ? r.getAnchor() : null, color, r.getLineColor(), imagePath, border, outputTracker);
@ -595,29 +611,31 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
throw new Error("Unrecognized indent level: " + indents.get(i));
}
}
if (!indents.isEmpty())
if (!indents.isEmpty()) {
String sfx = ACTIVE_TABLE && hasChildren ? "-open" : "";
switch (indents.get(indents.size()-1)) {
case NEW_REGULAR:
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_end.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_end"+sfx+".png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
break;
case NEW_SLICER:
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_end_slicer.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_end_slicer"+sfx+".png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
break;
case NEW_SLICE:
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_end_slice.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_end_slice"+sfx+".png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
break;
case CONTINUE_REGULAR:
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin"+sfx+".png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
break;
case CONTINUE_SLICER:
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_slicer.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_slicer"+sfx+".png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
break;
case CONTINUE_SLICE:
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_slice.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_slice"+sfx+".png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
break;
default:
throw new Error("Unrecognized indent level: " + indents.get(indents.size()-1));
}
}
}
else
tc.setAttribute("style", "vertical-align: top; text-align : left; background-color: "+color+"; border: "+ border +"px #F0F0F0 solid; padding:0px 4px 0px 4px");
@ -700,7 +718,7 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
check(c);
int i = 0;
for (Row r : model.getRows()) {
check(r, "rows", model.getTitles().size(), Integer.toString(i));
check(r, "rows", model.getTitles().size(), "", i, model.getRows().size());
i++;
}
}
@ -715,11 +733,18 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
}
private void check(Row r, String string, int size, String path) throws FHIRException {
private void check(Row r, String string, int size, String path, int index, int total) throws FHIRException {
String id = Integer.toString(index)+".";
if (total <= 26) {
char c = (char) ('a'+index);
id = Character.toString(c);
}
path = path + id;
r.setId(path);
check(r.getCells().size() == size, "All rows must have the same number of columns ("+Integer.toString(size)+") as the titles but row "+path+" doesn't ("+r.getCells().get(0).text()+"): "+r.getCells());
int i = 0;
for (Row c : r.getSubRows()) {
check(c, "rows", size, path+"."+Integer.toString(i));
check(c, "rows", size, path, i, r.getSubRows().size());
i++;
}
}