package io.asfjava.ui.core.generators;

import java.lang.reflect.Field;

import com.fasterxml.jackson.databind.node.ObjectNode;

import io.asfjava.ui.core.form.ComboBox;

public class ComboBoxGenerator implements FormDefinitionGenerator {

	@Override
	public void generate(ObjectNode fieldFormDefinition, Field field) {
		ComboBox annotation = field.getAnnotation(ComboBox.class);
		fieldFormDefinition.put("key", field.getName());
		fieldFormDefinition.put("autofocus", annotation.autofocus());
		fieldFormDefinition.put("disabled", annotation.disabled());
		fieldFormDefinition.put("multiple", annotation.multiple());
		fieldFormDefinition.put("required", annotation.required());
		fieldFormDefinition.put("size", annotation.size());
	}

	@Override
	public String getAnnoation() {
		return ComboBox.class.getName();
	}

}

@@ -65,16 +65,144 @@
 .Field;%0A
+import java.util.Map;%0A%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.fasterxml.jackson.databind.node.ArrayNode;
 %0Aimport 
@@ -290,16 +290,65 @@
 omboBox;
+%0Aimport io.asfjava.ui.core.form.TitleMapsAdapter;
 %0A%0Apublic
@@ -598,24 +598,69 @@
 getName());%0A
+%09%09fieldFormDefinition.put(%22type%22, %22select%22);%0A
 %09%09fieldFormD
@@ -951,16 +951,1264 @@
 ize());%0A
+%09%09ObjectMapper comboMapper = new ObjectMapper();%0A%09%09ArrayNode titlesMap = comboMapper.createArrayNode();%0A%09%09String%5B%5D comboValues = annotation.values();%0A%09%09if (comboValues.length != 0) %7B%0A%09%09%09for (String value : comboValues) %7B%0A%09%09%09%09ObjectNode entry = comboMapper.createObjectNode();%0A%09%09%09%09if (value.equals(value.toUpperCase())) %7B%0A%09%09%09%09%09entry.put(%22name%22, value.toLowerCase());%0A%09%09%09%09%7D else if (value.equals(value.toLowerCase())) %7B%0A%09%09%09%09%09entry.put(%22name%22, value.replace(value.substring(0, 1), value.substring(0, 1).toUpperCase()));%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09entry.put(%22name%22, value);%0A%09%09%09%09%7D%0A%09%09%09%09entry.put(%22value%22, value);%0A%09%09%09%09titlesMap.add(entry);%0A%09%09%09%7D%0A%09%09%09fieldFormDefinition.set(%22titleMap%22, titlesMap);%0A%09%09%7D else if (!annotation.titleMap().equals(TitleMapsAdapter.class)) %7B%0A%0A%09%09%09try %7B%0A%09%09%09%09Map%3CString, Object%3E map = (annotation.titleMap()).newInstance().getPossibleValues();%0A%0A%09%09%09%09for (Map.Entry%3CString, Object%3E iterator : map.entrySet()) %7B%0A%09%09%09%09%09ObjectNode entry = comboMapper.createObjectNode();%0A%09%09%09%09%09entry.put(%22name%22, iterator.getKey());%0A%09%09%09%09%09entry.putPOJO(%22value%22, iterator.getValue());%0A%09%09%09%09%09titlesMap.add(entry);%0A%09%09%09%09%7D%0A%09%09%09%09fieldFormDefinition.set(%22titleMap%22, titlesMap);%0A%09%09%09%7D catch (InstantiationException %7C IllegalAccessException e) %7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09%7D%0A%0A
 %09%7D%0A%0A%09@Ov

Update ComboBoxGenerator