1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.ui.client.configurable.mvc; |
17 |
|
|
18 |
|
|
19 |
|
import org.kuali.student.common.assembly.data.Metadata; |
20 |
|
import org.kuali.student.common.assembly.data.MetadataInterrogator; |
21 |
|
import org.kuali.student.common.ui.client.application.Application; |
22 |
|
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding; |
23 |
|
import org.kuali.student.common.ui.client.configurable.mvc.binding.MultiplicityCompositeBinding; |
24 |
|
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite; |
25 |
|
import org.kuali.student.common.ui.client.mvc.Callback; |
26 |
|
import org.kuali.student.common.ui.client.mvc.HasCrossConstraints; |
27 |
|
import org.kuali.student.common.ui.client.mvc.HasDataValue; |
28 |
|
import org.kuali.student.common.ui.client.widgets.KSCheckBox; |
29 |
|
import org.kuali.student.common.ui.client.widgets.KSTextBox; |
30 |
|
import org.kuali.student.common.ui.client.widgets.RichTextEditor; |
31 |
|
import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement; |
32 |
|
import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; |
33 |
|
import org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract; |
34 |
|
|
35 |
|
import com.google.gwt.user.client.ui.HasText; |
36 |
|
import com.google.gwt.user.client.ui.HasValue; |
37 |
|
import com.google.gwt.user.client.ui.Widget; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@author |
86 |
|
@see |
87 |
|
@see |
88 |
|
@see |
89 |
|
@see |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 199 (199) |
Complexity: 72 |
Complexity Density: 0.67 |
|
91 |
|
public class FieldDescriptor { |
92 |
|
protected String fieldKey; |
93 |
|
protected Metadata metadata; |
94 |
|
@SuppressWarnings("unchecked") |
95 |
|
private ModelWidgetBinding modelWidgetBinding; |
96 |
|
private Callback<Boolean> validationRequestCallback; |
97 |
|
private boolean dirty = false; |
98 |
|
private boolean hasHadFocus = false; |
99 |
|
private final FieldElement fieldElement; |
100 |
|
private String modelId; |
101 |
|
private MessageKeyInfo messageKey; |
102 |
|
private boolean optional = false; |
103 |
|
private boolean ignoreShowRequired = false; |
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
|
108 |
|
@param |
109 |
|
@param |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 9 |
Complexity Density: 0.64 |
|
111 |
0
|
public FieldDescriptor(String fieldKey, MessageKeyInfo messageKey, Metadata metadata) {... |
112 |
0
|
this.fieldKey = fieldKey; |
113 |
0
|
this.metadata = metadata; |
114 |
0
|
if(messageKey == null){ |
115 |
0
|
messageKey = new MessageKeyInfo(""); |
116 |
|
} |
117 |
0
|
setMessageKey(messageKey); |
118 |
0
|
fieldElement = new FieldElement(fieldKey, messageKey, createFieldWidget(), metadata); |
119 |
0
|
setupField(); |
120 |
|
|
121 |
|
|
122 |
0
|
if((getFieldWidget() instanceof HasDataValue || getFieldWidget() instanceof KSTextBox || getFieldWidget() instanceof HasValue)&&!(this instanceof FieldDescriptorReadOnly)){ |
123 |
0
|
Application.getApplicationContext().putPathToFieldMapping(null, Application.getApplicationContext().getParentPath()+fieldKey, this); |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
0
|
if(fieldElement.getFieldWidget() instanceof HasCrossConstraints){ |
128 |
0
|
HasCrossConstraints crossConstraintWidget = (HasCrossConstraints) fieldElement.getFieldWidget(); |
129 |
0
|
if(crossConstraintWidget!=null&&crossConstraintWidget.getCrossConstraints()!=null){ |
130 |
0
|
for(String path:crossConstraintWidget.getCrossConstraints()){ |
131 |
0
|
Application.getApplicationContext().putCrossConstraint(null, path, crossConstraintWidget); |
132 |
|
} |
133 |
|
} |
134 |
|
} |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
@param |
139 |
|
|
140 |
|
@param |
141 |
|
@param |
142 |
|
@param |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 8 |
Complexity Density: 0.53 |
|
144 |
0
|
public FieldDescriptor(String fieldKey, MessageKeyInfo messageKey, Metadata metadata, Widget fieldWidget){... |
145 |
0
|
this.fieldKey = fieldKey; |
146 |
0
|
this.metadata = metadata; |
147 |
0
|
if(messageKey == null){ |
148 |
0
|
messageKey = new MessageKeyInfo(""); |
149 |
|
} |
150 |
0
|
setMessageKey(messageKey); |
151 |
0
|
addStyleToWidget(fieldWidget); |
152 |
0
|
fieldElement = new FieldElement(fieldKey, messageKey, fieldWidget, metadata); |
153 |
0
|
setupField(); |
154 |
|
|
155 |
|
|
156 |
0
|
if((fieldWidget instanceof HasDataValue || fieldWidget instanceof KSTextBox) &&!(this instanceof FieldDescriptorReadOnly)){ |
157 |
0
|
Application.getApplicationContext().putPathToFieldMapping(null, Application.getApplicationContext().getParentPath()+fieldKey, this); |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
0
|
if(fieldElement.getFieldWidget() instanceof HasCrossConstraints){ |
162 |
0
|
HasCrossConstraints crossConstraintWidget = (HasCrossConstraints) fieldElement.getFieldWidget(); |
163 |
0
|
if(crossConstraintWidget!=null&&crossConstraintWidget.getCrossConstraints()!=null){ |
164 |
0
|
for(String path:crossConstraintWidget.getCrossConstraints()){ |
165 |
0
|
Application.getApplicationContext().putCrossConstraint(null, path, crossConstraintWidget); |
166 |
|
} |
167 |
|
} |
168 |
|
} |
169 |
|
|
170 |
|
} |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 4 |
Complexity Density: 1.33 |
|
172 |
0
|
protected void addStyleToWidget(Widget w){... |
173 |
0
|
if(fieldKey != null && !fieldKey.isEmpty() && w != null){ |
174 |
0
|
String style = this.fieldKey.replaceAll("/", "-"); |
175 |
0
|
w.addStyleName(style); |
176 |
|
} |
177 |
|
} |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 10 |
Complexity Density: 0.62 |
|
179 |
0
|
protected void setupField() {... |
180 |
0
|
if(metadata != null){ |
181 |
0
|
if(MetadataInterrogator.isRequired(metadata)){ |
182 |
0
|
fieldElement.setRequiredString("requiredMarker", "ks-form-module-elements-required"); |
183 |
|
} |
184 |
0
|
else if(MetadataInterrogator.isRequiredForNextState(metadata)){ |
185 |
0
|
String nextState = MetadataInterrogator.getNextState(metadata); |
186 |
0
|
if(nextState != null){ |
187 |
0
|
if(nextState.equalsIgnoreCase("SUBMITTED")){ |
188 |
0
|
fieldElement.setRequiredString("requiredOnSubmit", "ks-form-required-for-submit"); |
189 |
|
} |
190 |
0
|
else if(nextState.equalsIgnoreCase("APPROVED")){ |
191 |
0
|
fieldElement.setRequiredString("reqApproval", "ks-form-required-for-submit"); |
192 |
|
} |
193 |
0
|
else if(nextState.equalsIgnoreCase("ACTIVE")){ |
194 |
0
|
fieldElement.setRequiredString("reqActivate", "ks-form-required-for-submit"); |
195 |
|
} |
196 |
0
|
else if(nextState.equalsIgnoreCase("SUSPENDED") || |
197 |
|
nextState.equalsIgnoreCase("RETIRED")){ |
198 |
0
|
fieldElement.setRequiredString("reqDeactivate", "ks-form-required-for-submit"); |
199 |
|
} |
200 |
|
else { |
201 |
0
|
fieldElement.setRequiredString("requiredOnSubmit", "ks-form-required-for-submit"); |
202 |
|
} |
203 |
|
|
204 |
|
} |
205 |
|
} else{ |
206 |
0
|
fieldElement.clearRequiredText(); |
207 |
|
} |
208 |
|
} |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
@see |
213 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
214 |
0
|
public void hideLabel(){... |
215 |
0
|
fieldElement.hideLabel(); |
216 |
|
} |
217 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
0
|
public boolean isLabelShown(){... |
219 |
0
|
return fieldElement.isLabelShown(); |
220 |
|
} |
221 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
222 |
0
|
public FieldElement getFieldElement(){... |
223 |
0
|
return fieldElement; |
224 |
|
} |
225 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
0
|
public String getFieldKey() {... |
227 |
0
|
return fieldKey; |
228 |
|
} |
229 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
230 |
0
|
public void setFieldKey(String fieldKey) {... |
231 |
0
|
this.fieldKey = fieldKey; |
232 |
|
} |
233 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
234 |
0
|
public String getFieldLabel() {... |
235 |
0
|
return fieldElement.getFieldName(); |
236 |
|
} |
237 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
238 |
0
|
public Widget getFieldWidget(){... |
239 |
0
|
if (fieldElement.getFieldWidget() == null){ |
240 |
0
|
Widget w = createFieldWidget(); |
241 |
0
|
fieldElement.setWidget(w); |
242 |
|
} |
243 |
0
|
return fieldElement.getFieldWidget(); |
244 |
|
} |
245 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
246 |
0
|
protected Widget createFieldWidget() {... |
247 |
0
|
if (metadata == null) { |
248 |
|
|
249 |
|
|
250 |
0
|
Widget result = new KSTextBox(); |
251 |
0
|
addStyleToWidget(result); |
252 |
0
|
return result; |
253 |
|
} else { |
254 |
0
|
Widget result = DefaultWidgetFactory.getInstance().getWidget(this); |
255 |
0
|
addStyleToWidget(result); |
256 |
0
|
return result; |
257 |
|
} |
258 |
|
} |
259 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 9 |
Complexity Density: 0.56 |
|
260 |
0
|
public ModelWidgetBinding<?> getModelWidgetBinding() {... |
261 |
0
|
if(modelWidgetBinding == null){ |
262 |
0
|
if(fieldElement.getFieldWidget() instanceof RichTextEditor){ |
263 |
0
|
modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.RichTextBinding.INSTANCE; |
264 |
0
|
} else if (fieldElement.getFieldWidget() instanceof KSCheckBox){ |
265 |
0
|
modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.HasValueBinding.INSTANCE; |
266 |
0
|
} else if(fieldElement.getFieldWidget() instanceof MultiplicityComposite){ |
267 |
0
|
modelWidgetBinding = MultiplicityCompositeBinding.INSTANCE; |
268 |
0
|
} else if (fieldElement.getFieldWidget()instanceof HasText) { |
269 |
0
|
modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.HasTextBinding.INSTANCE; |
270 |
0
|
} else if (fieldElement.getFieldWidget() instanceof KSSelectItemWidgetAbstract){ |
271 |
0
|
modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.SelectItemWidgetBinding.INSTANCE; |
272 |
0
|
} else if (fieldElement.getFieldWidget() instanceof HasDataValue){ |
273 |
0
|
modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.HasDataValueBinding.INSTANCE; |
274 |
0
|
} else if (fieldElement.getFieldWidget() instanceof HasValue){ |
275 |
0
|
modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.HasValueBinding.INSTANCE; |
276 |
|
} |
277 |
|
} |
278 |
0
|
return modelWidgetBinding; |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
@param |
285 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
286 |
0
|
public void setValidationCallBack(Callback<Boolean> callback){... |
287 |
0
|
validationRequestCallback = callback; |
288 |
|
} |
289 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
290 |
0
|
public Callback<Boolean> getValidationRequestCallback(){... |
291 |
0
|
return validationRequestCallback; |
292 |
|
} |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
@return |
298 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
299 |
0
|
public boolean isDirty() {... |
300 |
0
|
return dirty; |
301 |
|
} |
302 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
303 |
0
|
public void setDirty(boolean dirty) {... |
304 |
0
|
this.dirty = dirty; |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
@return |
310 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
311 |
0
|
public boolean hasHadFocus() {... |
312 |
0
|
return hasHadFocus; |
313 |
|
} |
314 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
315 |
0
|
public void setHasHadFocus(boolean hasHadFocus) {... |
316 |
0
|
this.hasHadFocus = hasHadFocus; |
317 |
|
} |
318 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
319 |
0
|
public Metadata getMetadata() {... |
320 |
0
|
return metadata; |
321 |
|
} |
322 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
323 |
0
|
public void setMetadata(Metadata metadata) {... |
324 |
0
|
this.metadata = metadata; |
325 |
0
|
setupField(); |
326 |
|
} |
327 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
328 |
0
|
public void setFieldWidget(Widget fieldWidget) {... |
329 |
0
|
this.fieldElement.setWidget(fieldWidget); |
330 |
|
} |
331 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
332 |
0
|
public String getModelId() {... |
333 |
0
|
return modelId; |
334 |
|
} |
335 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
336 |
0
|
public void setModelId(String modelId) {... |
337 |
0
|
this.modelId = modelId; |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
@param |
345 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
346 |
0
|
public void setWidgetBinding(ModelWidgetBinding widgetBinding) {... |
347 |
0
|
this.modelWidgetBinding = widgetBinding; |
348 |
|
} |
349 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
350 |
0
|
public MessageKeyInfo getMessageKey() {... |
351 |
0
|
return messageKey; |
352 |
|
} |
353 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
354 |
0
|
public void setMessageKey(MessageKeyInfo messageKey) {... |
355 |
0
|
this.messageKey = messageKey; |
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
@param |
363 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
364 |
0
|
public void setOptional(boolean optional){... |
365 |
0
|
this.optional = optional; |
366 |
|
} |
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
372 |
0
|
public boolean isOptional(){... |
373 |
0
|
return optional; |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
@return |
378 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
379 |
0
|
public boolean isVisible() {... |
380 |
0
|
if (metadata != null){ |
381 |
0
|
return metadata.isCanView(); |
382 |
|
} else { |
383 |
0
|
return true; |
384 |
|
} |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
392 |
0
|
public void setRequired(Boolean isRequired){ ... |
393 |
0
|
fieldElement.setRequiredString("requiredMarker", "ks-form-module-elements-required"); |
394 |
0
|
fieldElement.setRequired(isRequired); |
395 |
|
|
396 |
|
|
397 |
0
|
if (isRequired){ |
398 |
0
|
getMetadata().getConstraints().get(0).setMinOccurs(1); |
399 |
|
} else { |
400 |
0
|
getMetadata().getConstraints().get(0).setMinOccurs(0); |
401 |
|
} |
402 |
|
} |
403 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
404 |
0
|
public boolean isIgnoreShowRequired() {... |
405 |
0
|
return ignoreShowRequired; |
406 |
|
} |
407 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
408 |
0
|
public void setIgnoreShowRequired(boolean ignoreShowRequired) {... |
409 |
0
|
this.ignoreShowRequired = ignoreShowRequired; |
410 |
|
} |
411 |
|
|
412 |
|
} |