Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Configurer |
|
| 1.0869565217391304;1.087 |
1 | package org.kuali.student.common.ui.client.configurable.mvc; | |
2 | ||
3 | import org.kuali.student.common.assembly.data.Metadata; | |
4 | import org.kuali.student.common.assembly.data.ModelDefinition; | |
5 | import org.kuali.student.common.assembly.data.QueryPath; | |
6 | import org.kuali.student.common.ui.client.application.Application; | |
7 | import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; | |
8 | import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; | |
9 | ||
10 | import com.google.gwt.user.client.ui.Widget; | |
11 | ||
12 | /** | |
13 | * A configurer defines the configuration of screens in KS, in particular this is where you add views, | |
14 | * sections, and fields to a LayoutController preferably passed in in an configurer's implementation. | |
15 | * This abstract class contains helper methods to do this. | |
16 | * | |
17 | * @author Kuali Student Team | |
18 | * | |
19 | */ | |
20 | 0 | public abstract class Configurer { |
21 | protected ModelDefinition modelDefinition; | |
22 | 0 | protected String type = ""; |
23 | 0 | protected String state = ""; |
24 | 0 | protected String nextState = ""; |
25 | 0 | protected String groupName = ""; |
26 | ||
27 | /** | |
28 | * Sets the modelDefinition which is the metadata backing the fields to be configured, | |
29 | * this needs to be set before adding any fields in the configurer | |
30 | * @param modelDefinition | |
31 | */ | |
32 | public void setModelDefinition(ModelDefinition modelDefinition){ | |
33 | 0 | this.modelDefinition = modelDefinition; |
34 | 0 | } |
35 | ||
36 | public ModelDefinition getModelDefinition() { | |
37 | 0 | return modelDefinition; |
38 | } | |
39 | ||
40 | /** | |
41 | * Generates a message info to be used in your field descriptor to get the label for the field. | |
42 | * Used by the field descriptor with the application context to determine the label to show based on | |
43 | * the labelKey | |
44 | * @param labelKey key of the message - must match a message in your messages (stored in the db) | |
45 | * @return | |
46 | */ | |
47 | protected MessageKeyInfo generateMessageInfo(String labelKey) { | |
48 | 0 | return new MessageKeyInfo(groupName, type, state, labelKey); |
49 | } | |
50 | ||
51 | /** | |
52 | * Gets the string corresponding to the label key passed in from the application messages | |
53 | * @param labelKey | |
54 | * @return | |
55 | */ | |
56 | protected String getLabel(String labelKey) { | |
57 | 0 | return Application.getApplicationContext().getUILabel(groupName, type, state, labelKey); |
58 | } | |
59 | ||
60 | /** | |
61 | * Gets a section title which is an h1 element using the label key passed to retrieve the corresponding | |
62 | * message | |
63 | * @param labelKey | |
64 | * @return | |
65 | */ | |
66 | protected SectionTitle getH1Title(String labelKey) { | |
67 | 0 | return SectionTitle.generateH1Title(getLabel(labelKey)); |
68 | } | |
69 | ||
70 | /** | |
71 | * Gets a section title which is an h1 element using the label key passed to retrieve the corresponding | |
72 | * message | |
73 | * @param labelKey | |
74 | * @return | |
75 | */ | |
76 | protected SectionTitle getH2Title(String labelKey) { | |
77 | 0 | return SectionTitle.generateH2Title(getLabel(labelKey)); |
78 | } | |
79 | ||
80 | /** | |
81 | * Gets a section title which is an h1 element using the label key passed to retrieve the corresponding | |
82 | * message | |
83 | * @param labelKey | |
84 | * @return | |
85 | */ | |
86 | protected SectionTitle getH3Title(String labelKey) { | |
87 | 0 | return SectionTitle.generateH3Title(getLabel(labelKey)); |
88 | } | |
89 | ||
90 | /** | |
91 | * Gets a section title which is an h1 element using the label key passed to retrieve the corresponding | |
92 | * message | |
93 | * @param labelKey | |
94 | * @return | |
95 | */ | |
96 | protected SectionTitle getH4Title(String labelKey) { | |
97 | 0 | return SectionTitle.generateH4Title(getLabel(labelKey)); |
98 | } | |
99 | ||
100 | /** | |
101 | * Gets a section title which is an h1 element using the label key passed to retrieve the corresponding | |
102 | * message | |
103 | * @param labelKey | |
104 | * @return | |
105 | */ | |
106 | protected SectionTitle getH5Title(String labelKey) { | |
107 | 0 | return SectionTitle.generateH5Title(getLabel(labelKey)); |
108 | } | |
109 | ||
110 | /** | |
111 | * Adds a field with the field key specified to the passed in section. | |
112 | * Returns the generated FieldDescriptor. The field will have no label in this case. | |
113 | * The widget will be auto generated in field descriptor based on the field's metadata in the | |
114 | * model definition defined in this configurer - using the default widget factory. The fieldKey passed | |
115 | * in MUST match a logical path in the metadata (ex. proposal/proposalTitle, etc.) | |
116 | * | |
117 | * Note: It also is acceptable to not use this helper method and add the FieldDescriptor directly | |
118 | * to the section | |
119 | * | |
120 | * @param section | |
121 | * @param fieldKey | |
122 | * @return | |
123 | */ | |
124 | public FieldDescriptor addField(Section section, String fieldKey) { | |
125 | 0 | return addField(section, fieldKey, null, null, null); |
126 | } | |
127 | ||
128 | /** | |
129 | * Adds a field with the field key specified to the passed in section. | |
130 | * Returns the generated FieldDescriptor. Uses the message key provided to generate the field label. | |
131 | * The widget will be auto generated in field descriptor based on the field's metadata in the | |
132 | * model definition defined in this configurer - using the default widget factory. The fieldKey passed | |
133 | * in MUST match a logical path in the metadata (ex. proposal/proposalTitle, etc.) | |
134 | * | |
135 | * Note: It also is acceptable to not use this helper method and add the FieldDescriptor directly | |
136 | * to the section | |
137 | * | |
138 | * @param section | |
139 | * @param fieldKey | |
140 | * @param messageKey | |
141 | * @return | |
142 | */ | |
143 | public FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey) { | |
144 | 0 | return addField(section, fieldKey, messageKey, null, null); |
145 | } | |
146 | ||
147 | /** | |
148 | * Adds a field with the field key specified to the passed in section. | |
149 | * Returns the generated FieldDescriptor. Uses the message key provided to generate the field label. | |
150 | * The widget is not autogenerated based on the metadata in the defined model definition, but instead | |
151 | * the passed in widget is used. The widget must be a type that is compatible with the default bindings | |
152 | * (such as being a widget which implements HasText or HasValue), unless a custom binding is set on the | |
153 | * returned FieldDescriptor from this method manually. | |
154 | * | |
155 | * Note: It also is acceptable to not use this helper method and add the FieldDescriptor directly | |
156 | * to the section | |
157 | * | |
158 | * @param section | |
159 | * @param fieldKey | |
160 | * @param messageKey | |
161 | * @param widget | |
162 | * @return | |
163 | */ | |
164 | public FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget) { | |
165 | 0 | return addField(section, fieldKey, messageKey, widget, null); |
166 | } | |
167 | ||
168 | /** | |
169 | * Adds a field with the field key specified to the passed in section. | |
170 | * Returns the generated FieldDescriptor. Uses the message key provided to generate the field label. | |
171 | * The widget will be auto generated in field descriptor based on the field's metadata in the | |
172 | * model definition defined in this configurer - using the default widget factory. The fieldKey passed | |
173 | * in MUST match a logical path in the metadata (ex. proposal/proposalTitle, etc.). The parentPath | |
174 | * will be concatenated onto the front of the fieldKey. | |
175 | * | |
176 | * Note: It also is acceptable to not use this helper method and add the FieldDescriptor directly | |
177 | * to the section | |
178 | * | |
179 | * @param section | |
180 | * @param fieldKey | |
181 | * @param messageKey | |
182 | * @param parentPath | |
183 | * @return | |
184 | */ | |
185 | public FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, String parentPath) { | |
186 | 0 | return addField(section, fieldKey, messageKey, null, parentPath); |
187 | } | |
188 | ||
189 | /** | |
190 | * Adds a field with the field key specified to the passed in section. | |
191 | * Returns the generated FieldDescriptor. Uses the message key provided to generate the field label. | |
192 | * The widget is not autogenerated based on the metadata in the defined model definition, but instead | |
193 | * the passed in widget is used. The widget must be a type that is compatible with the default bindings | |
194 | * (such as being a widget which implements HasText or HasValue), unless a custom binding is set on the | |
195 | * returned FieldDescriptor from this method manually. The parentPath | |
196 | * will be concatenated onto the front of the fieldKey. | |
197 | * | |
198 | * Note: It also is acceptable to not use this helper method and add the FieldDescriptor directly | |
199 | * to the section | |
200 | * | |
201 | * @param section | |
202 | * @param fieldKey | |
203 | * @param messageKey | |
204 | * @param widget | |
205 | * @param parentPath | |
206 | * @return | |
207 | */ | |
208 | public FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget, String parentPath) { | |
209 | 0 | QueryPath path = QueryPath.concat(parentPath, fieldKey); |
210 | 0 | Metadata meta = modelDefinition.getMetadata(path); |
211 | ||
212 | 0 | FieldDescriptor fd = new FieldDescriptor(path.toString(), messageKey, meta); |
213 | 0 | if (widget != null) { |
214 | 0 | fd.setFieldWidget(widget); |
215 | } | |
216 | 0 | section.addField(fd); |
217 | 0 | return fd; |
218 | } | |
219 | ||
220 | /** | |
221 | * Read only variant of the corresponding addField method. This method will generate the read only version | |
222 | * of the widget from the metadata found in the model definition that matches the fieldKey. | |
223 | * | |
224 | * @param section | |
225 | * @param fieldKey | |
226 | * @return | |
227 | */ | |
228 | public FieldDescriptor addReadOnlyField(Section section, String fieldKey) { | |
229 | 0 | return addReadOnlyField(section, fieldKey, null, null, null); |
230 | } | |
231 | ||
232 | /** | |
233 | * Read only variant of the corresponding addField method. This method will generate the read only version | |
234 | * of the widget from the metadata found in the model definition that matches the fieldKey. | |
235 | * | |
236 | * @param section | |
237 | * @param fieldKey | |
238 | * @param messageKey | |
239 | * @return | |
240 | */ | |
241 | public FieldDescriptor addReadOnlyField(Section section, String fieldKey, MessageKeyInfo messageKey) { | |
242 | 0 | return addReadOnlyField(section, fieldKey, messageKey, null, null); |
243 | } | |
244 | ||
245 | /** | |
246 | * Read only variant of the corresponding addField method. Uses widget passed in. | |
247 | * | |
248 | * @param section | |
249 | * @param fieldKey | |
250 | * @param messageKey | |
251 | * @param widget | |
252 | * @return | |
253 | */ | |
254 | public FieldDescriptor addReadOnlyField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget) { | |
255 | 0 | return addReadOnlyField(section, fieldKey, messageKey, widget, null); |
256 | } | |
257 | ||
258 | /** | |
259 | * Read only variant of the corresponding addField method. This method will generate the read only version | |
260 | * of the widget from the metadata found in the model definition that matches the fieldKey. | |
261 | * | |
262 | * @param section | |
263 | * @param fieldKey | |
264 | * @param messageKey | |
265 | * @param parentPath | |
266 | * @return | |
267 | */ | |
268 | public FieldDescriptor addReadOnlyField(Section section, String fieldKey, MessageKeyInfo messageKey, String parentPath) { | |
269 | 0 | return addReadOnlyField(section, fieldKey, messageKey, null, parentPath); |
270 | } | |
271 | ||
272 | /** | |
273 | * Read only variant of the corresponding addField method. Uses widget passed in. | |
274 | * | |
275 | * @param section | |
276 | * @param fieldKey | |
277 | * @param messageKey | |
278 | * @param widget | |
279 | * @param parentPath | |
280 | * @return | |
281 | */ | |
282 | public FieldDescriptor addReadOnlyField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget, String parentPath) { | |
283 | 0 | QueryPath path = QueryPath.concat(parentPath, fieldKey); |
284 | 0 | Metadata meta = modelDefinition.getMetadata(path); |
285 | ||
286 | 0 | FieldDescriptor fd = new FieldDescriptorReadOnly(path.toString(), messageKey, meta); |
287 | 0 | if (widget != null) { |
288 | 0 | fd.setFieldWidget(widget); |
289 | } | |
290 | 0 | section.addField(fd); |
291 | 0 | return fd; |
292 | } | |
293 | ||
294 | /** | |
295 | * The initial state of the objects for the screen | |
296 | * | |
297 | * @return | |
298 | */ | |
299 | public String getState() { | |
300 | 0 | return state; |
301 | } | |
302 | ||
303 | public void setState(String state) { | |
304 | 0 | this.state = state; |
305 | 0 | } |
306 | ||
307 | public String getNextState() { | |
308 | 0 | return nextState; |
309 | } | |
310 | ||
311 | public void setNextState(String nextState) { | |
312 | 0 | this.nextState = nextState; |
313 | 0 | } |
314 | } |