Coverage Report - org.kuali.student.lum.lu.ui.tools.client.configuration.CatalogBrowserConfigurer
 
Classes in this File Line Coverage Branch Coverage Complexity
CatalogBrowserConfigurer
0%
0/46
0%
0/10
1.636
CatalogBrowserConfigurer$Sections
0%
0/3
N/A
1.636
 
 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.lum.lu.ui.tools.client.configuration;
 17  
 
 18  
 import com.google.gwt.user.client.ui.Widget;
 19  
 import org.kuali.student.common.ui.client.application.Application;
 20  
 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
 21  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
 22  
 import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView;
 23  
 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
 24  
 import org.kuali.student.common.ui.client.mvc.Controller;
 25  
 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
 26  
 import org.kuali.student.common.ui.client.widgets.KSErrorDialog;
 27  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
 28  
 import org.kuali.student.core.assembly.data.Metadata;
 29  
 import org.kuali.student.core.assembly.data.QueryPath;
 30  
 import org.kuali.student.lum.lu.ui.tools.client.widgets.KSBrowser;
 31  
 
 32  
 
 33  0
 public class CatalogBrowserConfigurer {
 34  
 
 35  
         public static final String CATALOG_BROWSER_MODEL = "CatalogBrowserModel";
 36  
         private DataModelDefinition modelDefinition;
 37  
 
 38  0
         public enum Sections {
 39  0
                 BROWSE_BY_SUBJECT_AREA,
 40  0
                 BROWSE_BY_SCHOOL;
 41  
         }
 42  
 
 43  
         public void setModelDefinition (DataModelDefinition modelDefinition) {
 44  0
                 this.modelDefinition = modelDefinition;
 45  0
         }
 46  
 
 47  
         private Controller controller;
 48  
 
 49  
         public Controller getController ()
 50  
         {
 51  0
                 return controller;
 52  
         }
 53  
 
 54  
         public void setController (Controller controller)
 55  
         {
 56  0
                 this.controller = controller;
 57  0
         }
 58  
 
 59  
 
 60  
         public void configureCatalogBrowser (CatalogBrowserController layout)
 61  
         {
 62  
                 //layout.setContentTitle("Browse Course Catalog");
 63  0
                 layout.addStyleName("browseCatalog");
 64  0
                 layout.setBasicTitle("Browse Course Catalog");
 65  0
                 layout.addTab(createBrowseBySubjectAreaSection (), "Browse By Subject Area");
 66  0
                 layout.addTab(createBrowseBySchoolSection (), "Browse By School");
 67  0
                 layout.setDefaultView(Sections.BROWSE_BY_SUBJECT_AREA);
 68  0
         }
 69  
 
 70  
         private SectionView createBrowseBySubjectAreaSection ()
 71  
         {
 72  0
                 VerticalSectionView nestedSectionView =
 73  
                         new VerticalSectionView (Sections.BROWSE_BY_SUBJECT_AREA,
 74  
                                         "",
 75  
                                         CATALOG_BROWSER_MODEL);
 76  0
                 String fieldKey = CatalogBrowserConstants.FULLY_QUALIFIED_BY_SUBJECT_AREA;
 77  0
                 addField (nestedSectionView, fieldKey, null, configureKSBrowser (fieldKey));
 78  0
                 return nestedSectionView;
 79  
         }
 80  
 
 81  
         private SectionView createBrowseBySchoolSection ()
 82  
         {
 83  0
                 VerticalSectionView nestedSectionView =
 84  
                         new VerticalSectionView (Sections.BROWSE_BY_SCHOOL,
 85  
                                         "",
 86  
                                         CATALOG_BROWSER_MODEL);
 87  0
                 String fieldKey =  CatalogBrowserConstants.FULLY_QUALIFIED_BY_SCHOOL_OR_COLLEGE;
 88  0
                 addField (nestedSectionView, fieldKey, null, configureKSBrowser (fieldKey));
 89  0
                 return nestedSectionView;
 90  
         }
 91  
 
 92  
  private String formatMetadata (Metadata md, String fieldKey) {
 93  0
   String msg = "metadata for fieldKey=" + fieldKey
 94  
 //    + "\n Name=" + md.getName ()
 95  
     + "\n LabelKey=" + md.getLabelKey ()
 96  
     + "\n defaultValuePath=" + md.getDefaultValuePath ()
 97  
     + "\n LookupContextPath="  + md.getLookupContextPath ()
 98  
 //    + "\n maskForatter="  + md.getMaskFormatter ()
 99  
 //    + "\n partialMaskFormatter="  + md.getPartialMaskFormatter ()
 100  
     + "\n dataType="  + md.getDataType ()
 101  
     + "\n defaultValue="  + md.getDefaultValue ()
 102  
     + "\n WriteAccess="  + md.getWriteAccess ()
 103  
     + "\n initialLookup="  + md.getInitialLookup ()
 104  
     + "\n additionalLookups="  + md.getAdditionalLookups ()
 105  
     ;
 106  0
   if (md.getProperties () != null) {
 107  0
    msg += "\n It has " + md.getProperties ().size () + " properties: \n";
 108  0
    for (String fk : md.getProperties ().keySet ()) {
 109  0
     msg += "\n" + formatMetadata (md.getProperties ().get (fk), fk);
 110  
    }
 111  
   }
 112  0
   return msg;
 113  
  }
 114  
 
 115  
         private KSBrowser configureKSBrowser (String fieldKey)
 116  
         {
 117  0
                 QueryPath path = QueryPath.concat (null, fieldKey);
 118  0
                 Metadata md = modelDefinition.getMetadata (path);
 119  0
   if (md == null) {
 120  0
                         KSErrorDialog.show (new NullPointerException
 121  
      ("Invalid lookup configuration: missing field in metadata."
 122  
      + formatMetadata (modelDefinition.getMetadata (), fieldKey)));
 123  0
    return null;
 124  
   }
 125  0
   if (md.getInitialLookup () == null) {
 126  0
                         KSErrorDialog.show (new NullPointerException
 127  
      ("Invalid lookup configuration: missing initial lookup in metadata." 
 128  
      + formatMetadata (modelDefinition.getMetadata (), fieldKey)));
 129  0
                         return null;
 130  
                 }
 131  0
                 KSBrowser browser = new KSBrowser (md.getInitialLookup (), controller);
 132  0
                 return browser;
 133  
         }
 134  
 
 135  
         private String getLabel (String labelKey)
 136  
         {
 137  
                 // TODO make the group, type and state configurable when framework is ready
 138  
                 // tried created a new message group clusetmanagement but the entries are not read for some reason
 139  0
                 return Application.getApplicationContext ().getUILabel ("course", "course", "draft", labelKey);
 140  
         }
 141  
 
 142  
         protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget) {
 143  0
                 return addField(section, fieldKey, messageKey, widget, null);
 144  
         }
 145  
         
 146  
         protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget, String parentPath) {
 147  0
                 QueryPath path = QueryPath.concat(parentPath, fieldKey);
 148  0
                 Metadata meta = modelDefinition.getMetadata(path);
 149  
 
 150  0
                 FieldDescriptor fd = new FieldDescriptor(path.toString(), messageKey, meta);
 151  0
                 if (widget != null) {
 152  0
                         fd.setFieldWidget(widget);
 153  
                 }
 154  0
                 section.addField(fd);
 155  0
                 return fd;
 156  
         }
 157  
 
 158  
 }