1 package org.kuali.student.lum.program.client.major.view;
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.FieldDescriptorReadOnly;
7 import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding;
8 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
9 import org.kuali.student.common.ui.client.mvc.Controller;
10 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
11 import org.kuali.student.common.ui.client.widgets.menus.KSListPanel;
12 import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldBlock;
13 import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldRow;
14 import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection;
15 import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
16 import org.kuali.student.lum.common.client.lo.TreeStringBinding;
17 import org.kuali.student.lum.program.client.ProgramConstants;
18 import org.kuali.student.lum.program.client.ProgramMsgConstants;
19 import org.kuali.student.lum.program.client.ProgramSections;
20 import org.kuali.student.lum.program.client.major.MajorEditableHeader;
21 import org.kuali.student.lum.program.client.major.edit.MajorEditController;
22 import org.kuali.student.lum.program.client.major.proposal.MajorProposalController;
23
24 import com.google.gwt.user.client.ui.Widget;
25
26
27
28
29 public class LearningObjectivesViewConfiguration extends AbstractSectionConfiguration {
30
31 private Controller controller = null;
32
33 public static LearningObjectivesViewConfiguration create(Configurer configurer) {
34 return new LearningObjectivesViewConfiguration(configurer);
35 }
36
37 public static LearningObjectivesViewConfiguration createSpecial(Configurer configurer, Controller controller) {
38 return new LearningObjectivesViewConfiguration(configurer, controller);
39 }
40
41 private LearningObjectivesViewConfiguration(Configurer configurer) {
42 this.setConfigurer(configurer);
43 String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_LEARNINGOBJECTIVES);
44 rootSection = new VerticalSectionView(ProgramSections.LEARNING_OBJECTIVES_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID);
45 }
46
47 private LearningObjectivesViewConfiguration(Configurer configurer, Controller controller) {
48 this.setConfigurer(configurer);
49 String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_LEARNINGOBJECTIVES);
50 rootSection = new VerticalSectionView(ProgramSections.LEARNING_OBJECTIVES_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID, new MajorEditableHeader(title, ProgramSections.LEARNING_OBJECTIVES_EDIT));
51 this.controller = controller;
52 }
53
54 protected void buildLayout() {
55 if (controller instanceof MajorProposalController || controller instanceof MajorEditController)
56 rootSection.addSection(createLearningObjectivesSectionEdit());
57 else
58 configurer.addReadOnlyField(rootSection, ProgramConstants.LEARNING_OBJECTIVES, new MessageKeyInfo(""), new KSListPanel()).setWidgetBinding(new TreeStringBinding());
59 }
60
61
62 private SummaryTableSection createLearningObjectivesSectionEdit() {
63 SummaryTableSection section = new SummaryTableSection((Controller) controller);
64 section.setEditable(false);
65 section.addSummaryTableFieldBlock(createLearningObjectivesSectionEditBlock());
66
67 return section;
68 }
69
70 public SummaryTableFieldBlock createLearningObjectivesSectionEditBlock() {
71 SummaryTableFieldBlock block = new SummaryTableFieldBlock();
72
73 block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.LEARNING_OBJECTIVES, new MessageKeyInfo(""), new KSListPanel(),
74 new KSListPanel(), null, new TreeStringBinding(), false));
75
76 return block;
77 }
78
79 protected SummaryTableFieldRow getFieldRow(String fieldKey, MessageKeyInfo messageKey) {
80 return getFieldRow(fieldKey, messageKey, null, null, null, null, false);
81 }
82
83 protected SummaryTableFieldRow getFieldRow(String fieldKey,
84 MessageKeyInfo messageKey, Widget widget, Widget widget2,
85 String parentPath, ModelWidgetBinding<?> binding, boolean optional)
86 {
87 QueryPath path = QueryPath.concat(parentPath, fieldKey);
88 Metadata meta = configurer.getModelDefinition().getMetadata(path);
89
90 FieldDescriptorReadOnly fd = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
91 if (widget != null) {
92 fd.setFieldWidget(widget);
93 }
94 if (binding != null) {
95 fd.setWidgetBinding(binding);
96 }
97 fd.setOptional(optional);
98
99 FieldDescriptorReadOnly fd2 = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
100 if (widget2 != null) {
101 fd2.setFieldWidget(widget2);
102 }
103 if (binding != null) {
104 fd2.setWidgetBinding(binding);
105 }
106 fd2.setOptional(optional);
107
108 SummaryTableFieldRow fieldRow = new SummaryTableFieldRow(fd, fd2);
109
110 return fieldRow;
111 }
112 }