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