use of fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta in project muikku by otavanopisto.
the class FieldTranslator method translateTextField.
public TextFieldMeta translateTextField(String name, Integer columns, Boolean autogrow, List<RightAnswer> rightAnswers, String help, String hint) {
List<TextFieldRightAnswer> translatedAnswers = new ArrayList<>();
for (fi.otavanopisto.muikku.plugins.dnm.parser.content.RightAnswer rightAnswer : rightAnswers) {
Boolean correct = rightAnswer.getPoints() != null && rightAnswer.getPoints() > 0;
translatedAnswers.add(new TextFieldRightAnswer(rightAnswer.getText(), true, false, correct));
}
return new TextFieldMeta(name, columns, autogrow, translatedAnswers, hint);
}
use of fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta in project muikku by otavanopisto.
the class FieldElementsHandler method handleTextField.
@Override
public Node handleTextField(org.w3c.dom.Document ownerDocument, String paramName, Integer columns, Boolean autogrow, List<RightAnswer> rightAnswers, String help, String hint) {
// TODO: This is just for show, real implementation depends on QueryMaterial implementation
TextFieldMeta textFieldData = fieldTranslator.translateTextField(paramName, columns, autogrow, rightAnswers, help, hint);
Element inputElement = ownerDocument.createElement("input");
inputElement.setAttribute("type", "text");
inputElement.setAttribute("name", paramName);
inputElement.setAttribute("size", String.valueOf(columns));
return wrapWithObjectElement(ownerDocument, inputElement, textFieldData);
}
use of fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta in project muikku by otavanopisto.
the class HtmlMaterialFieldChangeListener method onHtmlMaterialTextFieldCreated.
// Create
// Text field
public void onHtmlMaterialTextFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
if (event.getField().getType().equals("application/vnd.muikku.field.text")) {
ObjectMapper objectMapper = new ObjectMapper();
TextFieldMeta textFieldMeta;
try {
textFieldMeta = objectMapper.readValue(event.getField().getContent(), TextFieldMeta.class);
} catch (IOException e) {
throw new MaterialFieldMetaParsingExeption("Could not parse text field meta", e);
}
QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), textFieldMeta.getName());
if (queryField == null) {
queryTextFieldController.createQueryTextField(event.getMaterial(), textFieldMeta.getName());
} else {
throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
}
}
}
Aggregations