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