Coverage Report - org.kuali.student.lum.common.client.widgets.GradeWidget
 
Classes in this File Line Coverage Branch Coverage Complexity
GradeWidget
0%
0/27
0%
0/4
1.2
GradeWidget$1
0%
0/6
N/A
1.2
 
 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  
 package org.kuali.student.lum.common.client.widgets;
 16  
 
 17  
 import java.util.List;
 18  
 
 19  
 import org.kuali.student.common.ui.client.configurable.mvc.DefaultWidgetFactory;
 20  
 import org.kuali.student.common.ui.client.mvc.Callback;
 21  
 import org.kuali.student.common.ui.client.mvc.HasDataValue;
 22  
 import org.kuali.student.common.ui.client.widgets.KSDropDown;
 23  
 import org.kuali.student.common.ui.client.widgets.list.KSRadioButtonList;
 24  
 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent;
 25  
 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler;
 26  
 import org.kuali.student.common.ui.client.widgets.list.impl.KSRadioButtonListImpl;
 27  
 import org.kuali.student.common.ui.client.widgets.rules.AccessWidgetValue;
 28  
 import org.kuali.student.common.ui.client.widgets.search.KSPicker;
 29  
 import org.kuali.student.core.assembly.data.Data;
 30  
 import org.kuali.student.core.assembly.data.Metadata;
 31  
 
 32  
 import com.google.gwt.user.client.ui.Composite;
 33  
 import com.google.gwt.user.client.ui.FlowPanel;
 34  
 
 35  0
 public class GradeWidget extends Composite implements AccessWidgetValue, HasDataValue {
 36  
 
 37  0
     private FlowPanel layout = new FlowPanel();
 38  
     KSPicker gradeTypeWidget;
 39  0
     KSPicker gradeWidget = null;
 40  
     Metadata gradeMetadata;
 41  
 
 42  0
     public GradeWidget() {
 43  0
         this.initWidget(layout);
 44  0
     }
 45  
 
 46  
     @Override
 47  
     public void initWidget(List<Metadata> fieldsMetadata) {
 48  0
         layout.clear();
 49  0
         gradeTypeWidget = (KSPicker) DefaultWidgetFactory.getInstance().getWidget(fieldsMetadata.get(0));
 50  0
         layout.add(gradeTypeWidget);
 51  0
         gradeMetadata = fieldsMetadata.get(1);
 52  0
         setupHandlers();
 53  0
     }
 54  
 
 55  
     private void setupHandlers() {
 56  
 
 57  0
         ((KSRadioButtonList)gradeTypeWidget.getInputWidget()).addSelectionChangeHandler(new SelectionChangeHandler() {
 58  
 
 59  
             @Override
 60  
             public void onSelectionChange(SelectionChangeEvent event) {
 61  0
                 String gradeTypeSelected = ((KSRadioButtonListImpl)event.getWidget()).getSelectedItem();
 62  0
                 gradeMetadata.getInitialLookup().getParams().get(0).setDefaultValueList(null);
 63  0
                 gradeMetadata.getInitialLookup().getParams().get(0).setDefaultValueString(gradeTypeSelected);
 64  0
                 addGradeListWidget(true);
 65  0
             }
 66  
         });
 67  0
     }
 68  
 
 69  
     private void addGradeListWidget(boolean enabled) {
 70  0
         if (gradeWidget != null) {
 71  0
             layout.remove(gradeWidget);
 72  
         }
 73  0
         gradeWidget = (KSPicker) DefaultWidgetFactory.getInstance().getWidget(gradeMetadata);
 74  0
         ((KSDropDown)gradeWidget.getInputWidget()).setEnabled(enabled);
 75  0
         layout.add(gradeWidget);
 76  0
     }
 77  
 
 78  
         @Override
 79  
         public void addValueChangeCallback(Callback<Data.Value> callback) {
 80  0
         }
 81  
 
 82  
         @Override
 83  
         public void setValue(Data.Value value) {
 84  0
         addGradeListWidget(false);
 85  0
                 gradeWidget.setValue(value);        
 86  0
         }
 87  
 
 88  
     @Override
 89  
     public void getValue(Callback<String> doneSaveCallback) { 
 90  0
     }
 91  
 
 92  
     @Override
 93  
     public void setValue(String id) {
 94  0
     }
 95  
 
 96  
     @Override
 97  
     public Data.Value getValue() {
 98  0
         return (gradeWidget != null ? gradeWidget.getValue() : null);
 99  
     }
 100  
 }