Coverage Report - org.kuali.student.lum.lu.ui.browseprogram.client.views.BrowseProgramView
 
Classes in this File Line Coverage Branch Coverage Complexity
BrowseProgramView
0%
0/48
0%
0/22
2.273
BrowseProgramView$1
0%
0/11
N/A
2.273
BrowseProgramView$1$1
0%
0/5
N/A
2.273
BrowseProgramView$1$2
0%
0/3
N/A
2.273
BrowseProgramView$2
0%
0/9
N/A
2.273
BrowseProgramView$ViewCourseCallback
0%
0/9
0%
0/2
2.273
 
 1  
 package org.kuali.student.lum.lu.ui.browseprogram.client.views;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Arrays;
 5  
 import java.util.HashSet;
 6  
 import java.util.List;
 7  
 import java.util.Map;
 8  
 import java.util.Map.Entry;
 9  
 
 10  
 import org.kuali.student.common.assembly.data.LookupMetadata;
 11  
 import org.kuali.student.common.assembly.data.Metadata;
 12  
 import org.kuali.student.common.ui.client.application.Application;
 13  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 14  
 import org.kuali.student.common.ui.client.application.ViewContext;
 15  
 import org.kuali.student.common.ui.client.mvc.Callback;
 16  
 import org.kuali.student.common.ui.client.mvc.Controller;
 17  
 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
 18  
 import org.kuali.student.common.ui.client.mvc.ViewComposite;
 19  
 import org.kuali.student.common.ui.client.service.MetadataRpcService;
 20  
 import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync;
 21  
 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout;
 22  
 import org.kuali.student.common.ui.client.widgets.filter.FilterEvent;
 23  
 import org.kuali.student.common.ui.client.widgets.filter.FilterEventHandler;
 24  
 import org.kuali.student.common.ui.client.widgets.filter.FilterResetEventHandler;
 25  
 import org.kuali.student.common.ui.client.widgets.filter.KSFilterOptions;
 26  
 import org.kuali.student.common.ui.client.widgets.headers.KSDocumentHeader;
 27  
 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
 28  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 29  
 import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow;
 30  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 31  
 import org.kuali.student.lum.lu.ui.main.client.configuration.CurriculumHomeConstants;
 32  
 import org.kuali.student.lum.lu.ui.tools.client.widgets.BrowsePanel;
 33  
 
 34  
 import com.google.gwt.core.client.GWT;
 35  
 import com.google.gwt.user.client.Window;
 36  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 37  
 
 38  
 
 39  0
 public class BrowseProgramView extends ViewComposite {
 40  
     
 41  0
         private final BlockingTask initializingTask = new BlockingTask("Loading");
 42  0
     protected MetadataRpcServiceAsync metadataServiceAsync = GWT.create(MetadataRpcService.class);
 43  
         
 44  0
     private VerticalFieldLayout container = new VerticalFieldLayout();
 45  0
         private HorizontalPanel layout = new HorizontalPanel();
 46  
         protected KSFilterOptions dependencyFilter;
 47  
         protected DataModelDefinition searchDefinition;
 48  0
         protected boolean initialized = false;
 49  
         BrowsePanel browsePanel;
 50  
         
 51  
         public BrowseProgramView(Controller controller, String name,
 52  
                         Enum<?> viewType) {
 53  0
                 super(controller, name, viewType);
 54  0
         }
 55  
 
 56  
         private void init() {
 57  0
                 initWidget(container);
 58  
                 Metadata metaData;
 59  
                 
 60  0
                 KSDocumentHeader header = new KSDocumentHeader();
 61  0
         header.setTitle(Application.getApplicationContext().getMessage(CurriculumHomeConstants.BROWSE_PROGRAM));
 62  
         
 63  0
         container.setTitleWidget(header);
 64  
         
 65  0
                 metaData = searchDefinition.getMetadata("search");
 66  
                 
 67  0
                 browsePanel = new BrowsePanel(metaData.getInitialLookup(),400);
 68  
 
 69  0
                 browsePanel.setOnSelectectedCallback(new ViewCourseCallback());
 70  
                 
 71  0
                 browsePanel.executeSearch(new Callback<Boolean>(){
 72  
                         @Override
 73  
                         public void exec(Boolean result) {
 74  
                                 Metadata metaData;
 75  0
                                 List<LookupMetadata> lookups = new ArrayList<LookupMetadata>();
 76  0
                         metaData = searchDefinition.getMetadata("filter");
 77  0
                         lookups.add(metaData.getInitialLookup());
 78  0
                         dependencyFilter = new KSFilterOptions(metaData.getAdditionalLookups(),
 79  
                                         browsePanel.getFilterCount());
 80  0
                         dependencyFilter.addFilterEventHandler(new FilterEventHandler(){
 81  
                                         @Override
 82  
                                         public void onDeselect(FilterEvent e) {
 83  0
                                                 handleSelections(e.getSelections());
 84  0
                                         }
 85  
                                         @Override
 86  
                                         public void onSelect(FilterEvent e) {
 87  0
                                                 handleSelections(e.getSelections());
 88  0
                                         }
 89  
                                
 90  
                         });
 91  
                         
 92  0
                         dependencyFilter.addFilterResetEventHandler(new FilterResetEventHandler(){
 93  
                                         @Override
 94  
                                         public void onReset() {
 95  0
                                                 handleSelections(null);                                
 96  0
                                         }                
 97  
                         });
 98  
                                 
 99  0
                         layout.add(dependencyFilter);
 100  
                         
 101  0
                         layout.add(browsePanel);
 102  
                         
 103  0
                                 container.add(layout);
 104  0
                         }
 105  
                 });
 106  
 
 107  0
         }   
 108  
 
 109  
         private void handleSelections(Map<String, List<String>> selections) {
 110  0
                 if(selections == null || selections.isEmpty()){
 111  0
                         browsePanel.showAllRows();
 112  
                 }else{
 113  0
                         HashSet<String> rowKeys = new HashSet<String>();
 114  0
                         for(ResultRow resultRow:browsePanel.getAllResultRows()){
 115  0
                                 boolean matches = true;
 116  0
                                 for(Entry<String, List<String>> entry:selections.entrySet()){
 117  0
                                         String entryKey = entry.getKey();
 118  0
                                         String rowValue = resultRow.getValue(entryKey);
 119  0
                                         List<String> entryValue = entry.getValue();
 120  0
                                         if(entryValue!=null){
 121  0
                                                 if("lu.resultColumn.resultComponentId".equals(entryKey)||
 122  
                                "lu.resultColumn.luOptionalCampusLocation".equals(entryKey)){
 123  0
                                                         String[] rowValues = rowValue.split("<br/>");
 124  0
                                                         ArrayList<String> intersection = new ArrayList<String>(entryValue);
 125  0
                                                         intersection.retainAll(Arrays.asList(rowValues));
 126  0
                                                         if(intersection.isEmpty()){
 127  0
                                                                 matches = false;
 128  0
                                                                 break;
 129  
                                                         }
 130  0
                                                 }else if(!entryValue.contains(rowValue)){
 131  0
                                                         matches = false;
 132  0
                                                         break;
 133  
                                                 }
 134  
                                         }
 135  0
                                 }
 136  0
                                 if(matches){
 137  0
                                         rowKeys.add(resultRow.getId());
 138  
                                 }
 139  0
                         }
 140  
                         
 141  0
                         browsePanel.showOnlyRows(rowKeys);
 142  
                 }
 143  
                 
 144  
 
 145  
                 
 146  0
         }
 147  
         
 148  
         @Override
 149  
         public void beforeShow(final Callback<Boolean> onReadyCallback) {
 150  0
         if (!initialized) {
 151  0
                     KSBlockingProgressIndicator.addTask(initializingTask);
 152  
 
 153  
                     //This loads search definitions for the dependency analysis search 
 154  0
             metadataServiceAsync.getMetadata("browseProgram", null, null, new KSAsyncCallback<Metadata>(){
 155  
 
 156  
                 @Override
 157  
                 public void handleFailure(Throwable caught) {
 158  0
                     KSBlockingProgressIndicator.removeTask(initializingTask);
 159  0
                     throw new RuntimeException("Failed to load search definitions.", caught);                        
 160  
                 }
 161  
 
 162  
                 @Override
 163  
                 public void onSuccess(Metadata result) {
 164  0
                         searchDefinition = new DataModelDefinition(result);
 165  0
                         init();
 166  0
                         onReadyCallback.exec(true);                        
 167  0
                     initialized = true;
 168  0
                     KSBlockingProgressIndicator.removeTask(initializingTask);
 169  0
                 }
 170  
             
 171  
             });                
 172  
         } else {
 173  0
                 onReadyCallback.exec(true);
 174  
         }
 175  0
         }
 176  
         
 177  0
         private class ViewCourseCallback implements BrowsePanel.OnSelectedCallback {
 178  
 
 179  
                 @Override
 180  
                 public void selected (List<String> selectedIds)        {
 181  0
                         if (selectedIds.size () == 0) {
 182  0
                                 Window.alert ("Please select a row before clicking");
 183  0
                                 return;
 184  
                         }
 185  0
                         ViewContext viewContext = new ViewContext ();
 186  0
                         viewContext.setId (selectedIds.get (0));
 187  0
                         viewContext.setIdType (IdType.OBJECT_ID);
 188  0
                         Application.navigate("/HOME/CURRICULUM_HOME/PROGRAM_VIEW", viewContext);
 189  0
                 }
 190  
         }
 191  
 
 192  
 
 193  
 
 194  
 
 195  
 }