Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FormFieldCustomization |
|
| 1.5555555555555556;1,556 |
1 | 0 | /** |
2 | * 2014, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos | |
3 | * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt | |
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 | * The customization of a form field | |
16 | * | |
17 | * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a><br/> | |
18 | * @created 28/01/2014 | |
19 | */ | |
20 | public class FormFieldCustomization { | |
21 | ||
22 | /** the configuration id to save the help message */ | |
23 | public final static String MESSAGE_HELP_ID = "help"; | |
24 | ||
25 | /** the configuration id to save the hint message */ | |
26 | public final static String MESSAGE_HINT_ID = "hint"; | |
27 | ||
28 | /** the configuration id to save the label message */ | |
29 | public final static String MESSAGE_LABEL_ID = "label"; | |
30 | ||
31 | /** the form field ID */ | |
32 | private String fieldID; | |
33 | ||
34 | /** if the field is mandatory */ | |
35 | 0 | private FeatureState mandatory = FeatureState.DEFAULT; |
36 | ||
37 | /** the customized messages */ | |
38 | 0 | private MessageList messages = null; |
39 | ||
40 | /** | |
41 | * @param fieldID | |
42 | */ | |
43 | 0 | public FormFieldCustomization(String fieldID) |
44 | { | |
45 | 0 | this.fieldID = fieldID; |
46 | 0 | } |
47 | ||
48 | /** | |
49 | * Utility method that returns the desired customized message or the default one if no customization exists | |
50 | * | |
51 | * @param messageID | |
52 | * the message ID to get | |
53 | * @param language | |
54 | * the desired language | |
55 | * @param defaultValue | |
56 | * the default value of not custom message exists | |
57 | * @return the custom message or if it does not exist the given default value | |
58 | */ | |
59 | public String getCustomMessage(String messageID, String language, String defaultValue) | |
60 | { | |
61 | 0 | MessageList messageList = this.getMessages(); |
62 | 0 | MessageTranslations messageTranslations = null; |
63 | 0 | Message message = null; |
64 | ||
65 | 0 | if (messageList != null) |
66 | 0 | messageTranslations = messageList.getMessageTranslations(messageID); |
67 | 0 | if (messageTranslations != null) |
68 | 0 | message = messageTranslations.getTranslations().get(language); |
69 | ||
70 | 0 | if (message != null && StringUtils.isNotBlank(message.getMessage())) |
71 | 0 | return message.getMessage(); |
72 | else | |
73 | 0 | return defaultValue; |
74 | } | |
75 | ||
76 | /** | |
77 | * Inspector for the 'fieldID' attribute. | |
78 | * | |
79 | * @return the fieldID value | |
80 | */ | |
81 | public String getFieldID() | |
82 | { | |
83 | 0 | return fieldID; |
84 | } | |
85 | ||
86 | /** | |
87 | * Inspector for the 'mandatory' attribute. | |
88 | * | |
89 | * @return the mandatory value | |
90 | */ | |
91 | public FeatureState getMandatory() | |
92 | { | |
93 | 0 | return mandatory; |
94 | } | |
95 | ||
96 | /** | |
97 | * Inspector for the 'messages' attribute. | |
98 | * | |
99 | * @return the messages value | |
100 | */ | |
101 | public MessageList getMessages() | |
102 | { | |
103 | 0 | return messages; |
104 | } | |
105 | ||
106 | /** | |
107 | * Modifier for the 'fieldID' attribute. | |
108 | * | |
109 | * @param fieldID | |
110 | * the new fieldID value to set | |
111 | * @return the updated object | |
112 | */ | |
113 | public FormFieldCustomization setFieldID(String fieldID) | |
114 | { | |
115 | 0 | this.fieldID = fieldID; |
116 | ||
117 | 0 | return this; |
118 | } | |
119 | ||
120 | /** | |
121 | * Modifier for the 'mandatory' attribute. | |
122 | * | |
123 | * @param mandatory | |
124 | * the new mandatory value to set | |
125 | * @return the updated object | |
126 | */ | |
127 | public FormFieldCustomization setMandatory(FeatureState mandatory) | |
128 | { | |
129 | 0 | this.mandatory = mandatory; |
130 | ||
131 | 0 | return this; |
132 | } | |
133 | ||
134 | /** | |
135 | * Modifier for the 'messages' attribute. | |
136 | * | |
137 | * @param messages | |
138 | * the new messages value to set | |
139 | * @return the updated object | |
140 | */ | |
141 | public FormFieldCustomization setMessages(MessageList messages) | |
142 | { | |
143 | 0 | this.messages = messages; |
144 | ||
145 | 0 | return this; |
146 | } | |
147 | ||
148 | /** | |
149 | * @see java.lang.Object#toString() | |
150 | */ | |
151 | @Override | |
152 | public String toString() | |
153 | { | |
154 | 0 | ObjectFormatter formatter = new ObjectFormatter(); |
155 | 0 | formatter.addItem("FieldID", this.fieldID); |
156 | 0 | formatter.addItem("Mandatory", this.mandatory); |
157 | 0 | formatter.addItem("Messages", this.messages); |
158 | ||
159 | 0 | return formatter.getFormatedObject(); |
160 | } | |
161 | } |