argos/dmp-backend/src/main/java/eu/eudat/models/components/commons/datafield/ComboBoxData.java

91 lines
2.1 KiB
Java

package eu.eudat.models.components.commons.datafield;
import eu.eudat.utilities.interfaces.XmlSerializable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Map;
public abstract class ComboBoxData<T> extends FieldData<T> {
public class Option implements XmlSerializable<Option> {
private String label;
private String value;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public Element toXml(Document doc) {
Element option = doc.createElement("option");
option.setAttribute("label", this.label);
option.setAttribute("value", this.value);
return option;
}
@Override
public Option fromXml(Element item) {
this.label = item.getAttribute("label");
this.value = item.getAttribute("value");
return this;
}
}
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public Element toXml(Document doc) {
Element root = doc.createElement("data");
root.setAttribute("type", this.type);
root.setAttribute("label", this.getLabel());
return root;
}
@Override
public T fromXml(Element item) {
this.setLabel(item.getAttribute("label"));
this.type = item.getAttribute("type");
return (T) this;
}
@Override
public T fromData(Object data) {
if (data != null) {
this.type = (String) ((Map<String, Object>) data).get("type");
this.setLabel((String) ((Map<String, Object>) data).get("label"));
}
return (T) this;
}
@Override
public Object toData() {
// TODO Auto-generated method stub
return null;
}
}