Search in sources :

Example 1 with ConnectFieldOption

use of fi.otavanopisto.muikku.plugins.dnm.parser.content.ConnectFieldOption 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);
}
Also used : ConnectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta) ConnectFieldConnectionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldConnectionMeta) ArrayList(java.util.ArrayList) ConnectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldOptionMeta) ConnectFieldOption(fi.otavanopisto.muikku.plugins.dnm.parser.content.ConnectFieldOption)

Example 2 with ConnectFieldOption

use of fi.otavanopisto.muikku.plugins.dnm.parser.content.ConnectFieldOption 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);
}
Also used : ConnectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta) Element(org.w3c.dom.Element) ConnectFieldOption(fi.otavanopisto.muikku.plugins.dnm.parser.content.ConnectFieldOption)

Aggregations

ConnectFieldOption (fi.otavanopisto.muikku.plugins.dnm.parser.content.ConnectFieldOption)2 ConnectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta)2 ConnectFieldConnectionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldConnectionMeta)1 ConnectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldOptionMeta)1 ArrayList (java.util.ArrayList)1 Element (org.w3c.dom.Element)1