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