Commit 10a8de6e authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

organization form

parent c0765907
package kz.arta.synergy.api.asforms.annotations; package kz.arta.synergy.api.asforms.annotations;
import kz.arta.synergy.api.asforms.pojo.DefaultListBoxDictionary;
import kz.arta.synergy.api.asforms.pojo.ListBoxDictionary;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
...@@ -13,6 +16,8 @@ import java.lang.annotation.Target; ...@@ -13,6 +16,8 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface ListBox { public @interface ListBox {
String value() default ""; String id() default "";
Class<? extends ListBoxDictionary> dictionary() default DefaultListBoxDictionary.class;
} }
package kz.arta.synergy.api.asforms.converter.components; package kz.arta.synergy.api.asforms.converter.components;
import kz.arta.synergy.api.asforms.annotations.ListBox; import kz.arta.synergy.api.asforms.annotations.ListBox;
import kz.arta.synergy.api.asforms.pojo.AsFormData;
import kz.arta.synergy.api.asforms.pojo.ComponentTypes; import kz.arta.synergy.api.asforms.pojo.ComponentTypes;
import kz.arta.synergy.api.asforms.pojo.ListBoxDictionary;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
/** /**
* @author raimbek * @author raimbek
...@@ -11,6 +14,37 @@ import java.lang.annotation.Annotation; ...@@ -11,6 +14,37 @@ import java.lang.annotation.Annotation;
*/ */
public class ListBoxConverter extends AbstractComponentConverter { public class ListBoxConverter extends AbstractComponentConverter {
@Override
public <T> AsFormData toAsfData(T asForm, Field field, Annotation annotation, String index) throws IllegalAccessException {
field.setAccessible(true);
String cmpId = getCmpId(field, annotation, index);
AsFormData asFormData = AsFormData.create(cmpId, getType(annotation));
Object valueObject = field.get(asForm);
if (valueObject instanceof AsFormData) {
AsFormData asFormDataObject = (AsFormData) valueObject;
asFormDataObject.setId(cmpId);
asFormDataObject.setType(getType(annotation));
return asFormDataObject;
} else {
String value = String.valueOf(valueObject);
try {
ListBoxDictionary listBoxDictionary = ((ListBox) annotation).dictionary().newInstance();
if (hasKeyValueAnnotation(field)) {
asFormData.setKey(value);
asFormData.setValue(listBoxDictionary.getValue(value));
} else {
asFormData.setValue(value);
asFormData.setKey(listBoxDictionary.getValue(value));
}
} catch (InstantiationException e) {
e.printStackTrace();
}
}
return asFormData;
}
@Override @Override
public String getType(Annotation annotation) { public String getType(Annotation annotation) {
return ComponentTypes.LISTBOX; return ComponentTypes.LISTBOX;
...@@ -18,6 +52,6 @@ public class ListBoxConverter extends AbstractComponentConverter { ...@@ -18,6 +52,6 @@ public class ListBoxConverter extends AbstractComponentConverter {
@Override @Override
public String getCmpId(Annotation annotation) { public String getCmpId(Annotation annotation) {
return ((ListBox) annotation).value(); return ((ListBox) annotation).id();
} }
} }
package kz.arta.synergy.api.asforms.pojo;
public class DefaultListBoxDictionary implements ListBoxDictionary {
@Override
public String getValue(String key) {
throw new UnsupportedOperationException();
}
}
package kz.arta.synergy.api.asforms.pojo;
public interface ListBoxDictionary {
String getValue(String key);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment