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 import com.google.gwt.core.client.GWT;
19 import com.google.gwt.event.dom.client.BlurEvent;
20 import com.google.gwt.event.dom.client.BlurHandler;
21 import com.google.gwt.event.dom.client.HasBlurHandlers;
22 import com.google.gwt.user.client.ui.Widget;
23 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityGroup;
24 import org.kuali.student.common.ui.client.mvc.Callback;
25 import org.kuali.student.common.ui.client.mvc.HasFocusLostCallbacks;
26 import org.kuali.student.common.ui.client.widgets.KSLabel;
27 import org.kuali.student.common.ui.client.widgets.list.HasSelectionChangeHandlers;
28 import org.kuali.student.common.ui.client.widgets.list.KSCheckBoxList;
29 import org.kuali.student.common.ui.client.widgets.list.KSSelectedList;
30 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent;
31 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler;
32 import org.kuali.student.common.ui.client.widgets.search.KSPicker;
33
34
35
36
37
38
39
40 public class ValidationEventBindingImpl implements ValidationEventBinding {
41
42 public void bind(final FieldDescriptor fd) {
43 Widget w = fd.getFieldWidget();
44
45 if (w instanceof HasSelectionChangeHandlers) {
46 ((HasSelectionChangeHandlers) w).addSelectionChangeHandler(new SelectionChangeHandler() {
47 @Override
48 public void onSelectionChange(SelectionChangeEvent event) {
49 if (event.isUserInitiated()) {
50 processValidationEvent(fd);
51 }
52 }
53 });
54 } else if(w instanceof KSPicker && ((KSPicker)w).getInputWidget() instanceof HasSelectionChangeHandlers){
55 ((KSPicker)w).addSelectionChangeHandler(new SelectionChangeHandler() {
56 @Override
57 public void onSelectionChange(SelectionChangeEvent event) {
58 if(event.isUserInitiated()){
59 processValidationEvent(fd);
60 }
61 }
62 });
63 } else if (w instanceof HasBlurHandlers) {
64 ((HasBlurHandlers) w).addBlurHandler(new BlurHandler() {
65 public void onBlur(BlurEvent event) {
66 processValidationEvent(fd);
67 }
68 });
69 } else if (w instanceof HasFocusLostCallbacks) {
70 ((HasFocusLostCallbacks) w).addFocusLostCallback(new Callback<Boolean>() {
71 @Override
72 public void exec(Boolean result) {
73 processValidationEvent(fd);
74 }
75 });
76 } else if (w instanceof KSLabel
77 || w instanceof org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite
78 || w instanceof MultiplicityGroup) {
79
80 } else {
81 GWT.log("The field with key: " + fd.getFieldKey() +
82 " does not use a widget which implements an interface that can perform on the fly validation", null);
83 }
84
85 if (w instanceof KSSelectedList && !((KSSelectedList)w).getConfig().isRepeating) {
86 ((HasFocusLostCallbacks) w).addFocusLostCallback(new Callback<Boolean>() {
87 @Override
88 public void exec(Boolean result) {
89 processValidationEvent(fd);
90 }
91 });
92 }
93
94 }
95
96 private void processValidationEvent(FieldDescriptor fieldDescriptor) {
97 fieldDescriptor.setHasHadFocus(true);
98 fieldDescriptor.getValidationRequestCallback().exec(true);
99 }
100 }