Coverage Report - org.kuali.student.lum.lu.ui.tools.client.configuration.CatalogBrowserConfigurer
 
Classes in this File Line Coverage Branch Coverage Complexity
CatalogBrowserConfigurer
0%
0/45
0%
0/10
1.7
CatalogBrowserConfigurer$Sections
0%
0/2
N/A
1.7
 
 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 org.kuali.student.common.assembly.data.Metadata;
 19  
 import org.kuali.student.common.assembly.data.QueryPath;
 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.mvc.history.HistoryManager;
 27  
 import org.kuali.student.common.ui.client.widgets.KSErrorDialog;
 28  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
 29  
 import org.kuali.student.lum.lu.ui.tools.client.widgets.KSBrowser;
 30  
 
 31  
 import com.google.gwt.user.client.ui.Widget;
 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, BROWSE_BY_SCHOOL;
 40  
         }
 41  
 
 42  
         public void setModelDefinition(DataModelDefinition modelDefinition) {
 43  0
                 this.modelDefinition = modelDefinition;
 44  0
         }
 45  
 
 46  
         private Controller controller;
 47  
 
 48  
         public Controller getController() {
 49  0
                 return controller;
 50  
         }
 51  
 
 52  
         public void setController(Controller controller) {
 53  0
                 this.controller = controller;
 54  0
         }
 55  
 
 56  
         public void configureCatalogBrowser(CatalogBrowserController layout) {
 57  
                 // layout.setContentTitle("Browse Course Catalog");
 58  0
                 layout.addStyleName("browseCatalog");
 59  0
                 layout.setBasicTitle("Browse Course Catalog");
 60  0
                 layout.addTab(createBrowseBySubjectAreaSection(),
 61  
                                 "Browse By Subject Area");
 62  0
                 layout.addTab(createBrowseBySchoolSection(), "Browse By School");
 63  0
                 layout.setDefaultView(Sections.BROWSE_BY_SUBJECT_AREA);
 64  0
         }
 65  
 
 66  
         protected SectionView createBrowseBySubjectAreaSection() {
 67  
                 //constructor sets the attributes of the browse subject area tab
 68  0
                 VerticalSectionView nestedSectionView = 
 69  
                         new VerticalSectionView(Sections.BROWSE_BY_SUBJECT_AREA, "Browse by Subject Area", CATALOG_BROWSER_MODEL);
 70  0
                 String fieldKey = CatalogBrowserConstants.FULLY_QUALIFIED_BY_SUBJECT_AREA;
 71  0
                 addField(nestedSectionView, fieldKey, null,        configureKSBrowser(fieldKey));
 72  0
                 return nestedSectionView;
 73  
         }
 74  
 
 75  
         protected SectionView createBrowseBySchoolSection() {
 76  
                 //constructor sets the attributes of the browse school tab
 77  0
                 VerticalSectionView nestedSectionView = 
 78  
                         new VerticalSectionView(Sections.BROWSE_BY_SCHOOL, "Browse by School", CATALOG_BROWSER_MODEL);
 79  0
                 String fieldKey = CatalogBrowserConstants.FULLY_QUALIFIED_BY_SCHOOL_OR_COLLEGE;
 80  0
                 addField(nestedSectionView, fieldKey, null,        configureKSBrowser(fieldKey));
 81  0
                 return nestedSectionView;
 82  
         }
 83  
 
 84  
         private String formatMetadata(Metadata md, String fieldKey) {
 85  0
                 String msg = "metadata for fieldKey="
 86  
                                 + fieldKey
 87  
                                 // + "\n Name=" + md.getName ()
 88  
                                 + "\n LabelKey="
 89  
                                 + md.getLabelKey()
 90  
                                 + "\n defaultValuePath="
 91  
                                 + md.getDefaultValuePath()
 92  
                                 + "\n LookupContextPath="
 93  
                                 + md.getLookupContextPath()
 94  
                                 // + "\n maskForatter=" + md.getMaskFormatter ()
 95  
                                 // + "\n partialMaskFormatter=" + md.getPartialMaskFormatter ()
 96  
                                 + "\n dataType=" + md.getDataType() + "\n defaultValue="
 97  
                                 + md.getDefaultValue() + "\n WriteAccess="
 98  
                                 + md.getWriteAccess() + "\n initialLookup="
 99  
                                 + md.getInitialLookup() + "\n additionalLookups="
 100  
                                 + md.getAdditionalLookups();
 101  0
                 if (md.getProperties() != null) {
 102  0
                         msg += "\n It has " + md.getProperties().size() + " properties: \n";
 103  0
                         for (String fk : md.getProperties().keySet()) {
 104  0
                                 msg += "\n" + formatMetadata(md.getProperties().get(fk), fk);
 105  
                         }
 106  
                 }
 107  0
                 return msg;
 108  
         }
 109  
 
 110  
         private KSBrowser configureKSBrowser(String fieldKey) {
 111  0
                 QueryPath path = QueryPath.concat(null, fieldKey);
 112  0
                 Metadata md = modelDefinition.getMetadata(path);
 113  0
                 if (md == null) {
 114  0
                         KSErrorDialog.show(new NullPointerException(
 115  
                                         "Invalid lookup configuration: missing field in metadata."
 116  
                                                         + formatMetadata(modelDefinition.getMetadata(),        fieldKey)));
 117  0
                         return null;
 118  
                 }
 119  0
                 if (md.getInitialLookup() == null) {
 120  0
                         KSErrorDialog.show(new NullPointerException(
 121  
                                         "Invalid lookup configuration: missing initial lookup in metadata."
 122  
                                                         + formatMetadata(modelDefinition.getMetadata(),        fieldKey)));
 123  0
                         return null;
 124  
                 }
 125  0
                 KSBrowser browser = new KSBrowser(md.getInitialLookup(), controller);
 126  0
                 return browser;
 127  
         }
 128  
 
 129  
         protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget) {
 130  0
                 return addField(section, fieldKey, messageKey, widget, null);
 131  
         }
 132  
 
 133  
         protected FieldDescriptor addField(Section section, String fieldKey,
 134  
                         MessageKeyInfo messageKey, Widget widget, String parentPath) {
 135  0
                 QueryPath path = QueryPath.concat(parentPath, fieldKey);
 136  0
                 Metadata meta = modelDefinition.getMetadata(path);
 137  
 
 138  0
                 FieldDescriptor fd = new FieldDescriptor(path.toString(), messageKey, meta);
 139  0
                 if (widget != null) {
 140  0
                         fd.setFieldWidget(widget);
 141  
                 }
 142  0
                 section.addField(fd);
 143  0
                 return fd;
 144  
         }
 145  
 
 146  
 }