| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.lum.lu.ui.course.client.requirements; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.HashMap; | 
  | 19 |  |  import java.util.List; | 
  | 20 |  |  import java.util.Map; | 
  | 21 |  |   | 
  | 22 |  |  import org.kuali.student.common.assembly.data.Metadata; | 
  | 23 |  |  import org.kuali.student.common.ui.client.application.KSAsyncCallback; | 
  | 24 |  |  import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; | 
  | 25 |  |  import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; | 
  | 26 |  |  import org.kuali.student.common.ui.client.mvc.Callback; | 
  | 27 |  |  import org.kuali.student.common.ui.client.service.MetadataRpcService; | 
  | 28 |  |  import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync; | 
  | 29 |  |  import org.kuali.student.common.ui.client.widgets.KSProgressIndicator; | 
  | 30 |  |  import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations; | 
  | 31 |  |  import org.kuali.student.common.ui.client.widgets.field.layout.button.ActionCancelGroup; | 
  | 32 |  |  import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; | 
  | 33 |  |  import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; | 
  | 34 |  |  import org.kuali.student.common.ui.client.widgets.rules.ReqCompEditWidget; | 
  | 35 |  |  import org.kuali.student.common.ui.client.widgets.rules.ReqComponentInfoUi; | 
  | 36 |  |  import org.kuali.student.common.ui.client.widgets.rules.RuleManageWidget; | 
  | 37 |  |  import org.kuali.student.common.ui.client.widgets.rules.RulesUtil; | 
  | 38 |  |  import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo; | 
  | 39 |  |  import org.kuali.student.core.statement.dto.ReqCompFieldInfo; | 
  | 40 |  |  import org.kuali.student.core.statement.dto.ReqCompFieldTypeInfo; | 
  | 41 |  |  import org.kuali.student.core.statement.dto.ReqComponentInfo; | 
  | 42 |  |  import org.kuali.student.core.statement.dto.ReqComponentTypeInfo; | 
  | 43 |  |  import org.kuali.student.core.statement.dto.StatementOperatorTypeKey; | 
  | 44 |  |  import org.kuali.student.core.statement.dto.StatementTreeViewInfo; | 
  | 45 |  |  import org.kuali.student.lum.common.client.widgets.BuildCluSetWidget; | 
  | 46 |  |  import org.kuali.student.lum.common.client.widgets.CluSetRetrieverImpl; | 
  | 47 |  |  import org.kuali.student.lum.common.client.widgets.CourseWidget; | 
  | 48 |  |  import org.kuali.student.lum.common.client.widgets.GradeWidget; | 
  | 49 |  |  import org.kuali.student.lum.common.client.widgets.ProgramWidget; | 
  | 50 |  |  import org.kuali.student.lum.lu.dto.CluInfo; | 
  | 51 |  |  import org.kuali.student.lum.lu.ui.course.client.service.LuRpcService; | 
  | 52 |  |  import org.kuali.student.lum.lu.ui.course.client.service.LuRpcServiceAsync; | 
  | 53 |  |  import org.kuali.student.lum.program.client.rpc.StatementRpcService; | 
  | 54 |  |  import org.kuali.student.lum.program.client.rpc.StatementRpcServiceAsync; | 
  | 55 |  |   | 
  | 56 |  |  import com.google.gwt.core.client.GWT; | 
  | 57 |  |  import com.google.gwt.user.client.Window; | 
  | 58 |  |  import com.google.gwt.user.client.rpc.AsyncCallback; | 
  | 59 |  |  import com.google.gwt.user.client.ui.SimplePanel; | 
  | 60 |  |  import com.google.gwt.user.client.ui.VerticalPanel; | 
  | 61 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 62 |  |   | 
  | 63 | 0 |  public class CourseRequirementsManageView extends VerticalSectionView { | 
  | 64 |  |   | 
  | 65 | 0 |      private StatementRpcServiceAsync statementRpcServiceAsync = GWT.create(StatementRpcService.class); | 
  | 66 | 0 |      private MetadataRpcServiceAsync metadataServiceAsync = GWT.create(MetadataRpcService.class); | 
  | 67 | 0 |      private LuRpcServiceAsync luRpcServiceAsync = GWT.create(LuRpcService.class);     | 
  | 68 |  |   | 
  | 69 |  |      protected static final String TEMLATE_LANGUAGE = "en"; | 
  | 70 |  |      protected static final String RULEEDIT_TEMLATE = "KUALI.RULE"; | 
  | 71 |  |      protected static final String RULEPREVIEW_TEMLATE = "KUALI.RULE.PREVIEW"; | 
  | 72 |  |      protected static final String COMPOSITION_TEMLATE = "KUALI.RULE.COMPOSITION"; | 
  | 73 |  |      private static final String LU_NAMESPACE = "http://student.kuali.org/wsdl/lu"; | 
  | 74 |  |      private static final String CLU_NAMESPACE_URI = "{" + LU_NAMESPACE + "}cluInfo"; | 
  | 75 |  |   | 
  | 76 |  |      private CourseRequirementsViewController parentController; | 
  | 77 |  |   | 
  | 78 |  |       | 
  | 79 | 0 |      private VerticalPanel layout = new VerticalPanel(); | 
  | 80 |  |      private ReqCompEditWidget editReqCompWidget; | 
  | 81 |  |      private RuleManageWidget ruleManageWidget; | 
  | 82 | 0 |      private SimplePanel twiddlerPanel = new SimplePanel(); | 
  | 83 | 0 |      private ActionCancelGroup actionCancelButtons = new ActionCancelGroup(ButtonEnumerations.SaveCancelEnum.SAVE, ButtonEnumerations.SaveCancelEnum.CANCEL); | 
  | 84 |  |   | 
  | 85 |  |       | 
  | 86 | 0 |      private StatementTreeViewInfo rule = null; | 
  | 87 | 0 |      private boolean isInitialized = false; | 
  | 88 | 0 |      private boolean isNewRule = false; | 
  | 89 | 0 |      private ReqComponentInfo editedReqCompInfo = null; | 
  | 90 | 0 |      private static int tempStmtTreeViewInfoID = 9999; | 
  | 91 | 0 |      private Integer internalCourseReqID = null; | 
  | 92 |  |      private String originalReqCompNL; | 
  | 93 |  |      private String originalLogicExpression; | 
  | 94 |  |   | 
  | 95 |  |       | 
  | 96 | 0 |      private boolean userClickedSaveButton = false; | 
  | 97 | 0 |          private BlockingTask creatingRuleTask = new BlockingTask("Creating Rule"); | 
  | 98 |  |   | 
  | 99 |  |      public CourseRequirementsManageView(CourseRequirementsViewController parentController, Enum<?> viewEnum, String name, String modelId) { | 
  | 100 | 0 |          super(viewEnum, name, modelId); | 
  | 101 | 0 |          this.parentController = parentController; | 
  | 102 | 0 |      } | 
  | 103 |  |   | 
  | 104 |  |      @Override | 
  | 105 |  |      public void beforeShow(final Callback<Boolean> onReadyCallback) { | 
  | 106 |  |   | 
  | 107 | 0 |          retrieveAndSetupReqCompTypes();  | 
  | 108 | 0 |          if (!isInitialized) { | 
  | 109 | 0 |              setupHandlers(); | 
  | 110 | 0 |              draw(); | 
  | 111 | 0 |              isInitialized = true; | 
  | 112 |  |          } | 
  | 113 |  |   | 
  | 114 | 0 |          onReadyCallback.exec(true); | 
  | 115 | 0 |      } | 
  | 116 |  |   | 
  | 117 |  |      private void setupHandlers() { | 
  | 118 | 0 |          editReqCompWidget.setReqCompConfirmButtonClickCallback(actionButtonClickedReqCompCallback); | 
  | 119 | 0 |          editReqCompWidget.setNewReqCompSelectedCallbackCallback(newReqCompSelectedCallbackCallback); | 
  | 120 | 0 |          editReqCompWidget.setRetrieveCompositionTemplateCallback(retrieveCompositionTemplateCallback); | 
  | 121 | 0 |          editReqCompWidget.setRetrieveFieldsMetadataCallback(retrieveFieldsMetadataCallback); | 
  | 122 | 0 |          editReqCompWidget.setRetrieveCustomWidgetCallback(retrieveCustomWidgetCallback); | 
  | 123 | 0 |      } | 
  | 124 |  |   | 
  | 125 |  |      private void draw() { | 
  | 126 |  |   | 
  | 127 | 0 |          remove(layout); | 
  | 128 | 0 |          layout.clear(); | 
  | 129 |  |   | 
  | 130 |  |           | 
  | 131 | 0 |          SectionTitle title = SectionTitle.generateH3Title("Step 1: Build and Add Rules"); | 
  | 132 | 0 |          title.setStyleName("KS-Course-Requisites-Manage-Step-header1"); | 
  | 133 | 0 |          layout.add(title); | 
  | 134 |  |   | 
  | 135 | 0 |          layout.add(editReqCompWidget); | 
  | 136 |  |   | 
  | 137 |  |           | 
  | 138 | 0 |          title = SectionTitle.generateH3Title("Step 2: Combine Rules with Logic"); | 
  | 139 | 0 |          title.setStyleName("KS-Course-Requisites-Manage-Step-header2"); | 
  | 140 | 0 |          layout.add(title); | 
  | 141 |  |   | 
  | 142 | 0 |          layout.add(ruleManageWidget); | 
  | 143 |  |   | 
  | 144 |  |           | 
  | 145 | 0 |          KSProgressIndicator twiddler = new KSProgressIndicator(); | 
  | 146 | 0 |          twiddler.setVisible(false); | 
  | 147 | 0 |          twiddlerPanel.setWidget(twiddler); | 
  | 148 | 0 |          layout.add(twiddlerPanel); | 
  | 149 |  |   | 
  | 150 | 0 |          addWidget(layout); | 
  | 151 |  |   | 
  | 152 | 0 |          displaySaveButton(); | 
  | 153 | 0 |      } | 
  | 154 |  |   | 
  | 155 |  |      private void displaySaveButton() { | 
  | 156 | 0 |          actionCancelButtons.addStyleName("KS-Course-Requisites-Save-Button"); | 
  | 157 | 0 |          actionCancelButtons.addCallback(new Callback<ButtonEnumerations.ButtonEnum>(){ | 
  | 158 |  |               @Override | 
  | 159 |  |              public void exec(ButtonEnumerations.ButtonEnum result) { | 
  | 160 | 0 |                  userClickedSaveButton = (result == ButtonEnumerations.SaveCancelEnum.SAVE); | 
  | 161 | 0 |                  parentController.showView(CourseRequirementsViewController.CourseRequirementsViews.PREVIEW); | 
  | 162 | 0 |              } | 
  | 163 |  |          }); | 
  | 164 | 0 |          addWidget(actionCancelButtons); | 
  | 165 | 0 |      } | 
  | 166 |  |   | 
  | 167 |  |       | 
  | 168 |  |      public void setRuleTree(StatementTreeViewInfo stmtTreeInfo, boolean newRuleFlag, Integer internalCourseReqID) { | 
  | 169 |  |   | 
  | 170 | 0 |          if (!isInitialized) { | 
  | 171 | 0 |              editReqCompWidget = new ReqCompEditWidget(CourseRequirementsSummaryView.NEW_REQ_COMP_ID); | 
  | 172 | 0 |              ruleManageWidget = new RuleManageWidget(); | 
  | 173 | 0 |              ruleManageWidget.setReqCompEditButtonClickCallback(editReqCompCallback); | 
  | 174 | 0 |              ruleManageWidget.setRuleChangedButtonClickCallback(ruleChangedCallback); | 
  | 175 |  |          } | 
  | 176 |  |   | 
  | 177 | 0 |          this.internalCourseReqID = internalCourseReqID; | 
  | 178 | 0 |          editedReqCompInfo = null; | 
  | 179 | 0 |          userClickedSaveButton = false; | 
  | 180 | 0 |          rule = RulesUtil.clone(stmtTreeInfo); | 
  | 181 | 0 |          isNewRule = newRuleFlag; | 
  | 182 | 0 |          originalReqCompNL = getAllReqCompNLs(); | 
  | 183 |  |   | 
  | 184 |  |           | 
  | 185 | 0 |          editReqCompWidget.setupNewReqComp(); | 
  | 186 | 0 |          ruleManageWidget.redraw(rule, false); | 
  | 187 |  |          | 
  | 188 | 0 |      } | 
  | 189 |  |   | 
  | 190 |  |       | 
  | 191 |  |      public StatementTreeViewInfo getRuleTree() { | 
  | 192 | 0 |          rule = ruleManageWidget.getStatementTreeViewInfo(); | 
  | 193 | 0 |          return rule; | 
  | 194 |  |      } | 
  | 195 |  |   | 
  | 196 |  |      public boolean isNewRule() { | 
  | 197 | 0 |          return isNewRule; | 
  | 198 |  |      } | 
  | 199 |  |   | 
  | 200 |  |       | 
  | 201 | 0 |      protected Callback<ReqComponentInfo> editReqCompCallback = new Callback<ReqComponentInfo>(){ | 
  | 202 |  |          public void exec(ReqComponentInfo reqComp) { | 
  | 203 | 0 |              setEnabled(false); | 
  | 204 | 0 |              editReqCompWidget.setupExistingReqComp(reqComp); | 
  | 205 | 0 |              editedReqCompInfo = reqComp; | 
  | 206 | 0 |          } | 
  | 207 |  |      }; | 
  | 208 |  |   | 
  | 209 | 0 |      protected Callback<Boolean> ruleChangedCallback = new Callback<Boolean>(){ | 
  | 210 |  |          public void exec(Boolean ruleChanged) { | 
  | 211 | 0 |              actionCancelButtons.getButton(ButtonEnumerations.SaveCancelEnum.SAVE).setEnabled(ruleChanged); | 
  | 212 | 0 |          } | 
  | 213 |  |      }; | 
  | 214 |  |   | 
  | 215 |  |      protected void setEnabled(boolean enabled) { | 
  | 216 | 0 |          ruleManageWidget.setEnabled(enabled); | 
  | 217 | 0 |          actionCancelButtons.getButton(ButtonEnumerations.SaveCancelEnum.SAVE).setEnabled(enabled); | 
  | 218 | 0 |      } | 
  | 219 |  |   | 
  | 220 |  |      @Override | 
  | 221 |  |      public boolean isDirty() { | 
  | 222 | 0 |          if (!isInitialized) { | 
  | 223 | 0 |              return false; | 
  | 224 |  |          } | 
  | 225 |  |   | 
  | 226 |  |           | 
  | 227 | 0 |          return true; | 
  | 228 |  |   | 
  | 229 |  |           | 
  | 230 |  |   | 
  | 231 |  |   | 
  | 232 |  |   | 
  | 233 |  |   | 
  | 234 |  |           | 
  | 235 |  |         | 
  | 236 |  |         | 
  | 237 |  |         | 
  | 238 |  |           | 
  | 239 |  |          | 
  | 240 |  |      } | 
  | 241 |  |   | 
  | 242 |  |      private String getAllReqCompNLs() { | 
  | 243 | 0 |          StringBuilder NL = new StringBuilder(); | 
  | 244 | 0 |          for (StatementTreeViewInfo tree : rule.getStatements()) { | 
  | 245 | 0 |              for (ReqComponentInfo reqComp : tree.getReqComponents()) { | 
  | 246 | 0 |                  NL.append(reqComp.getNaturalLanguageTranslation()); | 
  | 247 |  |              } | 
  | 248 |  |          } | 
  | 249 | 0 |          return NL.toString(); | 
  | 250 |  |      } | 
  | 251 |  |   | 
  | 252 |  |       | 
  | 253 | 0 |      protected Callback<ReqComponentInfoUi> actionButtonClickedReqCompCallback = new Callback<ReqComponentInfoUi>(){ | 
  | 254 |  |          public void exec(final ReqComponentInfoUi reqComp) { | 
  | 255 |  |   | 
  | 256 | 0 |              editReqCompWidget.setupNewReqComp(); | 
  | 257 | 0 |              setEnabled(true); | 
  | 258 |  |   | 
  | 259 |  |               | 
  | 260 | 0 |              if (reqComp == null) { | 
  | 261 | 0 |                  return; | 
  | 262 |  |              } | 
  | 263 |  |   | 
  | 264 | 0 |              KSBlockingProgressIndicator.addTask(creatingRuleTask); | 
  | 265 |  |   | 
  | 266 |  |               | 
  | 267 | 0 |              statementRpcServiceAsync.translateReqComponentToNLs(reqComp, new String[]{RULEEDIT_TEMLATE, RULEPREVIEW_TEMLATE}, TEMLATE_LANGUAGE, new KSAsyncCallback<List<String>>() { | 
  | 268 |  |                  public void handleFailure(Throwable caught) { | 
  | 269 | 0 |                      KSBlockingProgressIndicator.removeTask(creatingRuleTask); | 
  | 270 | 0 |                      Window.alert(caught.getMessage()); | 
  | 271 | 0 |                      GWT.log("translateReqComponentToNL failed", caught); | 
  | 272 | 0 |                 } | 
  | 273 |  |   | 
  | 274 |  |                  public void onSuccess(final List<String> reqCompNL) { | 
  | 275 |  |   | 
  | 276 | 0 |                      reqComp.setNaturalLanguageTranslation(reqCompNL.get(0)); | 
  | 277 | 0 |                      reqComp.setPreviewNaturalLanguageTranslation(reqCompNL.get(1)); | 
  | 278 |  |   | 
  | 279 |  |                       | 
  | 280 | 0 |                      rule = ruleManageWidget.getStatementTreeViewInfo();   | 
  | 281 |  |   | 
  | 282 | 0 |                      if (editedReqCompInfo == null) {   | 
  | 283 | 0 |                          if (rule.getStatements() != null && !rule.getStatements().isEmpty()) { | 
  | 284 | 0 |                              StatementTreeViewInfo newStatementTreeViewInfo = new StatementTreeViewInfo(); | 
  | 285 | 0 |                              newStatementTreeViewInfo.setId(CourseRequirementsSummaryView.NEW_STMT_TREE_ID + Integer.toString(tempStmtTreeViewInfoID++)); | 
  | 286 | 0 |                              newStatementTreeViewInfo.setOperator(rule.getStatements().get(0).getOperator()); | 
  | 287 | 0 |                              newStatementTreeViewInfo.getReqComponents().add(reqComp); | 
  | 288 | 0 |                              rule.getStatements().add(newStatementTreeViewInfo); | 
  | 289 | 0 |                          } else { | 
  | 290 | 0 |                              rule.getReqComponents().add(reqComp); | 
  | 291 |  |                               | 
  | 292 | 0 |                              if (rule.getOperator() == null) { | 
  | 293 | 0 |                                  rule.setOperator(StatementOperatorTypeKey.AND); | 
  | 294 |  |                              } | 
  | 295 |  |                          } | 
  | 296 |  |                      } else {     | 
  | 297 | 0 |                          editedReqCompInfo.setNaturalLanguageTranslation(reqComp.getNaturalLanguageTranslation()); | 
  | 298 | 0 |                          editedReqCompInfo.setReqCompFields(reqComp.getReqCompFields()); | 
  | 299 | 0 |                          editedReqCompInfo.setType(reqComp.getType()); | 
  | 300 | 0 |                          editedReqCompInfo = null;   | 
  | 301 |  |                      } | 
  | 302 |  |   | 
  | 303 | 0 |                      ruleManageWidget.redraw(rule, true); | 
  | 304 | 0 |                      KSBlockingProgressIndicator.removeTask(creatingRuleTask); | 
  | 305 | 0 |                  } | 
  | 306 |  |              }); | 
  | 307 | 0 |          } | 
  | 308 |  |      }; | 
  | 309 |  |   | 
  | 310 |  |       | 
  | 311 | 0 |      protected Callback<ReqComponentInfo> newReqCompSelectedCallbackCallback = new Callback<ReqComponentInfo>(){ | 
  | 312 |  |          public void exec(final ReqComponentInfo reqComp) { | 
  | 313 | 0 |              setEnabled(false); | 
  | 314 | 0 |          } | 
  | 315 |  |      }; | 
  | 316 |  |   | 
  | 317 |  |      private void retrieveAndSetupReqCompTypes() { | 
  | 318 |  |   | 
  | 319 | 0 |          statementRpcServiceAsync.getReqComponentTypesForStatementType(rule.getType(), new KSAsyncCallback<List<ReqComponentTypeInfo>>() { | 
  | 320 |  |              public void handleFailure(Throwable cause) { | 
  | 321 | 0 |                      GWT.log("Failed to get req. component types for statement of type:" + rule.getType(), cause); | 
  | 322 | 0 |                      Window.alert("Failed to get req. component types for statement of type:" + rule.getType()); | 
  | 323 | 0 |              } | 
  | 324 |  |   | 
  | 325 |  |              public void onSuccess(final List<ReqComponentTypeInfo> reqComponentTypeInfoList) { | 
  | 326 | 0 |                  if (reqComponentTypeInfoList == null || reqComponentTypeInfoList.size() == 0) { | 
  | 327 | 0 |                      GWT.log("Missing Requirement Component Types", null); | 
  | 328 | 0 |                      Window.alert("Missing Requirement Component Types"); | 
  | 329 | 0 |                      return; | 
  | 330 |  |                  } | 
  | 331 | 0 |                  editReqCompWidget.setReqCompList(reqComponentTypeInfoList); | 
  | 332 | 0 |                  editReqCompWidget.setCustomWidgets(getCustomWidgets(reqComponentTypeInfoList));                 | 
  | 333 | 0 |              } | 
  | 334 |  |          }); | 
  | 335 | 0 |      } | 
  | 336 |  |   | 
  | 337 |  |      private Map<String, Widget> getCustomWidgets(List<ReqComponentTypeInfo> reqComponentTypeInfoList) { | 
  | 338 | 0 |          Map<String, Widget> customWidgets = new HashMap<String, Widget>(); | 
  | 339 |  |   | 
  | 340 | 0 |          for (ReqComponentTypeInfo reqCompTypeInfo : reqComponentTypeInfoList) { | 
  | 341 | 0 |              for (ReqCompFieldTypeInfo fieldTypeInfo : reqCompTypeInfo.getReqCompFieldTypeInfos()) { | 
  | 342 | 0 |                  if (RulesUtil.isGradeWidget(fieldTypeInfo.getId())) { | 
  | 343 | 0 |                      customWidgets.put("kuali.reqComponent.field.type.grade.id", new GradeWidget()); | 
  | 344 | 0 |                  } else if (RulesUtil.isCourseWidget(fieldTypeInfo.getId())) { | 
  | 345 |  |   | 
  | 346 | 0 |                      final CourseWidget courseWidget = new CourseWidget(); | 
  | 347 |  |                       | 
  | 348 | 0 |                      courseWidget.addGetCluNameCallback(new Callback() { | 
  | 349 |  |   | 
  | 350 |  |                          @Override | 
  | 351 |  |                          public void exec(Object id) { | 
  | 352 |  |   | 
  | 353 | 0 |                              luRpcServiceAsync.getCurrentVersion(CLU_NAMESPACE_URI, (String)id, new AsyncCallback<VersionDisplayInfo>() { | 
  | 354 |  |                                  @Override | 
  | 355 |  |                                  public void onFailure(Throwable throwable) { | 
  | 356 | 0 |                                      Window.alert(throwable.getMessage()); | 
  | 357 | 0 |                                      GWT.log("Failed to retrieve clu for id: '" +  "'", throwable); | 
  | 358 | 0 |                                  } | 
  | 359 |  |   | 
  | 360 |  |                                  @Override | 
  | 361 |  |                                  public void onSuccess(final VersionDisplayInfo versionInfo) { | 
  | 362 | 0 |                                      luRpcServiceAsync.getClu(versionInfo.getId(), new AsyncCallback<CluInfo>() { | 
  | 363 |  |                                          @Override | 
  | 364 |  |                                          public void onFailure(Throwable throwable) { | 
  | 365 | 0 |                                              Window.alert(throwable.getMessage()); | 
  | 366 | 0 |                                              GWT.log("Failed to retrieve clu", throwable); | 
  | 367 | 0 |                                          } | 
  | 368 |  |   | 
  | 369 |  |                                          @Override | 
  | 370 |  |                                          public void onSuccess(CluInfo cluInfo) { | 
  | 371 | 0 |                                              courseWidget.setLabelContent(cluInfo.getVersionInfo().getVersionIndId(), cluInfo.getOfficialIdentifier().getCode()); | 
  | 372 | 0 |                                          } | 
  | 373 |  |                                      }); | 
  | 374 | 0 |                                  } | 
  | 375 |  |                              }); | 
  | 376 |  |   | 
  | 377 |  |   | 
  | 378 | 0 |                          } | 
  | 379 |  |                      }); | 
  | 380 |  |   | 
  | 381 | 0 |                      customWidgets.put("kuali.reqComponent.field.type.course.clu.id", courseWidget); | 
  | 382 | 0 |                  } else if (RulesUtil.isProgramWidget(fieldTypeInfo.getId())) { | 
  | 383 | 0 |                      final ProgramWidget programWidget = new ProgramWidget(); | 
  | 384 |  |   | 
  | 385 | 0 |                      programWidget.addGetCluNameCallback(new Callback() { | 
  | 386 |  |   | 
  | 387 |  |                          @Override | 
  | 388 |  |                          public void exec(Object id) { | 
  | 389 |  |   | 
  | 390 | 0 |                              statementRpcServiceAsync.getCurrentVersion(CLU_NAMESPACE_URI, (String)id, new AsyncCallback<VersionDisplayInfo>() { | 
  | 391 |  |                                  @Override | 
  | 392 |  |                                  public void onFailure(Throwable throwable) { | 
  | 393 | 0 |                                      Window.alert(throwable.getMessage()); | 
  | 394 | 0 |                                      GWT.log("Failed to retrieve clu for id: '" +  "'", throwable); | 
  | 395 | 0 |                                  } | 
  | 396 |  |   | 
  | 397 |  |                                  @Override | 
  | 398 |  |                                  public void onSuccess(final VersionDisplayInfo versionInfo) { | 
  | 399 | 0 |                                      statementRpcServiceAsync.getClu(versionInfo.getId(), new AsyncCallback<CluInfo>() { | 
  | 400 |  |                                          @Override | 
  | 401 |  |                                          public void onFailure(Throwable throwable) { | 
  | 402 | 0 |                                              Window.alert(throwable.getMessage()); | 
  | 403 | 0 |                                              GWT.log("Failed to retrieve clu", throwable); | 
  | 404 | 0 |                                          } | 
  | 405 |  |   | 
  | 406 |  |                                          @Override | 
  | 407 |  |                                          public void onSuccess(CluInfo cluInfo) { | 
  | 408 | 0 |                                              programWidget.setLabelContent(cluInfo.getVersionInfo().getVersionIndId(), cluInfo.getOfficialIdentifier().getCode()); | 
  | 409 | 0 |                                          } | 
  | 410 |  |                                      }); | 
  | 411 | 0 |                                  } | 
  | 412 |  |                              }); | 
  | 413 | 0 |                          } | 
  | 414 |  |                      }); | 
  | 415 |  |   | 
  | 416 | 0 |                      customWidgets.put("kuali.reqComponent.field.type.program.clu.id", programWidget); | 
  | 417 | 0 |                  } | 
  | 418 |  |              } | 
  | 419 |  |          } | 
  | 420 | 0 |          return customWidgets; | 
  | 421 |  |      } | 
  | 422 |  |   | 
  | 423 |  |       | 
  | 424 | 0 |      protected Callback<ReqComponentInfo> retrieveCompositionTemplateCallback = new Callback<ReqComponentInfo>(){ | 
  | 425 |  |          public void exec(final ReqComponentInfo reqComp) { | 
  | 426 | 0 |              statementRpcServiceAsync.translateReqComponentToNL(reqComp, COMPOSITION_TEMLATE, TEMLATE_LANGUAGE, new KSAsyncCallback<String>() { | 
  | 427 |  |                  public void handleFailure(Throwable caught) { | 
  | 428 | 0 |                      Window.alert(caught.getMessage()); | 
  | 429 | 0 |                      GWT.log("translateReqComponentToNL failed for req. comp. type: '" + reqComp.getType() + "'",caught); | 
  | 430 | 0 |                  } | 
  | 431 |  |   | 
  | 432 |  |                  public void onSuccess(final String compositionTemplate) { | 
  | 433 | 0 |                      editReqCompWidget.displayFieldsStart(compositionTemplate); | 
  | 434 | 0 |                  } | 
  | 435 |  |              }); | 
  | 436 | 0 |          } | 
  | 437 |  |      }; | 
  | 438 |  |   | 
  | 439 | 0 |      protected Callback<List<String>> retrieveFieldsMetadataCallback = new Callback<List<String>>(){ | 
  | 440 |  |          public void exec(final List<String> fieldTypes) { | 
  | 441 |  |   | 
  | 442 | 0 |              if (fieldTypes.contains("kuali.reqComponent.field.type.grade.id")) { | 
  | 443 | 0 |                  fieldTypes.add("kuali.reqComponent.field.type.gradeType.id"); | 
  | 444 |  |              } | 
  | 445 |  |   | 
  | 446 | 0 |              metadataServiceAsync.getMetadataList(ReqCompFieldInfo.class.getName(), fieldTypes, null, new KSAsyncCallback<List<Metadata>>() { | 
  | 447 |  |                  public void handleFailure(Throwable caught) { | 
  | 448 | 0 |                      Window.alert(caught.getMessage()); | 
  | 449 | 0 |                      GWT.log("getMetadataList failed for req. comp. types: '" + fieldTypes.toString() + "'",caught); | 
  | 450 | 0 |                  } | 
  | 451 |  |   | 
  | 452 |  |                  public void onSuccess(final List<Metadata> metadataList) { | 
  | 453 | 0 |                      editReqCompWidget.displayFieldsEnd(metadataList); | 
  | 454 | 0 |                  } | 
  | 455 |  |              }); | 
  | 456 | 0 |          } | 
  | 457 |  |      }; | 
  | 458 |  |   | 
  | 459 | 0 |      protected Callback<String> retrieveCustomWidgetCallback = new Callback<String>(){ | 
  | 460 |  |          public void exec(final String fieldType) { | 
  | 461 | 0 |              if (RulesUtil.isCluSetWidget(fieldType)) { | 
  | 462 | 0 |                  String clusetType = "kuali.cluSet.type.Course"; | 
  | 463 | 0 |                  if (fieldType.toLowerCase().indexOf("program") > 0) { | 
  | 464 | 0 |                      clusetType = "kuali.cluSet.type.Program"; | 
  | 465 |  |                  } | 
  | 466 | 0 |                  editReqCompWidget.displayCustomWidget(fieldType, new BuildCluSetWidget(new CluSetRetrieverImpl(), clusetType, false)); | 
  | 467 |  |              } | 
  | 468 | 0 |          } | 
  | 469 |  |      }; | 
  | 470 |  |   | 
  | 471 |  |      public boolean isUserClickedSaveButton() { | 
  | 472 | 0 |          return userClickedSaveButton; | 
  | 473 |  |      } | 
  | 474 |  |   | 
  | 475 |  |      public void setUserClickedSaveButton(boolean userClickedSaveButton) { | 
  | 476 | 0 |          this.userClickedSaveButton = userClickedSaveButton; | 
  | 477 | 0 |      } | 
  | 478 |  |   | 
  | 479 |  |      public Integer getInternalCourseReqID() { | 
  | 480 | 0 |          return internalCourseReqID; | 
  | 481 |  |      } | 
  | 482 |  |  } |