use of org.javarosa.core.model.data.helper.Selection in project javarosa by opendatakit.
the class FormEntryPrompt method getAnswerText.
public String getAnswerText() {
IAnswerData data = this.getAnswerValue();
if (data == null)
return null;
else {
String text;
// and multi-selects.
if (data instanceof SelectOneData) {
text = this.getSelectItemText((Selection) data.getValue());
} else if (data instanceof SelectMultiData) {
StringBuilder b = new StringBuilder();
List<Selection> values = (List<Selection>) data.getValue();
for (Selection value : values) {
b.append(this.getSelectItemText(value)).append(" ");
}
text = b.toString();
} else {
text = data.getDisplayText();
}
if (getControlType() == Constants.CONTROL_SECRET) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < text.length(); ++i) {
b.append("*");
}
text = b.toString();
}
return text;
}
}
use of org.javarosa.core.model.data.helper.Selection in project javarosa by opendatakit.
the class XFormAnswerDataSerializer method serializeAnswerData.
/**
* @param data The AnswerDataObject to be serialized
* @return A string containing the xforms compliant format
* for a <select> tag, a string containing a list of answers
* separated by space characters.
*/
public Object serializeAnswerData(SelectMultiData data) {
List<Selection> selections = (List<Selection>) data.getValue();
StringBuilder selectString = new StringBuilder();
for (Selection selection : selections) {
if (selectString.length() > 0)
selectString.append(DELIMITER);
selectString.append(selection.getValue());
}
// for storing multiple selections.
return selectString.toString();
}
use of org.javarosa.core.model.data.helper.Selection in project javarosa by opendatakit.
the class FormDef method attachControlsToInstanceData.
private void attachControlsToInstanceData(TreeElement node) {
for (int i = 0; i < node.getNumChildren(); i++) {
attachControlsToInstanceData(node.getChildAt(i));
}
IAnswerData val = node.getValue();
List<Selection> selections = null;
if (val instanceof SelectOneData) {
selections = new ArrayList<Selection>();
selections.add((Selection) val.getValue());
} else if (val instanceof SelectMultiData) {
selections = (List<Selection>) val.getValue();
}
if (selections != null) {
QuestionDef q = findQuestionByRef(node.getRef(), this);
if (q == null) {
throw new RuntimeException("FormDef.attachControlsToInstanceData: can't find question to link");
}
if (q.getDynamicChoices() != null) {
// droos: i think we should do something like initializing the
// itemset here, so that default answers
// can be linked to the selectchoices. however, there are
// complications. for example, the itemset might
// not be ready to be evaluated at form initialization; it may
// require certain questions to be answered
// first. e.g., if we evaluate an itemset and it has no choices, the
// xform engine will throw an error
// itemset TODO
}
for (Selection s : selections) {
s.attachChoice(q);
}
}
}
use of org.javarosa.core.model.data.helper.Selection in project javarosa by opendatakit.
the class SelectMultiData method getDisplayText.
/**
* @return THE XMLVALUE!!
*/
/*
* (non-Javadoc)
* @see org.javarosa.core.model.data.IAnswerData#getDisplayText()
*/
@Override
public String getDisplayText() {
StringBuilder b = new StringBuilder();
for (int i = 0; i < vs.size(); i++) {
Selection s = (Selection) vs.get(i);
b.append(s.getValue());
if (i < vs.size() - 1)
b.append(", ");
}
return b.toString();
}
use of org.javarosa.core.model.data.helper.Selection in project collect by opendatakit.
the class FormEntryPromptUtils method getAnswerText.
public static String getAnswerText(FormEntryPrompt fep, Context context, FormController formController) {
IAnswerData data = fep.getAnswerValue();
final String appearance = fep.getQuestion().getAppearanceAttr();
if (data instanceof SelectMultiData) {
StringBuilder b = new StringBuilder();
String sep = "";
for (Selection value : (List<Selection>) data.getValue()) {
b.append(sep);
sep = ", ";
b.append(fep.getSelectItemText(value));
}
return b.toString();
}
if (data instanceof DateTimeData) {
return DateTimeUtils.getDateTimeLabel((Date) data.getValue(), DateTimeUtils.getDatePickerDetails(appearance), true, context);
}
if (data instanceof DateData) {
return DateTimeUtils.getDateTimeLabel((Date) data.getValue(), DateTimeUtils.getDatePickerDetails(appearance), false, context);
}
if (data != null && appearance != null && appearance.contains("thousands-sep")) {
try {
final BigDecimal answerAsDecimal = new BigDecimal(fep.getAnswerText());
DecimalFormat df = new DecimalFormat();
df.setGroupingSize(3);
df.setGroupingUsed(true);
df.setMaximumFractionDigits(Integer.MAX_VALUE);
// Use . as decimal marker for consistency with DecimalWidget
DecimalFormatSymbols customFormat = new DecimalFormatSymbols();
customFormat.setDecimalSeparator('.');
if (df.getDecimalFormatSymbols().getGroupingSeparator() == '.') {
customFormat.setGroupingSeparator(' ');
}
df.setDecimalFormatSymbols(customFormat);
return df.format(answerAsDecimal);
} catch (NumberFormatException e) {
return fep.getAnswerText();
}
}
if (data != null && data.getValue() != null && fep.getDataType() == DATATYPE_TEXT && fep.getQuestion().getAdditionalAttribute(null, "query") != null) {
// ItemsetWidget
return new ItemsetDao().getItemLabel(fep.getAnswerValue().getDisplayText(), formController.getMediaFolder().getAbsolutePath(), formController.getLanguage());
}
return fep.getAnswerText();
}
Aggregations