| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.lum.lu.ui.tools.client.widgets; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.ArrayList; | 
  | 19 |  |  import java.util.Collections; | 
  | 20 |  |  import java.util.LinkedHashMap; | 
  | 21 |  |  import java.util.List; | 
  | 22 |  |  import java.util.Map; | 
  | 23 |  |   | 
  | 24 |  |  import org.kuali.student.common.ui.client.application.Application; | 
  | 25 |  |  import org.kuali.student.common.ui.client.application.ViewContext; | 
  | 26 |  |  import org.kuali.student.common.ui.client.configurable.mvc.WidgetConfigInfo; | 
  | 27 |  |  import org.kuali.student.common.ui.client.mvc.Controller; | 
  | 28 |  |  import org.kuali.student.common.ui.client.widgets.KSErrorDialog; | 
  | 29 |  |  import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel; | 
  | 30 |  |  import org.kuali.student.common.ui.shared.IdAttributes.IdType; | 
  | 31 |  |  import org.kuali.student.core.assembly.data.LookupMetadata; | 
  | 32 |  |  import org.kuali.student.core.assembly.data.LookupParamMetadata; | 
  | 33 |  |   | 
  | 34 |  |  import com.google.gwt.user.client.Window; | 
  | 35 |  |  import com.google.gwt.user.client.ui.Composite; | 
  | 36 |  |   | 
  | 37 |  |  public class KSBrowser extends Composite { | 
  | 38 |  |   | 
  | 39 |  |          private List<BrowsePanel> browsePanels; | 
  | 40 |  |          private LookupMetadata fieldLookup; | 
  | 41 |  |          private List<LookupMetadata> cascadingLookups; | 
  | 42 |  |          private List<LookupParamMetadata> cascadingChildParameters; | 
  | 43 |  |          private WidgetConfigInfo config; | 
  | 44 | 0 |          private VerticalFlowPanel layout = new VerticalFlowPanel (); | 
  | 45 |  |   | 
  | 46 |  |          public KSBrowser (LookupMetadata fieldLookup, Controller controller) | 
  | 47 | 0 |          { | 
  | 48 | 0 |                  this.fieldLookup = fieldLookup; | 
  | 49 |  |   | 
  | 50 | 0 |                  if (config == null) | 
  | 51 |  |                  { | 
  | 52 | 0 |                          config = new WidgetConfigInfo (); | 
  | 53 |  |                  } | 
  | 54 |  |   | 
  | 55 | 0 |                  browsePanels = new ArrayList<BrowsePanel> (); | 
  | 56 | 0 |                  cascadingLookups = new ArrayList<LookupMetadata> (); | 
  | 57 | 0 |                  cascadingChildParameters = new ArrayList<LookupParamMetadata> (); | 
  | 58 | 0 |                  cascadingLookups.add (this.fieldLookup); | 
  | 59 | 0 |                  this.addChildLookups (this.fieldLookup); | 
  | 60 | 0 |                  Collections.reverse (cascadingChildParameters); | 
  | 61 | 0 |                  Collections.reverse (cascadingLookups); | 
  | 62 |  |   | 
  | 63 | 0 |                  for (LookupMetadata lookupMetadata : cascadingLookups) | 
  | 64 |  |                  { | 
  | 65 | 0 |                          BrowsePanel browsePanel = new BrowsePanel (lookupMetadata); | 
  | 66 | 0 |                          browsePanels.add (browsePanel); | 
  | 67 | 0 |                          layout.add (browsePanel); | 
  | 68 | 0 |                  } | 
  | 69 | 0 |                  for (int i = 0; i < browsePanels.size () - 1; i ++) | 
  | 70 |  |                  { | 
  | 71 | 0 |                          BrowsePanel currentBP = browsePanels.get (i); | 
  | 72 | 0 |                          LookupParamMetadata nextParamMetadata = this.cascadingChildParameters.get (i); | 
  | 73 | 0 |                          BrowsePanel nextBP = browsePanels.get (i + 1); | 
  | 74 | 0 |                          currentBP.setOnSelectectedCallback (new ExecuteNextSearchCallback (nextBP, nextParamMetadata)); | 
  | 75 |  |                  } | 
  | 76 | 0 |                  browsePanels.get (browsePanels.size () - 1).setOnSelectectedCallback (new ViewCourseCallback (controller)); | 
  | 77 |  |   | 
  | 78 | 0 |                  this.initWidget (layout); | 
  | 79 | 0 |                  browsePanels.get (0).executeSearch (); | 
  | 80 | 0 |          } | 
  | 81 |  |   | 
  | 82 |  |          private class ExecuteNextSearchCallback implements BrowsePanel.OnSelectedCallback { | 
  | 83 |  |   | 
  | 84 |  |                  private BrowsePanel nextBrowsePanel; | 
  | 85 |  |                  private LookupParamMetadata nextParamMetadata; | 
  | 86 |  |   | 
  | 87 |  |                  public ExecuteNextSearchCallback (BrowsePanel nextBrowsePanel, | 
  | 88 | 0 |                                  LookupParamMetadata nextParamMetadata) { | 
  | 89 | 0 |                          this.nextBrowsePanel = nextBrowsePanel; | 
  | 90 | 0 |                          this.nextParamMetadata = nextParamMetadata; | 
  | 91 | 0 |                  } | 
  | 92 |  |   | 
  | 93 |  |                  @Override | 
  | 94 |  |                  public void selected (List<String> selectedIds)        { | 
  | 95 | 0 |                          if (selectedIds.size () == 0) { | 
  | 96 | 0 |                                  Window.alert ("Please select a row before clicking"); | 
  | 97 | 0 |                                  return; | 
  | 98 |  |                          } | 
  | 99 | 0 |                          Map<String, Object> parameters = new LinkedHashMap<String, Object> (); | 
  | 100 | 0 |                          parameters.put (nextParamMetadata.getKey (), selectedIds.get (0)); | 
  | 101 | 0 |                          nextBrowsePanel.setParameters (parameters); | 
  | 102 | 0 |                          nextBrowsePanel.executeSearch (); | 
  | 103 | 0 |                  } | 
  | 104 |  |          } | 
  | 105 |  |   | 
  | 106 |  |          private class ViewCourseCallback implements BrowsePanel.OnSelectedCallback { | 
  | 107 |  |   | 
  | 108 |  |                  private Controller controller; | 
  | 109 |  |   | 
  | 110 |  |                  public ViewCourseCallback (Controller controller) | 
  | 111 | 0 |                  { | 
  | 112 | 0 |                          this.controller = controller; | 
  | 113 | 0 |                  } | 
  | 114 |  |   | 
  | 115 |  |                  @Override | 
  | 116 |  |                  public void selected (List<String> selectedIds)        { | 
  | 117 | 0 |                          if (selectedIds.size () == 0) { | 
  | 118 | 0 |                                  Window.alert ("Please select a row before clicking"); | 
  | 119 | 0 |                                  return; | 
  | 120 |  |                          } | 
  | 121 | 0 |                          ViewContext viewContext = new ViewContext (); | 
  | 122 | 0 |                          viewContext.setId (selectedIds.get (0)); | 
  | 123 | 0 |                          viewContext.setIdType (IdType.OBJECT_ID); | 
  | 124 | 0 |                          Application.navigate("/HOME/CURRICULUM_HOME/VIEW_COURSE", viewContext); | 
  | 125 | 0 |                  } | 
  | 126 |  |          } | 
  | 127 |  |   | 
  | 128 |  |          private void addChildLookups (LookupMetadata current) { | 
  | 129 | 0 |                  for (LookupParamMetadata param : current.getParams ())        { | 
  | 130 | 0 |                          if (param.getChildLookup () != null) { | 
  | 131 | 0 |                                  cascadingChildParameters.add (param); | 
  | 132 | 0 |                                  cascadingLookups.add (param.getChildLookup ()); | 
  | 133 | 0 |                                  addChildLookups (param.getChildLookup ()); | 
  | 134 |  |                          } | 
  | 135 |  |                  } | 
  | 136 | 0 |          } | 
  | 137 |  |   | 
  | 138 |  |  } |