public boolean canCreateRepeat(TreeReference repeatRef, FormIndex repeatIndex) { GroupDef repeat = (GroupDef) this.getChild(repeatIndex); // Check to see if this repeat can have children added by the user if (repeat.noAddRemove) { // Check to see if there's a count to use to determine how many children this repeat // should have if (repeat.getCountReference() != null) { int currentMultiplicity = repeatIndex.getElementMultiplicity(); // get the total multiplicity possible long fullcount = ((Integer) this.getInstance().getDataValue(repeat.getCountReference()).getValue()) .intValue(); if (fullcount <= currentMultiplicity) { return false; } } else { // Otherwise the user can never add repeat instances return false; } } // TODO: If we think the node is still relevant, we also need to figure out a way to test that // assumption against // the repeat's constraints. return true; }
// TODO: this is explicitly missing integration with the new multi-media support // TODO: localize the default captions public String getRepeatText(String typeKey) { GroupDef g = (GroupDef) element; if (!g.getRepeat()) { throw new RuntimeException("not a repeat"); } String title = getLongText(); int count = getNumRepetitions(); String caption = null; if ("mainheader".equals(typeKey)) { caption = g.mainHeader; if (caption == null) { return title; } } else if ("add".equals(typeKey)) { caption = g.addCaption; if (caption == null) { return "Add another " + title; } } else if ("add-empty".equals(typeKey)) { caption = g.addEmptyCaption; if (caption == null) { caption = g.addCaption; } if (caption == null) { return "None - Add " + title; } } else if ("del".equals(typeKey)) { caption = g.delCaption; if (caption == null) { return "Delete " + title; } } else if ("done".equals(typeKey)) { caption = g.doneCaption; if (caption == null) { return "Done"; } } else if ("done-empty".equals(typeKey)) { caption = g.doneEmptyCaption; if (caption == null) { caption = g.doneCaption; } if (caption == null) { return "Skip"; } } else if ("delheader".equals(typeKey)) { caption = g.delHeader; if (caption == null) { return "Delete which " + title + "?"; } } HashMap<String, Object> vars = new HashMap<String, Object>(); vars.put("name", title); vars.put("n", Integer.valueOf(count)); return form.fillTemplateString(caption, index.getReference(), vars); }
public List<String> getRepetitionsText() { GroupDef g = (GroupDef) element; if (!g.getRepeat()) { throw new RuntimeException("not a repeat"); } int numRepetitions = getNumRepetitions(); List<String> reps = new ArrayList<String>(numRepetitions); for (int i = 0; i < numRepetitions; i++) { reps.add(getRepetitionText("choose", form.descendIntoRepeat(index, i), false)); } return reps; }