1 package org.kuali.student.lum.program.client.major.view;
2
3 import com.google.gwt.user.client.ui.FlexTable;
4 import com.google.gwt.user.client.ui.Widget;
5
6 import org.kuali.student.r1.common.assembly.data.Metadata;
7 import org.kuali.student.r1.common.assembly.data.QueryPath;
8 import org.kuali.student.common.ui.client.configurable.mvc.Configurer;
9 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptorReadOnly;
10 import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding;
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.Controller;
14 import org.kuali.student.common.ui.client.widgets.KSCheckBox;
15 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
16 import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldBlock;
17 import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldRow;
18 import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection;
19 import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
20 import org.kuali.student.lum.common.client.widgets.AppLocations;
21 import org.kuali.student.lum.program.client.ProgramConstants;
22 import org.kuali.student.lum.program.client.ProgramMsgConstants;
23 import org.kuali.student.lum.program.client.ProgramSections;
24 import org.kuali.student.lum.program.client.major.MajorEditableHeader;
25 import org.kuali.student.lum.program.client.major.edit.MajorEditController;
26 import org.kuali.student.lum.program.client.major.proposal.MajorProposalController;
27 import org.kuali.student.lum.program.client.variation.VariationsBinding;
28
29
30
31
32 public class SpecializationsViewConfiguration extends AbstractSectionConfiguration {
33
34 private Controller controller = null;
35
36 public static SpecializationsViewConfiguration create(Configurer configurer) {
37 return new SpecializationsViewConfiguration(configurer);
38 }
39
40 public static SpecializationsViewConfiguration createSpecial(Configurer configurer, Controller controller) {
41 return new SpecializationsViewConfiguration(configurer, controller);
42 }
43
44 private SpecializationsViewConfiguration(Configurer configurer) {
45 this.setConfigurer(configurer);
46 String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_SPECIALIZATIONS);
47 rootSection = new VerticalSectionView(ProgramSections.SPECIALIZATIONS_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID);
48 }
49
50 private SpecializationsViewConfiguration(Configurer configurer, Controller controller) {
51 this.setConfigurer(configurer);
52 String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_SPECIALIZATIONS);
53 rootSection = new VerticalSectionView(ProgramSections.SPECIALIZATIONS_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID,
54 new MajorEditableHeader(title, ProgramSections.SPECIALIZATIONS_EDIT));
55 this.controller = controller;
56 }
57
58 @Override
59 protected void buildLayout() {
60 if (controller instanceof MajorProposalController || controller instanceof MajorEditController)
61 rootSection.addSection(createSpecializationsSectionEdit());
62 else
63 {
64 VerticalSection section = new VerticalSection();
65 KSCheckBox isVariationRequiredCheckBox = new KSCheckBox(getLabel(ProgramMsgConstants.PROGRAMSPECIALIZATION_INSTRUCTIONS));
66 isVariationRequiredCheckBox.setEnabled(false);
67 configurer.addReadOnlyField(section, ProgramConstants.IS_VARIATION_REQUIRED, null, isVariationRequiredCheckBox);
68 configurer.addReadOnlyField(section, ProgramConstants.VARIATIONS, new MessageKeyInfo(""), new FlexTable()).setWidgetBinding(new VariationsBinding(AppLocations.Locations.VIEW_VARIATION.getLocation(), false));
69 rootSection.addSection(section);
70 }
71 }
72
73
74 private SummaryTableSection createSpecializationsSectionEdit() {
75 SummaryTableSection section = new SummaryTableSection((Controller) controller);
76 section.setEditable(false);
77 section.addSummaryTableFieldBlock(createSpecializationsSectionEditBlock());
78
79 return section;
80 }
81
82 public SummaryTableFieldBlock createSpecializationsSectionEditBlock() {
83 SummaryTableFieldBlock block = new SummaryTableFieldBlock();
84
85 KSCheckBox isVariationRequiredCheckBox = new KSCheckBox(getLabel(ProgramMsgConstants.PROGRAMSPECIALIZATION_INSTRUCTIONS));
86 isVariationRequiredCheckBox.setEnabled(false);
87 KSCheckBox isVariationRequiredCheckBox2 = new KSCheckBox(getLabel(ProgramMsgConstants.PROGRAMSPECIALIZATION_INSTRUCTIONS));
88 isVariationRequiredCheckBox2.setEnabled(false);
89
90 block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.IS_VARIATION_REQUIRED, null, isVariationRequiredCheckBox, isVariationRequiredCheckBox2, null, null, false));
91 block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.VARIATIONS, new MessageKeyInfo(""), new FlexTable(),
92 new FlexTable(), null, new VariationsBinding(AppLocations.Locations.VIEW_VARIATION.getLocation(), false), false));
93
94 return block;
95 }
96
97 protected SummaryTableFieldRow getFieldRow(String fieldKey, MessageKeyInfo messageKey) {
98 return getFieldRow(fieldKey, messageKey, null, null, null, null, false);
99 }
100
101 protected SummaryTableFieldRow getFieldRow(String fieldKey,
102 MessageKeyInfo messageKey, Widget widget, Widget widget2,
103 String parentPath, ModelWidgetBinding<?> binding, boolean optional)
104 {
105 QueryPath path = QueryPath.concat(parentPath, fieldKey);
106 Metadata meta = configurer.getModelDefinition().getMetadata(path);
107
108 FieldDescriptorReadOnly fd = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
109 if (widget != null) {
110 fd.setFieldWidget(widget);
111 }
112 if (binding != null) {
113 fd.setWidgetBinding(binding);
114 }
115 fd.setOptional(optional);
116
117 FieldDescriptorReadOnly fd2 = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
118 if (widget2 != null) {
119 fd2.setFieldWidget(widget2);
120 }
121 if (binding != null) {
122
123
124
125 if (binding instanceof VariationsBinding){
126 binding = new VariationsBinding(AppLocations.Locations.VIEW_VARIATION.getLocation(), false, true);
127 }
128 fd2.setWidgetBinding(binding);
129 }
130 fd2.setOptional(optional);
131
132 SummaryTableFieldRow fieldRow = new SummaryTableFieldRow(fd, fd2);
133
134 return fieldRow;
135 }
136 }