12
12
import io .asfjava .ui .core .form .ValuesContainer ;
13
13
import io .asfjava .ui .core .logging .ASFUILogger ;
14
14
15
- public class ComboBoxGenerator implements FormDefinitionGenerator {
15
+ public class ComboBoxGenerator extends ListGenerator implements FormDefinitionGenerator {
16
16
17
17
@ Override
18
18
public void generate (ObjectNode fieldFormDefinition , Field field ) {
@@ -24,47 +24,22 @@ public void generate(ObjectNode fieldFormDefinition, Field field) {
24
24
fieldFormDefinition .put ("multiple" , annotation .multiple ());
25
25
fieldFormDefinition .put ("required" , annotation .required ());
26
26
fieldFormDefinition .put ("size" , annotation .size ());
27
+ if (!annotation .refURL ().isEmpty ()) {
28
+ fieldFormDefinition .put ("$ref" , annotation .refURL ());
29
+ }
27
30
28
31
ObjectMapper comboMapper = new ObjectMapper ();
29
32
ArrayNode titlesMap = comboMapper .createArrayNode ();
30
33
if (annotation .values ().length != 0 ) {
31
34
Arrays .stream (annotation .values ()).forEach (value -> buildValueDefinition (comboMapper , titlesMap , value ));
32
-
33
35
fieldFormDefinition .set ("titleMap" , titlesMap );
34
36
} else if (!annotation .titleMap ().equals (ValuesContainer .class )) {
35
-
36
- try {
37
- Map <String , String > map = (annotation .titleMap ()).newInstance ().getValues ();
38
- map .entrySet ().stream ().forEach (mapEntry -> {
39
- ObjectNode entryNode = comboMapper .createObjectNode ();
40
- entryNode .put ("name" , mapEntry .getKey ());
41
- entryNode .putPOJO ("value" , mapEntry .getValue ());
42
- titlesMap .add (entryNode );
43
- });
44
- fieldFormDefinition .set ("titleMap" , titlesMap );
45
- } catch (InstantiationException | IllegalAccessException e ) {
46
- ASFUILogger .getLogger ().error (e .getMessage ());
47
- throw new RuntimeException (e );
48
- }
37
+ buildValues (comboMapper , titlesMap , annotation .titleMap ());
38
+ fieldFormDefinition .set ("titleMap" , titlesMap );
49
39
}
50
40
51
41
}
52
42
53
- private void buildValueDefinition (ObjectMapper comboMapper , ArrayNode titlesMap , String value ) {
54
- ObjectNode entry = comboMapper .createObjectNode ();
55
- String upperCasedValue = value .toUpperCase ();
56
- String lowerCasedValue = value .toLowerCase ();
57
- if (value .equals (upperCasedValue )) {
58
- entry .put ("name" , value .toLowerCase ());
59
- } else if (value .equals (lowerCasedValue )) {
60
- entry .put ("name" , value .replace (value .substring (0 , 1 ), value .substring (0 , 1 ).toUpperCase ()));
61
- } else {
62
- entry .put ("name" , value );
63
- }
64
- entry .put ("value" , value );
65
- titlesMap .add (entry );
66
- }
67
-
68
43
@ Override
69
44
public String getAnnotation () {
70
45
return ComboBox .class .getName ();
0 commit comments