Coverage Report - org.kuali.student.lum.lu.ui.tools.client.widgets.KSBrowser
 
Classes in this File Line Coverage Branch Coverage Complexity
KSBrowser
0%
0/32
0%
0/10
2.5
KSBrowser$ExecuteNextSearchCallback
0%
0/12
0%
0/2
2.5
KSBrowser$ViewCourseCallback
0%
0/11
0%
0/2
2.5
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 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  
 }