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