View Javadoc

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.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.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.ProgramMsgConstants;
20  import org.kuali.student.lum.program.client.ProgramSections;
21  import org.kuali.student.lum.program.client.major.MajorEditableHeader;
22  import org.kuali.student.lum.program.client.major.MajorManager;
23  import org.kuali.student.lum.program.client.major.edit.MajorEditController;
24  import org.kuali.student.lum.program.client.major.proposal.MajorProposalController;
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  public class ProgramRequirementsViewConfiguration extends AbstractControllerConfiguration {
33  
34      private ProgramRequirementsViewController progReqcontroller;
35  
36      private ProgramRequirementsDataModel rules;
37      private ProgramRequirementsDataModel rulesComp;
38  
39      public ProgramRequirementsViewConfiguration(Configurer configurer, boolean special) {
40          this.setConfigurer(configurer);
41          progReqcontroller = new ProgramRequirementsViewController(controller, MajorManager.getEventBus(), this.getTitle(), 
42                                      ProgramSections.PROGRAM_REQUIREMENTS_VIEW, true,
43                                      (special ? new MajorEditableHeader(this.getTitle(), ProgramSections.PROGRAM_REQUIREMENTS_EDIT) : null));
44      }
45  
46      public ProgramRequirementsViewConfiguration(Configurer configurer, boolean special, boolean reloadRequirements) {
47          this.setConfigurer(configurer);
48          progReqcontroller = new ProgramRequirementsViewController(controller, MajorManager.getEventBus(), this.getTitle(), 
49                                      ProgramSections.PROGRAM_REQUIREMENTS_VIEW, true,
50                                      (special ? new MajorEditableHeader(this.getTitle(), ProgramSections.PROGRAM_REQUIREMENTS_EDIT) : null), reloadRequirements);
51      }
52  
53      public ProgramRequirementsViewConfiguration(Configurer configurer, Controller controller, boolean special) {
54          this.setConfigurer(configurer);
55          if (special){
56          	rootSection = new VerticalSectionView(ProgramSections.PROGRAM_REQUIREMENTS_VIEW, this.getTitle(), ProgramConstants.PROGRAM_MODEL_ID, 
57          	        new MajorEditableHeader(this.getTitle(), ProgramSections.PROGRAM_REQUIREMENTS_EDIT));
58          } else {
59          	rootSection = new VerticalSectionView(ProgramSections.PROGRAM_REQUIREMENTS_VIEW, this.getTitle(), ProgramConstants.PROGRAM_MODEL_ID);        	
60          }
61          this.controller = controller;
62      }
63      
64      private String getTitle(){
65          return getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_REQUIREMENTS);
66      }
67  
68      @Override
69      protected void buildLayout() {
70      	if (controller instanceof MajorProposalController || controller instanceof MajorEditController)
71      		rootSection.addSection(createProgramRequirementsSectionEdit());
72      	else  	
73              rootSection = progReqcontroller.getProgramRequirementsView(); 	
74      }
75  
76      @Override
77      public void setController(Controller controller) {
78          this.controller = controller;
79          if (progReqcontroller != null) {
80              progReqcontroller.setParentController(controller);
81          }
82      }
83         
84      // Side-by-side comparison (when controller is not null)  
85      private SummaryTableSection createProgramRequirementsSectionEdit() { 
86        	SummaryTableSection section = new SummaryTableSection((Controller) controller);     		
87        	section.setEditable(false);
88        	section.addSummaryTableFieldBlock(createProgramRequirementsSectionEditBlock());
89  
90          return section;
91      }
92  
93      public SummaryTableFieldBlock createProgramRequirementsSectionEditBlock() {
94    		SummaryTableFieldBlock block = new SummaryTableFieldBlock();
95    		if (controller instanceof MajorProposalController)
96    		{	
97    			rules = ((MajorProposalController) controller).getReqDataModel();
98    			rulesComp = ((MajorProposalController) controller).getReqDataModelComp();
99    		} else if (controller instanceof MajorEditController)
100   		{	
101   			rules = ((MajorEditController) controller).getReqDataModel();
102   			rulesComp = ((MajorEditController) controller).getReqDataModelComp();
103   		}
104   		
105   		// one row per requirement type
106         for (StatementTypeInfo stmtType : rules.getStmtTypes()) {
107             SummaryTableFieldRow arow;
108             arow = new SummaryTableFieldRow(addRequisiteField(new FlowPanel(), stmtType), 
109             				addRequisiteFieldComp(new FlowPanel(), stmtType));
110 
111             block.addSummaryTableFieldRow(arow);
112         }
113 
114   		return block;
115   	} 
116 
117     private FieldDescriptorReadOnly addRequisiteField(final FlowPanel panel,
118             final StatementTypeInfo stmtType) {
119 
120         final ModelWidgetBinding<FlowPanel> widgetBinding = new ModelWidgetBinding<FlowPanel>() {
121 
122             @Override
123             public void setModelValue(FlowPanel panel, DataModel model, String path) {}
124 
125             @Override
126             public void setWidgetValue(final FlowPanel panel, DataModel model, //Don't place a breakpoint here:  It will stall debugging for some unknown reason!
127                     String path) {
128                 panel.clear();
129                 List<ProgramRequirementInfo> programRequirementInfos = rules.getProgReqInfo(stmtType.getId());
130                 for (ProgramRequirementInfo rule : programRequirementInfos) {
131                     Integer internalProgReqID = rules.getInternalProgReqID(rule);
132                     String stmtTypeId = rule.getStatement().getType();
133 
134                     int minCredits = (rule.getMinCredits() == null ? 0 : rule.getMinCredits());
135                     int maxCredits = (rule.getMaxCredits() == null ? 0 : rule.getMaxCredits());
136                     String plainDesc = (rule.getDescr() == null ? "" : rule.getDescr().getPlain());
137                     final RulePreviewWidget ruleWidget = new RulePreviewWidget(internalProgReqID, rule.getShortTitle(),
138                     		getTotalCreditsString(minCredits, maxCredits), plainDesc, rule.getStatement(),
139                     		true, ProgramRequirementsSummaryView.getCluSetWidgetList(rule.getStatement()));
140                     panel.add(ruleWidget);
141                 }
142             }
143         };
144 
145         FieldDescriptorReadOnly requisiteField = new FieldDescriptorReadOnly(
146         		ProgramConstants.ID, new MessageKeyInfo(stmtType.getName()), null, panel);
147         requisiteField.setWidgetBinding(widgetBinding);
148 
149         return requisiteField;
150     }
151 
152     private FieldDescriptorReadOnly addRequisiteFieldComp(
153             final FlowPanel panel, final StatementTypeInfo stmtType) {
154 
155         final ModelWidgetBinding<FlowPanel> widgetBinding = new ModelWidgetBinding<FlowPanel>() {
156 
157             @Override
158             public void setModelValue(FlowPanel panel, DataModel model,
159                     String path) {
160                 }
161 
162             @Override
163             public void setWidgetValue(final FlowPanel panel, DataModel model, //Don't place a breakpoint here:  It will stall debugging for some unknown reason!
164                     String path) {
165                 panel.clear();
166                 List<ProgramRequirementInfo> programRequirementInfos = rulesComp.getProgReqInfo(stmtType.getId());
167                 for (ProgramRequirementInfo rule : programRequirementInfos) {
168                     Integer internalProgReqID = rulesComp.getInternalProgReqID(rule);
169                     String stmtTypeId = rule.getStatement().getType();
170 
171                     int minCredits = (rule.getMinCredits() == null ? 0 : rule.getMinCredits());
172                     int maxCredits = (rule.getMaxCredits() == null ? 0 : rule.getMaxCredits());
173                     String plainDesc = (rule.getDescr() == null ? "" : rule.getDescr().getPlain());
174                     final RulePreviewWidget ruleWidget = new RulePreviewWidget(internalProgReqID, rule.getShortTitle(),
175                     		getTotalCreditsString(minCredits, maxCredits), plainDesc, rule.getStatement(),
176                     		true, ProgramRequirementsSummaryView.getCluSetWidgetList(rule.getStatement()));
177                     panel.add(ruleWidget);
178                 }
179             }
180         };
181 
182         FieldDescriptorReadOnly requisiteField = new FieldDescriptorReadOnly(
183         		ProgramConstants.ID, new MessageKeyInfo(stmtType.getName()), null, panel);
184         requisiteField.setWidgetBinding(widgetBinding);
185 
186         return requisiteField;
187     }
188     
189     private String getTotalCreditsString(int min, int max) {
190         return "Expected Total Credits:" + min + "-" + max;
191     }
192 
193 }