| 1 |  |  package org.kuali.student.lum.program.client.variation.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.Configurer; | 
  | 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.sections.HorizontalSection; | 
  | 9 |  |  import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; | 
  | 10 |  |  import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; | 
  | 11 |  |  import org.kuali.student.common.ui.client.mvc.DataModel; | 
  | 12 |  |  import org.kuali.student.common.ui.client.widgets.KSTextBox; | 
  | 13 |  |  import org.kuali.student.common.ui.client.widgets.search.KSPicker; | 
  | 14 |  |  import org.kuali.student.common.ui.client.widgets.search.SearchPanel; | 
  | 15 |  |  import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration; | 
  | 16 |  |  import org.kuali.student.lum.program.client.ProgramConstants; | 
  | 17 |  |  import org.kuali.student.lum.program.client.ProgramMsgConstants; | 
  | 18 |  |  import org.kuali.student.lum.program.client.ProgramSections; | 
  | 19 |  |   | 
  | 20 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 21 |  |   | 
  | 22 |  |   | 
  | 23 |  |   | 
  | 24 |  |   | 
  | 25 |  |  public class VariationInformationEditConfiguration extends AbstractSectionConfiguration { | 
  | 26 |  |   | 
  | 27 | 0 |      public VariationInformationEditConfiguration(Configurer configurer) { | 
  | 28 | 0 |          this.setConfigurer(configurer); | 
  | 29 | 0 |          rootSection = new VerticalSectionView(ProgramSections.PROGRAM_DETAILS_EDIT, getLabel( | 
  | 30 |  |                  ProgramMsgConstants.PROGRAM_MENU_SECTIONS_PROGRAMINFORMATION), ProgramConstants.PROGRAM_MODEL_ID); | 
  | 31 | 0 |      } | 
  | 32 |  |   | 
  | 33 |  |      @Override | 
  | 34 |  |      protected void buildLayout() { | 
  | 35 | 0 |          HorizontalSection horizontalSection = new HorizontalSection(); | 
  | 36 | 0 |          horizontalSection.addSection(createLeftSection()); | 
  | 37 | 0 |          horizontalSection.addSection(createRightSection()); | 
  | 38 | 0 |          rootSection.addSection(horizontalSection); | 
  | 39 | 0 |      } | 
  | 40 |  |   | 
  | 41 |  |      private VerticalSection createLeftSection() { | 
  | 42 | 0 |          VerticalSection section = new VerticalSection(); | 
  | 43 | 0 |          section.addSection(createKeyProgramInformationSection()); | 
  | 44 | 0 |          section.addSection(createProgramTitleSection()); | 
  | 45 | 0 |          section.addSection(createDatesSection()); | 
  | 46 | 0 |          section.addSection(createOtherInformationSection()); | 
  | 47 | 0 |          return section; | 
  | 48 |  |      } | 
  | 49 |  |   | 
  | 50 |  |      private VerticalSection createRightSection() { | 
  | 51 | 0 |          VerticalSection section = new VerticalSection(); | 
  | 52 | 0 |          section.addStyleName("readOnlySection"); | 
  | 53 | 0 |          section.addSection(createReadOnlySection()); | 
  | 54 | 0 |          return section; | 
  | 55 |  |      } | 
  | 56 |  |   | 
  | 57 |  |      private VerticalSection createKeyProgramInformationSection() { | 
  | 58 | 0 |          VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_IDENTIFYINGDETAILS))); | 
  | 59 | 0 |          configurer.addField(section, ProgramConstants.CODE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CODE)); | 
  | 60 | 0 |          configurer.addField(section, ProgramConstants.PROGRAM_CLASSIFICATION, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CLASSIFICATION)); | 
  | 61 | 0 |          configurer.addField(section, ProgramConstants.DEGREE_TYPE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_DEGREETYPE)); | 
  | 62 | 0 |          return section; | 
  | 63 |  |      } | 
  | 64 |  |   | 
  | 65 |  |      private VerticalSection createProgramTitleSection() { | 
  | 66 | 0 |          VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_PROGRAMTITLE))); | 
  | 67 | 0 |          configurer.addField(section, ProgramConstants.LONG_TITLE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLEFULL)); | 
  | 68 | 0 |          configurer.addField(section, ProgramConstants.SHORT_TITLE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLESHORT)); | 
  | 69 | 0 |          configurer.addField(section, ProgramConstants.TRANSCRIPT, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLETRANSCRIPT)); | 
  | 70 | 0 |          configurer.addField(section, ProgramConstants.DIPLOMA, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLEDIPLOMA)).setWidgetBinding(new DiplomaBinding()); | 
  | 71 | 0 |          return section; | 
  | 72 |  |      } | 
  | 73 |  |   | 
  | 74 |  |      private VerticalSection createDatesSection() { | 
  | 75 | 0 |          VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_DATES))); | 
  | 76 | 0 |          configurer.addField(section, ProgramConstants.START_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_STARTTERM)); | 
  | 77 | 0 |          configurer.addField(section, ProgramConstants.END_INSTITUTIONAL_ADMIT_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_ADMITTERM)); | 
  | 78 | 0 |          configurer.addField(section, ProgramConstants.END_PROGRAM_ENTRY_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_ENTRYTERM)); | 
  | 79 | 0 |          configurer.addField(section, ProgramConstants.END_PROGRAM_ENROLL_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_ENROLLTERM)); | 
  | 80 | 0 |          return section; | 
  | 81 |  |      } | 
  | 82 |  |   | 
  | 83 |  |      private VerticalSection createOtherInformationSection() { | 
  | 84 | 0 |          VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_OTHERINFORMATION))); | 
  | 85 | 0 |          configurer.addField(section, ProgramConstants.LOCATION, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_LOCATION)); | 
  | 86 | 0 |          Widget cip2000Picker = configureSearch(ProgramConstants.CIP_2000); | 
  | 87 | 0 |          configurer.addField(section, ProgramConstants.CIP_2000, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CIP2000), cip2000Picker); | 
  | 88 | 0 |          Widget cip2010Picker = configureSearch(ProgramConstants.CIP_2010); | 
  | 89 | 0 |          configurer.addField(section, ProgramConstants.CIP_2010, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CIP2010), cip2010Picker); | 
  | 90 | 0 |          configurer.addField(section, ProgramConstants.HEGIS_CODE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_HEGIS)); | 
  | 91 | 0 |          return section; | 
  | 92 |  |      } | 
  | 93 |  |   | 
  | 94 |  |      private VerticalSection createReadOnlySection() { | 
  | 95 | 0 |          VerticalSection section = new VerticalSection(); | 
  | 96 | 0 |          configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_INSTITUTION_ID, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_INSTITUTION)); | 
  | 97 | 0 |          configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_TYPE_NAME, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CREDENTIALPROGRAM)); | 
  | 98 | 0 |          configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_LEVEL, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_LEVEL)); | 
  | 99 | 0 |          return section; | 
  | 100 |  |      } | 
  | 101 |  |   | 
  | 102 |  |          private Widget configureSearch(String fieldKey) {             | 
  | 103 |  |                  Widget searchWidget; | 
  | 104 | 0 |                  QueryPath path = QueryPath.concat(null, fieldKey); | 
  | 105 | 0 |                  Metadata meta = configurer.getModelDefinition().getMetadata(path); | 
  | 106 |  |                   | 
  | 107 | 0 |                  searchWidget = new KSPicker(meta.getInitialLookup(), meta.getAdditionalLookups()); | 
  | 108 | 0 |                  SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel(); | 
  | 109 | 0 |          if (panel != null) { | 
  | 110 | 0 |              panel.setMutipleSelect(false); | 
  | 111 |  |          } | 
  | 112 |  |           | 
  | 113 | 0 |                  return searchWidget; | 
  | 114 |  |          } | 
  | 115 |  |           | 
  | 116 | 0 |      public class DiplomaBinding extends ModelWidgetBindingSupport<KSTextBox> { | 
  | 117 |  |                  private boolean isEmpty(String value){ | 
  | 118 | 0 |                          return value == null || (value != null && "".equals(value)); | 
  | 119 |  |                  } | 
  | 120 |  |   | 
  | 121 |  |                  @Override | 
  | 122 |  |                  public void setModelValue(KSTextBox widget, DataModel model, String path) { | 
  | 123 | 0 |                          String         diplomaTitle =         widget.getText(); | 
  | 124 | 0 |                          if(diplomaTitle != null) | 
  | 125 | 0 |                                  model.set(QueryPath.concat(null, "/" + ProgramConstants.DIPLOMA), diplomaTitle); | 
  | 126 | 0 |                  } | 
  | 127 |  |   | 
  | 128 |  |                  @Override | 
  | 129 |  |                  public void setWidgetValue(KSTextBox widget, DataModel model, String path) { | 
  | 130 | 0 |                          String diplomaTitle = model.get("/" + ProgramConstants.DIPLOMA); | 
  | 131 | 0 |                          if(isEmpty(diplomaTitle)){ | 
  | 132 | 0 |                                  String programTitle = model.get("/" + ProgramConstants.LONG_TITLE); | 
  | 133 | 0 |                                  if (!isEmpty(programTitle)) | 
  | 134 | 0 |                                          widget.setText(programTitle); | 
  | 135 | 0 |                          } | 
  | 136 |  |                          else | 
  | 137 | 0 |                                  widget.setText(diplomaTitle); | 
  | 138 | 0 |                  } | 
  | 139 |  |          } | 
  | 140 |  |  } |