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