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