Coverage Report - org.kuali.student.lum.program.client.major.edit.MajorInformationEditConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
MajorInformationEditConfiguration
0%
0/66
0%
0/2
1.357
MajorInformationEditConfiguration$DiplomaBinding
0%
0/15
0%
0/10
1.357
 
 1  
 package org.kuali.student.lum.program.client.major.edit;
 2  
 
 3  
 import org.kuali.student.common.assembly.data.Metadata;
 4  
 import org.kuali.student.common.assembly.data.QueryPath;
 5  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 6  
 import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport;
 7  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityConfiguration;
 8  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.HorizontalSection;
 9  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.MultiplicitySection;
 10  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
 11  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
 12  
 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
 13  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 14  
 import org.kuali.student.common.ui.client.widgets.KSCharCount;
 15  
 import org.kuali.student.common.ui.client.widgets.KSTextBox;
 16  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
 17  
 import org.kuali.student.common.ui.client.widgets.search.KSPicker;
 18  
 import org.kuali.student.common.ui.client.widgets.search.SearchPanel;
 19  
 import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
 20  
 import org.kuali.student.lum.program.client.ProgramConstants;
 21  
 import org.kuali.student.lum.program.client.ProgramSections;
 22  
 import org.kuali.student.lum.program.client.properties.ProgramProperties;
 23  
 
 24  
 import com.google.gwt.user.client.ui.Widget;
 25  
 
 26  
 /**
 27  
  * @author Igor
 28  
  */
 29  
 public class MajorInformationEditConfiguration extends AbstractSectionConfiguration {
 30  
 
 31  0
     public MajorInformationEditConfiguration() {
 32  0
         rootSection = new VerticalSectionView(ProgramSections.PROGRAM_DETAILS_EDIT, ProgramProperties.get().program_menu_sections_programInformation(), ProgramConstants.PROGRAM_MODEL_ID);
 33  0
     }
 34  
 
 35  
     @Override
 36  
     protected void buildLayout() {
 37  0
         HorizontalSection horizontalSection = new HorizontalSection();
 38  0
         horizontalSection.addSection(createLeftSection());
 39  0
         horizontalSection.addSection(createRightSection());
 40  0
         rootSection.addSection(horizontalSection);
 41  0
     }
 42  
 
 43  
     private VerticalSection createLeftSection() {
 44  0
         VerticalSection section = new VerticalSection();
 45  0
         section.addSection(createKeyProgramInformationSection());
 46  0
         section.addSection(createProgramTitleSection());
 47  0
         section.addSection(createDatesSection());
 48  0
         section.addSection(createOtherInformationSection());
 49  0
         return section;
 50  
     }
 51  
 
 52  
     private VerticalSection createRightSection() {
 53  0
         VerticalSection section = new VerticalSection();
 54  0
         section.addStyleName("readOnlySection");
 55  0
         section.addSection(createReadOnlySection());
 56  0
         return section;
 57  
     }
 58  
 
 59  
     private VerticalSection createKeyProgramInformationSection() {
 60  0
         VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(ProgramProperties.get().programInformation_identifyingDetails()));
 61  0
         configurer.addField(section, ProgramConstants.CODE, new MessageKeyInfo(ProgramProperties.get().programInformation_code()));
 62  0
         configurer.addField(section, ProgramConstants.PROGRAM_CLASSIFICATION, new MessageKeyInfo(ProgramProperties.get().programInformation_classification()));
 63  0
         configurer.addField(section, ProgramConstants.DEGREE_TYPE, new MessageKeyInfo(ProgramProperties.get().programInformation_degreeType()));
 64  0
         return section;
 65  
     }
 66  
 
 67  
     private VerticalSection createProgramTitleSection() {
 68  0
         VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(ProgramProperties.get().programInformation_programTitle()));
 69  0
         configurer.addField(section, ProgramConstants.LONG_TITLE, new MessageKeyInfo(ProgramProperties.get().programInformation_titleFull()));
 70  0
         configurer.addField(section, ProgramConstants.SHORT_TITLE, new MessageKeyInfo(ProgramProperties.get().programInformation_titleShort()), new KSCharCount(configurer.getModelDefinition().getMetadata(QueryPath.parse(ProgramConstants.SHORT_TITLE))));
 71  0
         configurer.addField(section, ProgramConstants.TRANSCRIPT, new MessageKeyInfo(ProgramProperties.get().programInformation_titleTranscript()), new KSCharCount(configurer.getModelDefinition().getMetadata(QueryPath.parse(ProgramConstants.TRANSCRIPT))));
 72  0
         configurer.addField(section, ProgramConstants.DIPLOMA, new MessageKeyInfo(ProgramProperties.get().programInformation_titleDiploma())).setWidgetBinding(new DiplomaBinding());
 73  0
         return section;
 74  
     }
 75  
 
 76  
     private VerticalSection createDatesSection() {
 77  0
         VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(ProgramProperties.get().programInformation_dates()));
 78  0
         configurer.addField(section, ProgramConstants.START_TERM, new MessageKeyInfo(ProgramProperties.get().programInformation_startTerm()));
 79  0
         configurer.addField(section, ProgramConstants.END_INSTITUTIONAL_ADMIT_TERM, new MessageKeyInfo(ProgramProperties.get().programInformation_admitTerm()));
 80  0
         configurer.addField(section, ProgramConstants.END_PROGRAM_ENTRY_TERM, new MessageKeyInfo(ProgramProperties.get().programInformation_entryTerm()));
 81  0
         configurer.addField(section, ProgramConstants.END_PROGRAM_ENROLL_TERM, new MessageKeyInfo(ProgramProperties.get().programInformation_enrollTerm()));
 82  0
         return section;
 83  
     }
 84  
 
 85  
     private VerticalSection createOtherInformationSection() {
 86  0
         VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(ProgramProperties.get().programInformation_otherInformation()));
 87  0
         configurer.addField(section, ProgramConstants.LOCATION, new MessageKeyInfo(ProgramProperties.get().programInformation_location()));
 88  0
         Widget cip2000Picker = configureSearch(ProgramConstants.CIP_2000);
 89  0
         configurer.addField(section, ProgramConstants.CIP_2000, new MessageKeyInfo(ProgramProperties.get().programInformation_cip2000()), cip2000Picker);
 90  0
         Widget cip2010Picker = configureSearch(ProgramConstants.CIP_2010);
 91  0
         configurer.addField(section, ProgramConstants.CIP_2010, new MessageKeyInfo(ProgramProperties.get().programInformation_cip2010()), cip2010Picker);
 92  0
         configurer.addField(section, ProgramConstants.HEGIS_CODE, new MessageKeyInfo(ProgramProperties.get().programInformation_hegis()));
 93  0
         section.addSection(createAccreditingAgenciesSection());
 94  0
         return section;
 95  
     }
 96  
 
 97  
     private VerticalSection createReadOnlySection() {
 98  0
         VerticalSection section = new VerticalSection();
 99  0
         configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_INSTITUTION_ID, new MessageKeyInfo(ProgramProperties.get().programInformation_institution()));
 100  0
         configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_TYPE_NAME, new MessageKeyInfo(ProgramProperties.get().programInformation_credentialProgram()));
 101  0
         configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_LEVEL, new MessageKeyInfo(ProgramProperties.get().programInformation_level()));
 102  0
         return section;
 103  
     }
 104  
 
 105  
     private Section createAccreditingAgenciesSection() {
 106  
 
 107  0
         Metadata metadata = configurer.getModelDefinition().getMetadata(QueryPath.concat(ProgramConstants.ACCREDITING_AGENCY));
 108  0
         MultiplicityConfiguration config = new MultiplicityConfiguration(MultiplicityConfiguration.MultiplicityType.GROUP, MultiplicityConfiguration.StyleType.TOP_LEVEL_GROUP, metadata);
 109  0
         config.setAddItemLabel(ProgramProperties.get().programInformation_addAccreditation());
 110  0
         config.setUpdateable(true);
 111  0
         config.setItemLabel(ProgramProperties.get().programInformation_accreditation());
 112  
 
 113  0
         config.setParent(ProgramConstants.ACCREDITING_AGENCY, ProgramProperties.get().programInformation_accreditations(), null, metadata);
 114  
 
 115  0
         Metadata orgMetadata = configurer.getModelDefinition().getMetadata(QueryPath.concat(ProgramConstants.ACCREDITING_AGENCY, QueryPath.getWildCard(), ProgramConstants.ORG_ID));
 116  0
         config.addField(ProgramConstants.ORG_ID, null, ProgramConstants.ACCREDITING_AGENCY, orgMetadata);
 117  
 
 118  0
         MultiplicitySection section = new MultiplicitySection(config);
 119  
 
 120  0
         return section;
 121  
     }
 122  
 
 123  
         private Widget configureSearch(String fieldKey) {            
 124  
                 Widget searchWidget;
 125  0
                 QueryPath path = QueryPath.concat(null, fieldKey);
 126  0
                 Metadata meta = configurer.getModelDefinition().getMetadata(path);
 127  
                 
 128  0
                 searchWidget = new KSPicker(meta.getInitialLookup(), meta.getAdditionalLookups());
 129  0
                 SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel();
 130  0
         if (panel != null) {
 131  0
             panel.setMutipleSelect(false);
 132  
         }
 133  
         
 134  0
                 return searchWidget;
 135  
         }
 136  
         
 137  0
     public class DiplomaBinding extends ModelWidgetBindingSupport<KSTextBox> {
 138  
         private boolean isEmpty(String value) {
 139  0
             return value == null || value.isEmpty();
 140  
         }
 141  
 
 142  
         @Override
 143  
         public void setModelValue(KSTextBox widget, DataModel model, String path) {
 144  0
             String diplomaTitle = widget.getText();
 145  0
             if (diplomaTitle != null)
 146  0
                 model.set(QueryPath.concat(null, "/" + ProgramConstants.DIPLOMA), diplomaTitle);
 147  0
         }
 148  
 
 149  
         @Override
 150  
         public void setWidgetValue(KSTextBox widget, DataModel model, String path) {
 151  0
             String diplomaTitle = model.get("/" + ProgramConstants.DIPLOMA);
 152  0
             if (isEmpty(diplomaTitle)) {
 153  0
                 String programTitle = model.get("/" + ProgramConstants.LONG_TITLE);
 154  0
                 if (!isEmpty(programTitle)){
 155  0
                     widget.setText(programTitle);
 156  
                 }else{
 157  0
                     widget.setText("");
 158  
                 }
 159  0
             } else
 160  0
                 widget.setText(diplomaTitle);
 161  0
         }
 162  
     }
 163  
 }