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