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