1
2
3
4
5
6 package pt.digitalis.dif.dem.objects;
7
8 import pt.digitalis.dif.dem.objects.messages.Message;
9 import pt.digitalis.dif.dem.objects.messages.MessageList;
10 import pt.digitalis.dif.dem.objects.messages.MessageTranslations;
11 import pt.digitalis.dif.utils.ObjectFormatter;
12 import pt.digitalis.utils.common.StringUtils;
13
14
15
16
17
18
19
20 public class FormFieldCustomization {
21
22
23 public final static String MESSAGE_HELP_ID = "help";
24
25
26 public final static String MESSAGE_HINT_ID = "hint";
27
28
29 public final static String MESSAGE_LABEL_ID = "label";
30
31
32 private String fieldID;
33
34
35 private FeatureState mandatory = FeatureState.DEFAULT;
36
37
38 private MessageList messages = null;
39
40
41
42
43 public FormFieldCustomization(String fieldID)
44 {
45 this.fieldID = fieldID;
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59 public String getCustomMessage(String messageID, String language, String defaultValue)
60 {
61 MessageList messageList = this.getMessages();
62 MessageTranslations messageTranslations = null;
63 Message message = null;
64
65 if (messageList != null)
66 messageTranslations = messageList.getMessageTranslations(messageID);
67 if (messageTranslations != null)
68 message = messageTranslations.getTranslations().get(language);
69
70 if (message != null && StringUtils.isNotBlank(message.getMessage()))
71 return message.getMessage();
72 else
73 return defaultValue;
74 }
75
76
77
78
79
80
81 public String getFieldID()
82 {
83 return fieldID;
84 }
85
86
87
88
89
90
91 public FeatureState getMandatory()
92 {
93 return mandatory;
94 }
95
96
97
98
99
100
101 public MessageList getMessages()
102 {
103 return messages;
104 }
105
106
107
108
109
110
111
112
113 public FormFieldCustomization setFieldID(String fieldID)
114 {
115 this.fieldID = fieldID;
116
117 return this;
118 }
119
120
121
122
123
124
125
126
127 public FormFieldCustomization setMandatory(FeatureState mandatory)
128 {
129 this.mandatory = mandatory;
130
131 return this;
132 }
133
134
135
136
137
138
139
140
141 public FormFieldCustomization setMessages(MessageList messages)
142 {
143 this.messages = messages;
144
145 return this;
146 }
147
148
149
150
151 @Override
152 public String toString()
153 {
154 ObjectFormatter formatter = new ObjectFormatter();
155 formatter.addItem("FieldID", this.fieldID);
156 formatter.addItem("Mandatory", this.mandatory);
157 formatter.addItem("Messages", this.messages);
158
159 return formatter.getFormatedObject();
160 }
161 }