113 lines
3.8 KiB
Java
113 lines
3.8 KiB
Java
package eu.eudat.models.data.components.commons.datafield;
|
|
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class AutoCompleteData extends ComboBoxData<AutoCompleteData> {
|
|
private String url;
|
|
private Option autoCompleteOptions;
|
|
private String optionsRoot;
|
|
|
|
|
|
public String getOptionsRoot() {
|
|
return optionsRoot;
|
|
}
|
|
|
|
public void setOptionsRoot(String optionsRoot) {
|
|
this.optionsRoot = optionsRoot;
|
|
}
|
|
|
|
public String getUrl() {
|
|
return url;
|
|
}
|
|
|
|
public void setUrl(String url) {
|
|
this.url = url;
|
|
}
|
|
|
|
public Option getAutoCompleteOptions() {
|
|
return autoCompleteOptions;
|
|
}
|
|
|
|
public void setAutoCompleteOptions(Option autoCompleteOptions) {
|
|
this.autoCompleteOptions = autoCompleteOptions;
|
|
}
|
|
|
|
@Override
|
|
public Element toXml(Document doc) {
|
|
Element root = super.toXml(doc);
|
|
|
|
root.setAttribute("url", this.url);
|
|
root.setAttribute("optionsRoot", this.optionsRoot);
|
|
Element element = doc.createElement("option");
|
|
element.setAttribute("label", this.autoCompleteOptions.getLabel());
|
|
element.setAttribute("value", autoCompleteOptions.getValue());
|
|
root.appendChild(element);
|
|
return root;
|
|
}
|
|
|
|
@Override
|
|
public AutoCompleteData fromXml(Element item) {
|
|
super.fromXml(item);
|
|
this.url = item.getAttribute("url");
|
|
this.optionsRoot = item.getAttribute("optionsRoot");
|
|
Element optionElement = (Element) item.getElementsByTagName("option").item(0);
|
|
if (optionElement != null) {
|
|
this.autoCompleteOptions = new Option();
|
|
this.autoCompleteOptions.setLabel(optionElement.getAttribute("label"));
|
|
this.autoCompleteOptions.setValue(optionElement.getAttribute("value"));
|
|
}
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public AutoCompleteData fromData(Object data) {
|
|
super.fromData(data);
|
|
this.autoCompleteOptions = new Option();
|
|
if (data != null) {
|
|
this.url = (String) ((Map<String, Object>) data).get("url");
|
|
this.optionsRoot = (String) ((Map<String, Object>) data).get("optionsRoot");
|
|
Map<String, String> options = ((Map<String, Map<String, String>>) data).get("autoCompleteOptions");
|
|
if (options != null) {
|
|
this.autoCompleteOptions.setLabel(options.get("label"));
|
|
this.autoCompleteOptions.setValue(options.get("value"));
|
|
}
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public Object toData() {
|
|
// TODO Auto-generated method stub
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public Map<String, Object> toMap(Element item) {
|
|
HashMap dataMap = new HashMap();
|
|
dataMap.put("label", item != null ? item.getAttribute("label") : "");
|
|
dataMap.put("url", item != null ? item.getAttribute("url") : "");
|
|
dataMap.put("type", item != null ? item.getAttribute("type") : "autocomplete");
|
|
dataMap.put("optionsRoot", item != null ? item.getAttribute("optionsRoot") : "");
|
|
Element optionElement = (Element) item.getElementsByTagName("option").item(0);
|
|
// if (optionElement != null) {
|
|
// this.autoCompleteOptions = new Option();
|
|
// this.autoCompleteOptions.setLabel(optionElement.getAttribute("label"));
|
|
// this.autoCompleteOptions.setValue(optionElement.getAttribute("value"));
|
|
// }
|
|
dataMap.put("autoCompleteOptions", item != null ? optionToMap(optionElement) : null);
|
|
return dataMap;
|
|
}
|
|
|
|
private Map<String, Object> optionToMap(Element item){
|
|
HashMap dataMap = new HashMap();
|
|
dataMap.put("label", item != null ? item.getAttribute("label") : "");
|
|
dataMap.put("value", item != null ? item.getAttribute("value") : "");
|
|
return dataMap;
|
|
}
|
|
}
|