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