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