2018-06-27 12:29:21 +02:00
|
|
|
package eu.eudat.models.data.components.commons.datafield;
|
2017-11-30 11:10:42 +01:00
|
|
|
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.utilities.interfaces.XmlSerializable;
|
2017-11-30 11:10:42 +01:00
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Element;
|
|
|
|
|
2019-02-25 17:46:16 +01:00
|
|
|
import java.util.HashMap;
|
2018-02-16 11:34:02 +01:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public abstract class ComboBoxData<T> extends FieldData<T> {
|
2022-02-18 16:51:32 +01:00
|
|
|
public static class Option implements XmlSerializable<Option> {
|
2018-02-16 11:34:02 +01:00
|
|
|
private String label;
|
|
|
|
private String value;
|
2019-09-10 17:30:46 +02:00
|
|
|
private String source;
|
2020-03-20 17:20:22 +01:00
|
|
|
private String uri;
|
2018-02-16 11:34:02 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:30:46 +02:00
|
|
|
public String getSource() {
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
public void setSource(String source) {
|
|
|
|
this.source = source;
|
|
|
|
}
|
|
|
|
|
2020-03-20 17:20:22 +01:00
|
|
|
public String getUri() {
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUri(String uri) {
|
|
|
|
this.uri = uri;
|
|
|
|
}
|
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
@Override
|
|
|
|
public Element toXml(Document doc) {
|
|
|
|
Element option = doc.createElement("option");
|
|
|
|
option.setAttribute("label", this.label);
|
|
|
|
option.setAttribute("value", this.value);
|
2019-09-10 17:30:46 +02:00
|
|
|
option.setAttribute("source", this.source);
|
2020-03-20 17:20:22 +01:00
|
|
|
option.setAttribute("uri", this.uri);
|
2018-02-16 11:34:02 +01:00
|
|
|
return option;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-02-18 16:51:32 +01:00
|
|
|
public ComboBoxData.Option fromXml(Element item) {
|
2018-02-16 11:34:02 +01:00
|
|
|
this.label = item.getAttribute("label");
|
|
|
|
this.value = item.getAttribute("value");
|
2019-09-10 17:30:46 +02:00
|
|
|
this.source = item.getAttribute("source");
|
2020-03-20 17:20:22 +01:00
|
|
|
this.uri = item.getAttribute("uri");
|
2018-02-16 11:34:02 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-02-25 17:46:16 +01:00
|
|
|
@Override
|
|
|
|
public Map<String, Object> toMap(Element item) {
|
|
|
|
HashMap dataMap = new HashMap();
|
|
|
|
dataMap.put("label", item != null ? item.getAttribute("label") : "");
|
|
|
|
dataMap.put("type", item != null ? item.getAttribute("type") : "");
|
|
|
|
return dataMap;
|
|
|
|
}
|
2017-11-30 11:10:42 +01:00
|
|
|
}
|