| 1 |  |  package org.kuali.student.lum.program.client.core.view; | 
  | 2 |  |   | 
  | 3 |  |  import com.google.gwt.core.client.GWT; | 
  | 4 |  |  import com.google.gwt.event.dom.client.ChangeEvent; | 
  | 5 |  |  import com.google.gwt.event.dom.client.ChangeHandler; | 
  | 6 |  |  import com.google.gwt.event.shared.HandlerManager; | 
  | 7 |  |  import org.kuali.student.common.ui.client.application.KSAsyncCallback; | 
  | 8 |  |  import org.kuali.student.common.ui.client.application.ViewContext; | 
  | 9 |  |  import org.kuali.student.common.ui.client.mvc.DataModel; | 
  | 10 |  |  import org.kuali.student.common.ui.client.mvc.history.HistoryManager; | 
  | 11 |  |  import org.kuali.student.common.ui.shared.IdAttributes.IdType; | 
  | 12 |  |  import org.kuali.student.lum.common.client.widgets.AppLocations; | 
  | 13 |  |  import org.kuali.student.lum.common.client.widgets.DropdownList; | 
  | 14 |  |  import org.kuali.student.lum.program.client.ProgramConstants; | 
  | 15 |  |  import org.kuali.student.lum.program.client.ProgramRegistry; | 
  | 16 |  |  import org.kuali.student.lum.program.client.ProgramSections; | 
  | 17 |  |  import org.kuali.student.lum.program.client.ProgramStatus; | 
  | 18 |  |  import org.kuali.student.lum.program.client.core.CoreController; | 
  | 19 |  |  import org.kuali.student.lum.program.client.events.ModelLoadedEvent; | 
  | 20 |  |  import org.kuali.student.lum.program.client.events.ProgramViewEvent; | 
  | 21 |  |  import org.kuali.student.lum.program.client.major.ActionType; | 
  | 22 |  |   | 
  | 23 |  |   | 
  | 24 |  |   | 
  | 25 |  |   | 
  | 26 | 0 |  public class CoreViewController extends CoreController { | 
  | 27 |  |   | 
  | 28 | 0 |      private final DropdownList actionBox = new DropdownList(ActionType.getValues()); | 
  | 29 |  |   | 
  | 30 |  |       | 
  | 31 |  |   | 
  | 32 |  |   | 
  | 33 |  |   | 
  | 34 |  |   | 
  | 35 |  |      public CoreViewController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) { | 
  | 36 | 0 |          super(programModel, viewContext, eventBus); | 
  | 37 | 0 |          configurer = GWT.create(CoreViewConfigurer.class); | 
  | 38 | 0 |          bind(); | 
  | 39 | 0 |      } | 
  | 40 |  |   | 
  | 41 |  |      private void bind() { | 
  | 42 | 0 |          actionBox.addChangeHandler(new ChangeHandler() { | 
  | 43 |  |              @Override | 
  | 44 |  |              public void onChange(ChangeEvent event) { | 
  | 45 | 0 |                  ActionType actionType = ActionType.of(actionBox.getSelectedValue()); | 
  | 46 | 0 |                  ViewContext viewContext = getViewContext(); | 
  | 47 | 0 |                  if (actionType == ActionType.MODIFY) { | 
  | 48 | 0 |                      ProgramRegistry.setSection(ProgramSections.getEditSection(getCurrentViewEnum())); | 
  | 49 | 0 |                      HistoryManager.navigate(AppLocations.Locations.EDIT_CORE_PROGRAM.getLocation(), viewContext); | 
  | 50 | 0 |                  } else if (actionType == ActionType.MODIFY_VERSION) { | 
  | 51 | 0 |                      String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); | 
  | 52 | 0 |                      viewContext.setId(versionIndId); | 
  | 53 | 0 |                      viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); | 
  | 54 | 0 |                      HistoryManager.navigate(AppLocations.Locations.EDIT_CORE_PROGRAM.getLocation(), viewContext); | 
  | 55 |  |                  } | 
  | 56 | 0 |              } | 
  | 57 |  |          }); | 
  | 58 | 0 |          eventBus.addHandler(ProgramViewEvent.TYPE, new ProgramViewEvent.Handler() { | 
  | 59 |  |              @Override | 
  | 60 |  |              public void onEvent(ProgramViewEvent event) { | 
  | 61 | 0 |                  actionBox.setSelectedIndex(0); | 
  | 62 | 0 |              } | 
  | 63 |  |          }); | 
  | 64 | 0 |          eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() { | 
  | 65 |  |              @Override | 
  | 66 |  |              public void onEvent(ModelLoadedEvent event) { | 
  | 67 | 0 |                  resetActionList(); | 
  | 68 | 0 |              } | 
  | 69 |  |          }); | 
  | 70 | 0 |      } | 
  | 71 |  |   | 
  | 72 |  |      @Override | 
  | 73 |  |      protected void configureView() { | 
  | 74 | 0 |          super.configureView(); | 
  | 75 | 0 |          addContentWidget(actionBox); | 
  | 76 | 0 |          initialized = true; | 
  | 77 | 0 |      } | 
  | 78 |  |   | 
  | 79 |  |      protected void resetActionList() { | 
  | 80 |  |           | 
  | 81 | 0 |          ProgramStatus status = ProgramStatus.of(programModel.<String>get(ProgramConstants.STATE)); | 
  | 82 | 0 |          String versionIndId = programModel.get(ProgramConstants.VERSION_IND_ID); | 
  | 83 | 0 |          Long sequenceNumber = programModel.get(ProgramConstants.VERSION_SEQUENCE_NUMBER); | 
  | 84 |  |   | 
  | 85 | 0 |          actionBox.clear(); | 
  | 86 | 0 |          if (status == ProgramStatus.ACTIVE) { | 
  | 87 | 0 |              programRemoteService.isLatestVersion(versionIndId, sequenceNumber, new KSAsyncCallback<Boolean>() { | 
  | 88 |  |                  public void onSuccess(Boolean isLatest) { | 
  | 89 | 0 |                      actionBox.setList(ActionType.getValues(isLatest)); | 
  | 90 | 0 |                  } | 
  | 91 |  |              }); | 
  | 92 |  |          } else { | 
  | 93 | 0 |              actionBox.setList(ActionType.getValues(false)); | 
  | 94 |  |          } | 
  | 95 | 0 |      } | 
  | 96 |  |  } |