Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.ValidationEventBindingImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidationEventBindingImpl
0%
0/18
0%
0/18
2.571
ValidationEventBindingImpl$1
0%
0/4
0%
0/2
2.571
ValidationEventBindingImpl$2
0%
0/4
0%
0/2
2.571
ValidationEventBindingImpl$3
0%
0/3
N/A
2.571
ValidationEventBindingImpl$4
0%
0/3
N/A
2.571
ValidationEventBindingImpl$5
0%
0/3
N/A
2.571
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 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  
  * Adds the appropriate handler to the widget contained within the FieldDescriptor for when
 36  
  * to set that the field has had focus/user interaction based on what type of widget
 37  
  *
 38  
  * @author Kuali Student Team
 39  
  */
 40  0
 public class ValidationEventBindingImpl implements ValidationEventBinding {
 41  
 
 42  
     public void bind(final FieldDescriptor fd) {
 43  0
         Widget w = fd.getFieldWidget();
 44  
 
 45  0
         if (w instanceof HasSelectionChangeHandlers) {
 46  0
             ((HasSelectionChangeHandlers) w).addSelectionChangeHandler(new SelectionChangeHandler() {
 47  
                 @Override
 48  
                 public void onSelectionChange(SelectionChangeEvent event) {
 49  0
                     if (event.isUserInitiated()) {
 50  0
                         processValidationEvent(fd);
 51  
                     }
 52  0
                 }
 53  
             });
 54  0
         } else if(w instanceof KSPicker && ((KSPicker)w).getInputWidget() instanceof HasSelectionChangeHandlers){
 55  0
             ((KSPicker)w).addSelectionChangeHandler(new SelectionChangeHandler() {
 56  
                 @Override
 57  
                 public void onSelectionChange(SelectionChangeEvent event) {
 58  0
                         if(event.isUserInitiated()){
 59  0
                                 processValidationEvent(fd);
 60  
                         }
 61  0
                 }
 62  
             });
 63  0
         } else if (w instanceof HasBlurHandlers) {
 64  0
             ((HasBlurHandlers) w).addBlurHandler(new BlurHandler() {
 65  
                 public void onBlur(BlurEvent event) {
 66  0
                     processValidationEvent(fd);
 67  0
                 }
 68  
             });
 69  0
         } else if (w instanceof HasFocusLostCallbacks) {
 70  0
             ((HasFocusLostCallbacks) w).addFocusLostCallback(new Callback<Boolean>() {
 71  
                 @Override
 72  
                 public void exec(Boolean result) {
 73  0
                     processValidationEvent(fd);
 74  0
                 }
 75  
             });
 76  0
         } else if (w instanceof KSLabel
 77  
                 || w instanceof org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite
 78  
                 || w instanceof MultiplicityGroup) {
 79  
             //Do nothing these are valid but do not fire validation events (maybe?)
 80  
         } else {
 81  0
             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  0
         if (w instanceof KSSelectedList) {
 85  0
             ((HasFocusLostCallbacks) w).addFocusLostCallback(new Callback<Boolean>() {
 86  
                 @Override
 87  
                 public void exec(Boolean result) {
 88  0
                     processValidationEvent(fd);
 89  0
                 }
 90  
             });
 91  
         }
 92  
 
 93  0
     }
 94  
 
 95  
     private void processValidationEvent(FieldDescriptor fieldDescriptor) {
 96  0
         fieldDescriptor.setHasHadFocus(true);
 97  0
         fieldDescriptor.getValidationRequestCallback().exec(true);
 98  0
     }
 99  
 }