Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.ValidationEventBindingImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidationEventBindingImpl
0%
0/16
0%
0/14
2.333
ValidationEventBindingImpl$1
0%
0/4
0%
0/2
2.333
ValidationEventBindingImpl$2
0%
0/3
N/A
2.333
ValidationEventBindingImpl$3
0%
0/3
N/A
2.333
ValidationEventBindingImpl$4
0%
0/3
N/A
2.333
 
 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.KSSelectedList;
 29  
 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent;
 30  
 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler;
 31  
 
 32  
 /**
 33  
  * Adds the appropriate handler to the widget contained within the FieldDescriptor for when
 34  
  * to set that the field has had focus/user interaction based on what type of widget
 35  
  *
 36  
  * @author Kuali Student Team
 37  
  */
 38  0
 public class ValidationEventBindingImpl implements ValidationEventBinding {
 39  
 
 40  
     public void bind(final FieldDescriptor fd) {
 41  0
         Widget w = fd.getFieldWidget();
 42  
 
 43  0
         if (w instanceof HasSelectionChangeHandlers) {
 44  0
             ((HasSelectionChangeHandlers) w).addSelectionChangeHandler(new SelectionChangeHandler() {
 45  
                 @Override
 46  
                 public void onSelectionChange(SelectionChangeEvent event) {
 47  0
                     if (event.isUserInitiated()) {
 48  0
                         processValidationEvent(fd);
 49  
                     }
 50  0
                 }
 51  
             });
 52  0
         } else if (w instanceof HasBlurHandlers) {
 53  0
             ((HasBlurHandlers) w).addBlurHandler(new BlurHandler() {
 54  
                 public void onBlur(BlurEvent event) {
 55  0
                     processValidationEvent(fd);
 56  0
                 }
 57  
             });
 58  0
         } else if (w instanceof HasFocusLostCallbacks) {
 59  0
             ((HasFocusLostCallbacks) w).addFocusLostCallback(new Callback<Boolean>() {
 60  
                 @Override
 61  
                 public void exec(Boolean result) {
 62  0
                     processValidationEvent(fd);
 63  0
                 }
 64  
             });
 65  0
         } else if (w instanceof KSLabel
 66  
                 || w instanceof org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite
 67  
                 || w instanceof MultiplicityGroup) {
 68  
             //Do nothing these are valid but do not fire validation events (maybe?)
 69  
         } else {
 70  0
             GWT.log("The field with key: " + fd.getFieldKey() +
 71  
                     " does not use a widget which implements an interface that can perform on the fly validation", null);
 72  
         }
 73  0
         if (w instanceof KSSelectedList) {
 74  0
             ((HasFocusLostCallbacks) w).addFocusLostCallback(new Callback<Boolean>() {
 75  
                 @Override
 76  
                 public void exec(Boolean result) {
 77  0
                     processValidationEvent(fd);
 78  0
                 }
 79  
             });
 80  
         }
 81  
 
 82  0
     }
 83  
 
 84  
     private void processValidationEvent(FieldDescriptor fieldDescriptor) {
 85  0
         fieldDescriptor.setHasHadFocus(true);
 86  0
         fieldDescriptor.getValidationRequestCallback().exec(true);
 87  0
     }
 88  
 }