Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.ValidationEventBindingImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidationEventBindingImpl
0%
0/20
0%
0/22
2.625
ValidationEventBindingImpl$1
0%
0/4
0%
0/2
2.625
ValidationEventBindingImpl$2
0%
0/4
0%
0/2
2.625
ValidationEventBindingImpl$3
0%
0/3
N/A
2.625
ValidationEventBindingImpl$4
0%
0/3
N/A
2.625
ValidationEventBindingImpl$5
0%
0/3
N/A
2.625
ValidationEventBindingImpl$6
0%
0/3
N/A
2.625
 
 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.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  
  * Adds the appropriate handler to the widget contained within the FieldDescriptor for when
 39  
  * to set that the field has had focus/user interaction based on what type of widget
 40  
  *
 41  
  * @author Kuali Student Team
 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  
             //Do nothing these are valid but do not fire validation events (maybe?)
 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  
         //Dont add focus lost to the oracle if it is repeating
 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  
 }