View Javadoc

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