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.KSCheckBoxList; |
32 | |
import org.kuali.student.common.ui.client.widgets.list.KSSelectedList; |
33 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent; |
34 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler; |
35 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class ValidationEventBindingImpl implements ValidationEventBinding { |
44 | |
|
45 | |
public void bind(final FieldDescriptor fd) { |
46 | 0 | Widget w = fd.getFieldWidget(); |
47 | |
|
48 | 0 | if (w instanceof HasSelectionChangeHandlers) { |
49 | 0 | ((HasSelectionChangeHandlers) w).addSelectionChangeHandler(new SelectionChangeHandler() { |
50 | |
@Override |
51 | |
public void onSelectionChange(SelectionChangeEvent event) { |
52 | 0 | if (event.isUserInitiated()) { |
53 | 0 | processValidationEvent(fd); |
54 | |
} |
55 | 0 | } |
56 | |
}); |
57 | 0 | } else if(w instanceof KSPicker && ((KSPicker)w).getInputWidget() instanceof HasSelectionChangeHandlers){ |
58 | 0 | ((KSPicker)w).addSelectionChangeHandler(new SelectionChangeHandler() { |
59 | |
@Override |
60 | |
public void onSelectionChange(SelectionChangeEvent event) { |
61 | 0 | if(event.isUserInitiated()){ |
62 | 0 | processValidationEvent(fd); |
63 | |
} |
64 | 0 | } |
65 | |
}); |
66 | 0 | } else if (w instanceof HasBlurHandlers) { |
67 | 0 | ((HasBlurHandlers) w).addBlurHandler(new BlurHandler() { |
68 | |
public void onBlur(BlurEvent event) { |
69 | 0 | processValidationEvent(fd); |
70 | 0 | } |
71 | |
}); |
72 | 0 | } else if (w instanceof HasFocusLostCallbacks) { |
73 | 0 | ((HasFocusLostCallbacks) w).addFocusLostCallback(new Callback<Boolean>() { |
74 | |
@Override |
75 | |
public void exec(Boolean result) { |
76 | 0 | processValidationEvent(fd); |
77 | 0 | } |
78 | |
}); |
79 | 0 | } else if (w instanceof HasValueChangeHandlers) { |
80 | 0 | ((HasValueChangeHandlers<Object>) w).addValueChangeHandler(new ValueChangeHandler<Object>() { |
81 | |
|
82 | |
@Override |
83 | |
public void onValueChange(ValueChangeEvent<Object> event) { |
84 | 0 | processValidationEvent(fd); |
85 | 0 | } |
86 | |
}); |
87 | 0 | } else if (w instanceof KSLabel |
88 | |
|| w instanceof org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite |
89 | |
|| w instanceof MultiplicityGroup) { |
90 | |
|
91 | |
} else { |
92 | 0 | 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 | 0 | if (w instanceof KSSelectedList && !((KSSelectedList)w).getConfig().isRepeating) { |
97 | 0 | ((HasFocusLostCallbacks) w).addFocusLostCallback(new Callback<Boolean>() { |
98 | |
@Override |
99 | |
public void exec(Boolean result) { |
100 | 0 | processValidationEvent(fd); |
101 | 0 | } |
102 | |
}); |
103 | |
} |
104 | |
|
105 | 0 | } |
106 | |
|
107 | |
private void processValidationEvent(FieldDescriptor fieldDescriptor) { |
108 | 0 | fieldDescriptor.setHasHadFocus(true); |
109 | 0 | fieldDescriptor.getValidationRequestCallback().exec(true); |
110 | 0 | } |
111 | |
} |