use of fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta in project muikku by otavanopisto.
the class FieldTranslator method translateConnectField.
public ConnectFieldMeta translateConnectField(String name, List<ConnectFieldOption> options) {
List<ConnectFieldOptionMeta> connectFieldOptionMetas = new ArrayList<ConnectFieldOptionMeta>();
List<ConnectFieldOptionMeta> counterparts = new ArrayList<ConnectFieldOptionMeta>();
;
List<ConnectFieldConnectionMeta> connectFieldConnectionMetas = new ArrayList<>();
for (int i = 0; i < options.size(); i++) {
ConnectFieldOption option = options.get(i);
String fieldName = String.valueOf(i + 1);
String counterpartName = getExcelStyleLetterIndex(i);
if (StringUtils.length(option.getTerm()) > 255) {
option.setTerm(option.getTerm().substring(0, 254));
}
if (StringUtils.length(option.getEquivalent()) > 255) {
option.setEquivalent(option.getEquivalent().substring(0, 254));
}
connectFieldOptionMetas.add(new ConnectFieldOptionMeta(fieldName, option.getTerm()));
counterparts.add(new ConnectFieldOptionMeta(counterpartName, option.getEquivalent()));
connectFieldConnectionMetas.add(new ConnectFieldConnectionMeta(fieldName, option.getAnswer()));
}
return new ConnectFieldMeta(name, connectFieldOptionMetas, counterparts, connectFieldConnectionMetas);
}
use of fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta in project muikku by otavanopisto.
the class FieldElementsHandler method handleConnectField.
@Override
public Node handleConnectField(org.w3c.dom.Document ownerDocument, String paramName, List<ConnectFieldOption> options, String help, String hint) {
ConnectFieldMeta connectFieldData = fieldTranslator.translateConnectField(paramName, options);
Element outerSpan = ownerDocument.createElement("span");
outerSpan.setAttribute("style", "display: table;");
int fieldCount = 0;
for (ConnectFieldOption connectFieldOption : options) {
Element rowSpan = ownerDocument.createElement("span");
rowSpan.setAttribute("style", "display: table-row;");
Element leftSpan = ownerDocument.createElement("span");
leftSpan.setAttribute("style", "display: table-cell;");
Element centerSpan = ownerDocument.createElement("span");
centerSpan.setAttribute("style", "display: table-cell;");
Element rightSpan = ownerDocument.createElement("span");
rightSpan.setAttribute("style", "display: table-cell;");
Element input = ownerDocument.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("name", paramName);
input.setAttribute("data-fieldcount", String.valueOf(fieldCount));
leftSpan.setTextContent(connectFieldOption.getTerm());
centerSpan.appendChild(input);
rightSpan.setTextContent(connectFieldOption.getEquivalent());
rowSpan.appendChild(leftSpan);
rowSpan.appendChild(centerSpan);
rowSpan.appendChild(rightSpan);
outerSpan.appendChild(rowSpan);
fieldCount++;
}
return wrapWithObjectElement(ownerDocument, outerSpan, connectFieldData);
}
use of fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta in project muikku by otavanopisto.
the class HtmlMaterialFieldChangeListener method onHtmlMaterialConnectFieldCreated.
// Connect field
public void onHtmlMaterialConnectFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
if (event.getField().getType().equals("application/vnd.muikku.field.connect")) {
ObjectMapper objectMapper = new ObjectMapper();
ConnectFieldMeta connectFieldMeta;
try {
connectFieldMeta = objectMapper.readValue(event.getField().getContent(), ConnectFieldMeta.class);
} catch (IOException e) {
throw new MaterialFieldMetaParsingExeption("Could not parse connect field meta", e);
}
QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), connectFieldMeta.getName());
if (queryField != null) {
throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
}
QueryConnectField field = queryConnectFieldController.createQueryConnectField(event.getMaterial(), connectFieldMeta.getName());
Map<String, QueryConnectFieldTerm> terms = new HashMap<String, QueryConnectFieldTerm>();
Map<String, QueryConnectFieldCounterpart> counterparts = new HashMap<String, QueryConnectFieldCounterpart>();
for (ConnectFieldOptionMeta option : connectFieldMeta.getFields()) {
terms.put(option.getName(), queryConnectFieldController.createConnectFieldTerm(field, option.getName(), option.getText(), null));
}
for (ConnectFieldOptionMeta option : connectFieldMeta.getCounterparts()) {
counterparts.put(option.getName(), queryConnectFieldController.createConnectFieldCounterpart(field, option.getName(), option.getText()));
}
for (ConnectFieldConnectionMeta connection : connectFieldMeta.getConnections()) {
terms.get(connection.getField()).setCounterpart(counterparts.get(connection.getCounterpart()));
}
}
}
Aggregations