Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.impl.DefaultWidgetFactoryImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultWidgetFactoryImpl
0%
0/91
0%
0/56
7.2
DefaultWidgetFactoryImpl$1
0%
0/1
N/A
7.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  
 
 16  
 package org.kuali.student.common.ui.client.configurable.mvc.impl;
 17  
 
 18  
 import org.kuali.student.common.assembly.data.LookupMetadata;
 19  
 import org.kuali.student.common.assembly.data.LookupParamMetadata;
 20  
 import org.kuali.student.common.assembly.data.Metadata;
 21  
 import org.kuali.student.common.assembly.data.MetadataInterrogator;
 22  
 import org.kuali.student.common.assembly.data.Data.DataType;
 23  
 import org.kuali.student.common.assembly.data.MetadataInterrogator.ConstraintIds;
 24  
 import org.kuali.student.common.ui.client.configurable.mvc.DefaultWidgetFactory;
 25  
 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
 26  
 import org.kuali.student.common.ui.client.configurable.mvc.WidgetConfigInfo;
 27  
 import org.kuali.student.common.ui.client.widgets.BooleanDisplayLabel;
 28  
 import org.kuali.student.common.ui.client.widgets.KSCheckBox;
 29  
 import org.kuali.student.common.ui.client.widgets.KSDatePicker;
 30  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 31  
 import org.kuali.student.common.ui.client.widgets.KSPlaceholder;
 32  
 import org.kuali.student.common.ui.client.widgets.KSRichEditor;
 33  
 import org.kuali.student.common.ui.client.widgets.KSTextArea;
 34  
 import org.kuali.student.common.ui.client.widgets.KSTextBox;
 35  
 import org.kuali.student.common.ui.client.widgets.list.KSSelectedList;
 36  
 import org.kuali.student.common.ui.client.widgets.search.KSPicker;
 37  
 
 38  
 import com.google.gwt.user.client.ui.Widget;
 39  
 
 40  
 /**
 41  
  * DefaultWidgetFactory implementation
 42  
  * @see DefaultWidgetFactory
 43  
  * @author Kuali Student Team
 44  
  *
 45  
  */
 46  0
 public class DefaultWidgetFactoryImpl extends DefaultWidgetFactory {        
 47  
 
 48  
         @Override
 49  
         public Widget getWidget(FieldDescriptor field) {
 50  0
                 return getWidget(field.getMetadata());
 51  
         }
 52  
 
 53  
         @Override
 54  
         public Widget getWidget(Metadata meta) {
 55  0
                 WidgetConfigInfo config = new WidgetConfigInfo();
 56  0
                 if (meta != null) {
 57  0
                         config.access = meta.getWriteAccess();
 58  0
                         config.isMultiLine = MetadataInterrogator.isMultilined(meta);
 59  0
                         config.isRepeating = MetadataInterrogator.isRepeating(meta);
 60  0
                         config.isRichText = MetadataInterrogator.hasConstraint(meta, ConstraintIds.RICH_TEXT);
 61  0
                         config.maxLength = MetadataInterrogator.getSmallestMaxLength(meta);
 62  0
                         config.type = meta.getDataType();
 63  0
                         config.metadata = meta;
 64  0
                         config.lookupMeta = meta.getInitialLookup();
 65  0
                         config.additionalLookups = meta.getAdditionalLookups();
 66  0
                         config.canEdit = meta.isCanEdit();
 67  0
                         config.canUnmask = meta.isCanUnmask();
 68  0
                         config.canView = meta.isCanView();
 69  
                 }
 70  0
                 return _getWidget(config);
 71  
         }
 72  
         
 73  
         @Override
 74  
         public Widget getReadOnlyWidget(Metadata meta){
 75  0
                 WidgetConfigInfo config = new WidgetConfigInfo();
 76  0
                 if (meta != null) {
 77  0
                         config.access = meta.getWriteAccess();
 78  0
                         config.isMultiLine = MetadataInterrogator.isMultilined(meta);
 79  0
                         config.isRepeating = MetadataInterrogator.isRepeating(meta);
 80  0
                         config.isRichText = MetadataInterrogator.hasConstraint(meta, ConstraintIds.RICH_TEXT);
 81  0
                         config.maxLength = MetadataInterrogator.getSmallestMaxLength(meta);
 82  0
                         config.type = meta.getDataType();
 83  0
                         config.metadata = meta;
 84  0
                         config.lookupMeta = meta.getInitialLookup();
 85  0
                         config.additionalLookups = meta.getAdditionalLookups();
 86  0
                         config.canEdit = false;
 87  0
                         config.canUnmask = meta.isCanUnmask();
 88  0
                         config.canView = meta.isCanView();
 89  
                 }
 90  0
                 return _getWidget(config);
 91  
         }
 92  
 
 93  
         @Override
 94  
         public Widget getWidget(LookupParamMetadata meta) {
 95  0
                 WidgetConfigInfo config = new WidgetConfigInfo();
 96  0
                 if (meta != null) {
 97  0
                         config.access = meta.getWriteAccess();
 98  0
                         config.type = meta.getDataType();
 99  0
                         config.lookupMeta = meta.getChildLookup();
 100  
                 }
 101  0
                 return _getWidget(config);
 102  
         }
 103  
 
 104  
         private Widget _getWidget(WidgetConfigInfo config) {
 105  0
                 Widget result = null;
 106  0
                 if(!config.canView) {
 107  0
                     result =  new KSPlaceholder();
 108  0
                     result.setVisible(config.canView);
 109  0
                 } else if(!config.canEdit && (config.lookupMeta == null || config.lookupMeta.getWidget() == null)) {
 110  0
                         if(config.type == DataType.BOOLEAN){
 111  0
                                 result = new BooleanDisplayLabel();
 112  
                         }
 113  
                         else{
 114  0
                                 result = new KSLabel();
 115  
                         }
 116  
                 } else {
 117  0
                     if (config.lookupMeta != null && config.lookupMeta.getWidget() != null) {
 118  
                             //All repeating fields should use the KSSelectedList for multiplicities (Except checkboxes)
 119  0
                 if (config.metadata != null && MetadataInterrogator.isRepeating(config.metadata) && !LookupMetadata.Widget.CHECKBOX_LIST.equals(config.lookupMeta.getWidget())) {
 120  0
                     result = new KSSelectedList(config);
 121  
                 } else {
 122  0
                     result = new KSPicker(config);
 123  
                 }
 124  
             } else {
 125  0
                 switch (config.type) {
 126  
                     case BOOLEAN:
 127  0
                         result = new KSCheckBox();
 128  0
                         break;
 129  
     
 130  
                     case DATE:
 131  
                         // fall through
 132  
     
 133  
                     case TRUNCATED_DATE:
 134  0
                         result = new KSDatePicker();
 135  0
                         break;
 136  
     
 137  
                     case DATA:
 138  0
                         if (config.isRichText) {
 139  0
                             result = new KSRichEditor();
 140  0
                             break;
 141  
                         }
 142  
                     default:
 143  0
                         if (config.isMultiLine) {
 144  0
                             result = new KSTextArea();
 145  0
                             result.addStyleName("ks-textarea-width");
 146  0
                             if(config.maxLength != null){
 147  0
                                     if(config.maxLength < 250){
 148  0
                                             result.addStyleName("ks-textarea-small-height");
 149  
                                     }
 150  0
                                     else if(config.maxLength < 500){
 151  0
                                             result.addStyleName("ks-textarea-medium-height");
 152  
                                     }
 153  
                                     else{
 154  0
                                             result.addStyleName("ks-textarea-large-height");
 155  
                                     }
 156  
                             }
 157  
                             else{
 158  0
                                     result.addStyleName("ks-textarea-medium-height");
 159  
                             }
 160  
                         } else {
 161  0
                             KSTextBox text = new KSTextBox();
 162  
                             //text.removeStyleName("KS-Textbox");
 163  0
                             if (config.maxLength != null) {
 164  0
                                 text.setMaxLength(config.maxLength);
 165  0
                                 if(config.maxLength < 5 ){
 166  0
                                         switch(config.maxLength){
 167  
                                                 case 1:
 168  0
                                                         text.addStyleName("ks-one-width");
 169  0
                                                         break;
 170  
                                                 case 2:
 171  0
                                                         text.addStyleName("ks-two-width");
 172  0
                                                         break;
 173  
                                                 case 3:
 174  0
                                                         text.addStyleName("ks-three-width");
 175  0
                                                         break;
 176  
                                                 case 4:
 177  0
                                                         text.addStyleName("ks-four-width");
 178  0
                                                         break;
 179  
                                         }
 180  
                                 }
 181  0
                                 else if(config.maxLength < 23){
 182  0
                                         text.addStyleName("ks-small-width");
 183  
                                 }
 184  0
                                 else if(config.maxLength < 35){
 185  0
                                         text.addStyleName("ks-medium-width");
 186  
                                 }
 187  0
                                 else if(config.maxLength < 60){
 188  0
                                         text.addStyleName("ks-large-width");
 189  
                                 }
 190  
                                 else{
 191  0
                                         text.addStyleName("ks-extra-large-width");
 192  
                                 }
 193  
                             }
 194  
                             else{
 195  0
                                     text.addStyleName("ks-medium-width");
 196  
                             }
 197  
                             
 198  0
                             result = text;
 199  
                         }
 200  
                     }
 201  
                     }
 202  
         }
 203  0
                 return result;
 204  
         }
 205  
 }