1 | |
package org.kuali.student.lum.program.client.major.view; |
2 | |
|
3 | |
import java.util.List; |
4 | |
|
5 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptorReadOnly; |
6 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding; |
7 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; |
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.mvc.DataModel; |
11 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; |
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.core.statement.dto.StatementTypeInfo; |
16 | |
import org.kuali.student.core.statement.ui.client.widgets.rules.RulePreviewWidget; |
17 | |
import org.kuali.student.lum.common.client.configuration.AbstractControllerConfiguration; |
18 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
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.MajorManager; |
22 | |
import org.kuali.student.lum.program.client.major.edit.MajorEditController; |
23 | |
import org.kuali.student.lum.program.client.major.proposal.MajorProposalController; |
24 | |
import org.kuali.student.lum.program.client.properties.ProgramProperties; |
25 | |
import org.kuali.student.lum.program.client.requirements.ProgramRequirementsDataModel; |
26 | |
import org.kuali.student.lum.program.client.requirements.ProgramRequirementsSummaryView; |
27 | |
import org.kuali.student.lum.program.client.requirements.ProgramRequirementsViewController; |
28 | |
import org.kuali.student.lum.program.dto.ProgramRequirementInfo; |
29 | |
|
30 | |
import com.google.gwt.user.client.ui.FlowPanel; |
31 | |
|
32 | 0 | public class ProgramRequirementsViewConfiguration extends AbstractControllerConfiguration { |
33 | |
|
34 | |
private ProgramRequirementsViewController progReqcontroller; |
35 | |
|
36 | |
private ProgramRequirementsDataModel rules; |
37 | |
private ProgramRequirementsDataModel rulesComp; |
38 | |
|
39 | 0 | public ProgramRequirementsViewConfiguration(boolean special) { |
40 | 0 | progReqcontroller = new ProgramRequirementsViewController(controller, MajorManager.getEventBus(), |
41 | |
ProgramProperties.get().program_menu_sections_requirements(), ProgramSections.PROGRAM_REQUIREMENTS_VIEW, true, |
42 | |
(special ? new MajorEditableHeader(ProgramProperties.get().program_menu_sections_requirements(), ProgramSections.PROGRAM_REQUIREMENTS_EDIT) : null)); |
43 | 0 | } |
44 | |
|
45 | 0 | public ProgramRequirementsViewConfiguration(boolean special, boolean reloadRequirements) { |
46 | 0 | progReqcontroller = new ProgramRequirementsViewController(controller, MajorManager.getEventBus(), |
47 | |
ProgramProperties.get().program_menu_sections_requirements(), ProgramSections.PROGRAM_REQUIREMENTS_VIEW, true, |
48 | |
(special ? new MajorEditableHeader(ProgramProperties.get().program_menu_sections_requirements(), ProgramSections.PROGRAM_REQUIREMENTS_EDIT) : null), reloadRequirements); |
49 | 0 | } |
50 | |
|
51 | 0 | public ProgramRequirementsViewConfiguration(Controller controller, boolean special) { |
52 | 0 | String title = ProgramProperties.get().program_menu_sections_requirements(); |
53 | 0 | if (special){ |
54 | 0 | rootSection = new VerticalSectionView(ProgramSections.PROGRAM_REQUIREMENTS_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID, new MajorEditableHeader(title, ProgramSections.PROGRAM_REQUIREMENTS_EDIT)); |
55 | |
} else { |
56 | 0 | rootSection = new VerticalSectionView(ProgramSections.PROGRAM_REQUIREMENTS_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID); |
57 | |
} |
58 | 0 | this.controller = controller; |
59 | 0 | } |
60 | |
|
61 | |
@Override |
62 | |
protected void buildLayout() { |
63 | 0 | if (controller instanceof MajorProposalController || controller instanceof MajorEditController) |
64 | |
{ |
65 | 0 | VerticalSection section = new VerticalSection(); |
66 | 0 | section.addSection(createProgramRequirementsSectionEdit()); |
67 | 0 | rootSection.addSection(section); |
68 | 0 | } |
69 | |
else |
70 | 0 | rootSection = progReqcontroller.getProgramRequirementsView(); |
71 | 0 | } |
72 | |
|
73 | |
@Override |
74 | |
public void setController(Controller controller) { |
75 | 0 | this.controller = controller; |
76 | 0 | if (progReqcontroller != null) { |
77 | 0 | progReqcontroller.setParentController(controller); |
78 | |
} |
79 | 0 | } |
80 | |
|
81 | |
|
82 | |
private SummaryTableSection createProgramRequirementsSectionEdit() { |
83 | 0 | SummaryTableSection section = new SummaryTableSection((Controller) controller); |
84 | 0 | section.setEditable(false); |
85 | 0 | section.addSummaryTableFieldBlock(createProgramRequirementsSectionEditBlock()); |
86 | |
|
87 | 0 | return section; |
88 | |
} |
89 | |
|
90 | |
@SuppressWarnings("unchecked") |
91 | |
public SummaryTableFieldBlock createProgramRequirementsSectionEditBlock() { |
92 | 0 | SummaryTableFieldBlock block = new SummaryTableFieldBlock(); |
93 | 0 | if (controller instanceof MajorProposalController) |
94 | |
{ |
95 | 0 | rules = ((MajorProposalController) controller).getReqDataModel(); |
96 | 0 | rulesComp = ((MajorProposalController) controller).getReqDataModelComp(); |
97 | 0 | } else if (controller instanceof MajorEditController) |
98 | |
{ |
99 | 0 | rules = ((MajorEditController) controller).getReqDataModel(); |
100 | 0 | rulesComp = ((MajorEditController) controller).getReqDataModelComp(); |
101 | |
} |
102 | |
|
103 | |
|
104 | 0 | for (StatementTypeInfo stmtType : rules.getStmtTypes()) { |
105 | |
SummaryTableFieldRow arow; |
106 | 0 | arow = new SummaryTableFieldRow(addRequisiteField(new FlowPanel(), stmtType), |
107 | |
addRequisiteFieldComp(new FlowPanel(), stmtType)); |
108 | |
|
109 | 0 | block.addSummaryTableFieldRow(arow); |
110 | 0 | } |
111 | |
|
112 | 0 | return block; |
113 | |
} |
114 | |
|
115 | |
private FieldDescriptorReadOnly addRequisiteField(final FlowPanel panel, |
116 | |
final StatementTypeInfo stmtType) { |
117 | |
|
118 | 0 | final ModelWidgetBinding<FlowPanel> widgetBinding = new ModelWidgetBinding<FlowPanel>() { |
119 | |
|
120 | |
@Override |
121 | 0 | public void setModelValue(FlowPanel panel, DataModel model, String path) {} |
122 | |
|
123 | |
@Override |
124 | |
public void setWidgetValue(final FlowPanel panel, DataModel model, |
125 | |
String path) { |
126 | 0 | panel.clear(); |
127 | 0 | List<ProgramRequirementInfo> programRequirementInfos = rules.getProgReqInfo(stmtType.getId()); |
128 | 0 | for (ProgramRequirementInfo rule : programRequirementInfos) { |
129 | 0 | Integer internalProgReqID = rules.getInternalProgReqID(rule); |
130 | 0 | String stmtTypeId = rule.getStatement().getType(); |
131 | |
|
132 | 0 | int minCredits = (rule.getMinCredits() == null ? 0 : rule.getMinCredits()); |
133 | 0 | int maxCredits = (rule.getMaxCredits() == null ? 0 : rule.getMaxCredits()); |
134 | 0 | String plainDesc = (rule.getDescr() == null ? "" : rule.getDescr().getPlain()); |
135 | 0 | final RulePreviewWidget ruleWidget = new RulePreviewWidget(internalProgReqID, rule.getShortTitle(), |
136 | |
getTotalCreditsString(minCredits, maxCredits), plainDesc, rule.getStatement(), |
137 | |
true, ProgramRequirementsSummaryView.getCluSetWidgetList(rule.getStatement())); |
138 | 0 | panel.add(ruleWidget); |
139 | 0 | } |
140 | 0 | } |
141 | |
}; |
142 | |
|
143 | 0 | FieldDescriptorReadOnly requisiteField = new FieldDescriptorReadOnly( |
144 | |
ProgramConstants.ID, new MessageKeyInfo(stmtType.getName()), null, panel); |
145 | 0 | requisiteField.setWidgetBinding(widgetBinding); |
146 | |
|
147 | 0 | return requisiteField; |
148 | |
} |
149 | |
|
150 | |
private FieldDescriptorReadOnly addRequisiteFieldComp( |
151 | |
final FlowPanel panel, final StatementTypeInfo stmtType) { |
152 | |
|
153 | 0 | final ModelWidgetBinding<FlowPanel> widgetBinding = new ModelWidgetBinding<FlowPanel>() { |
154 | |
|
155 | |
@Override |
156 | |
public void setModelValue(FlowPanel panel, DataModel model, |
157 | |
String path) { |
158 | 0 | } |
159 | |
|
160 | |
@Override |
161 | |
public void setWidgetValue(final FlowPanel panel, DataModel model, |
162 | |
String path) { |
163 | 0 | panel.clear(); |
164 | 0 | List<ProgramRequirementInfo> programRequirementInfos = rulesComp.getProgReqInfo(stmtType.getId()); |
165 | 0 | for (ProgramRequirementInfo rule : programRequirementInfos) { |
166 | 0 | Integer internalProgReqID = rulesComp.getInternalProgReqID(rule); |
167 | 0 | String stmtTypeId = rule.getStatement().getType(); |
168 | |
|
169 | 0 | int minCredits = (rule.getMinCredits() == null ? 0 : rule.getMinCredits()); |
170 | 0 | int maxCredits = (rule.getMaxCredits() == null ? 0 : rule.getMaxCredits()); |
171 | 0 | String plainDesc = (rule.getDescr() == null ? "" : rule.getDescr().getPlain()); |
172 | 0 | final RulePreviewWidget ruleWidget = new RulePreviewWidget(internalProgReqID, rule.getShortTitle(), |
173 | |
getTotalCreditsString(minCredits, maxCredits), plainDesc, rule.getStatement(), |
174 | |
true, ProgramRequirementsSummaryView.getCluSetWidgetList(rule.getStatement())); |
175 | 0 | panel.add(ruleWidget); |
176 | 0 | } |
177 | 0 | } |
178 | |
}; |
179 | |
|
180 | 0 | FieldDescriptorReadOnly requisiteField = new FieldDescriptorReadOnly( |
181 | |
ProgramConstants.ID, new MessageKeyInfo(stmtType.getName()), null, panel); |
182 | 0 | requisiteField.setWidgetBinding(widgetBinding); |
183 | |
|
184 | 0 | return requisiteField; |
185 | |
} |
186 | |
|
187 | |
private String getTotalCreditsString(int min, int max) { |
188 | 0 | return "Expected Total Credits:" + min + "-" + max; |
189 | |
} |
190 | |
|
191 | |
} |