Coverage Report - org.kuali.student.lum.lu.ui.dependency.client.views.DependencyAnalysisView
 
Classes in this File Line Coverage Branch Coverage Complexity
DependencyAnalysisView
0%
0/147
0%
0/62
3.231
DependencyAnalysisView$1
0%
0/9
N/A
3.231
DependencyAnalysisView$2
0%
0/19
0%
0/4
3.231
DependencyAnalysisView$3
0%
0/7
0%
0/2
3.231
DependencyAnalysisView$4
0%
0/3
N/A
3.231
DependencyAnalysisView$5
0%
0/56
0%
0/38
3.231
DependencyAnalysisView$6
0%
0/9
0%
0/2
3.231
DependencyAnalysisView$6$1
0%
0/9
0%
0/6
3.231
DependencyAnalysisView$7
0%
0/6
N/A
3.231
DependencyAnalysisView$8
0%
0/8
0%
0/2
3.231
DependencyAnalysisView$9
0%
0/5
N/A
3.231
 
 1  
 package org.kuali.student.lum.lu.ui.dependency.client.views;
 2  
 
 3  
 
 4  
 import java.util.ArrayList;
 5  
 import java.util.Arrays;
 6  
 import java.util.HashMap;
 7  
 import java.util.HashSet;
 8  
 import java.util.List;
 9  
 import java.util.Map;
 10  
 import java.util.Set;
 11  
 
 12  
 import org.kuali.student.common.assembly.data.LookupMetadata;
 13  
 import org.kuali.student.common.assembly.data.Metadata;
 14  
 import org.kuali.student.common.assembly.data.ModelDefinition;
 15  
 import org.kuali.student.common.search.dto.SearchParam;
 16  
 import org.kuali.student.common.search.dto.SearchRequest;
 17  
 import org.kuali.student.common.search.dto.SearchResult;
 18  
 import org.kuali.student.common.search.dto.SearchResultCell;
 19  
 import org.kuali.student.common.search.dto.SearchResultRow;
 20  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 21  
 import org.kuali.student.common.ui.client.mvc.Callback;
 22  
 import org.kuali.student.common.ui.client.mvc.Controller;
 23  
 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
 24  
 import org.kuali.student.common.ui.client.mvc.ViewComposite;
 25  
 import org.kuali.student.common.ui.client.service.MetadataRpcService;
 26  
 import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync;
 27  
 import org.kuali.student.common.ui.client.service.SearchRpcService;
 28  
 import org.kuali.student.common.ui.client.service.SearchRpcServiceAsync;
 29  
 import org.kuali.student.common.ui.client.util.UtilConstants;
 30  
 import org.kuali.student.common.ui.client.widgets.HasWatermark;
 31  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 32  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 33  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 34  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel;
 35  
 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout;
 36  
 import org.kuali.student.common.ui.client.widgets.filter.FilterEvent;
 37  
 import org.kuali.student.common.ui.client.widgets.filter.FilterEventHandler;
 38  
 import org.kuali.student.common.ui.client.widgets.filter.FilterResetEventHandler;
 39  
 import org.kuali.student.common.ui.client.widgets.filter.KSFilterOptions;
 40  
 import org.kuali.student.common.ui.client.widgets.headers.KSDocumentHeader;
 41  
 import org.kuali.student.common.ui.client.widgets.layout.HorizontalBlockFlowPanel;
 42  
 import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
 43  
 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
 44  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 45  
 import org.kuali.student.common.ui.client.widgets.search.CollapsablePanel;
 46  
 import org.kuali.student.common.ui.client.widgets.search.KSPicker;
 47  
 import org.kuali.student.common.ui.client.widgets.suggestbox.KSSuggestBox;
 48  
 import org.kuali.student.common.ui.client.widgets.suggestbox.IdableSuggestOracle.IdableSuggestion;
 49  
 import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
 50  
 import org.kuali.student.core.statement.dto.ReqComponentInfo;
 51  
 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
 52  
 import org.kuali.student.core.statement.ui.client.widgets.rules.RulePreviewWidget;
 53  
 import org.kuali.student.core.statement.ui.client.widgets.rules.RulesUtil;
 54  
 import org.kuali.student.lum.common.client.lu.LUUIConstants;
 55  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 56  
 import org.kuali.student.lum.common.client.widgets.CluSetDetailsWidget;
 57  
 import org.kuali.student.lum.common.client.widgets.CluSetRetriever;
 58  
 import org.kuali.student.lum.common.client.widgets.CluSetRetrieverImpl;
 59  
 import org.kuali.student.lum.lu.ui.dependency.client.controllers.DependencyAnalysisController;
 60  
 import org.kuali.student.lum.lu.ui.dependency.client.controllers.DependencyAnalysisController.DependencyViews;
 61  
 import org.kuali.student.lum.lu.ui.dependency.client.service.DependencyAnalysisRpcService;
 62  
 import org.kuali.student.lum.lu.ui.dependency.client.service.DependencyAnalysisRpcServiceAsync;
 63  
 import org.kuali.student.lum.lu.ui.dependency.client.widgets.DependencyResultPanel;
 64  
 import org.kuali.student.lum.lu.ui.dependency.client.widgets.DependencyResultPanel.DependencyTypeSection;
 65  
 import org.kuali.student.lum.lu.ui.tools.client.configuration.ClusetView.Picker;
 66  
 import org.kuali.student.lum.program.dto.ProgramRequirementInfo;
 67  
 
 68  
 import com.google.gwt.core.client.GWT;
 69  
 import com.google.gwt.event.dom.client.ClickEvent;
 70  
 import com.google.gwt.event.dom.client.ClickHandler;
 71  
 import com.google.gwt.user.client.Window;
 72  
 import com.google.gwt.user.client.ui.Anchor;
 73  
 import com.google.gwt.user.client.ui.FlowPanel;
 74  
 import com.google.gwt.user.client.ui.HTMLPanel;
 75  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 76  
 import com.google.gwt.user.client.ui.Widget;
 77  
 
 78  0
 public class DependencyAnalysisView extends ViewComposite{
 79  
        
 80  0
         private static CluSetRetriever cluSetRetriever = new CluSetRetrieverImpl();
 81  
         
 82  0
     protected final BlockingTask initializingTask = new BlockingTask("Loading");
 83  
     
 84  0
     protected DependencyAnalysisRpcServiceAsync depRpcServiceAsync = GWT.create(DependencyAnalysisRpcService.class);
 85  0
     protected MetadataRpcServiceAsync metadataServiceAsync = GWT.create(MetadataRpcService.class);
 86  0
     protected SearchRpcServiceAsync searchServiceAsync = GWT.create(SearchRpcService.class);
 87  
 
 88  
         private ModelDefinition searchDefinition;
 89  0
         private VerticalFieldLayout container = new VerticalFieldLayout();
 90  0
         protected boolean initialized = false;
 91  
         
 92  
         protected String selectedCourseId;
 93  
         protected String selectedCourseCd;
 94  
         protected String selectedCourseName;
 95  
         
 96  
         protected DependencyResultPanel depResultPanel;
 97  
         protected KSFilterOptions dependencyFilter;
 98  0
         protected HorizontalBlockFlowPanel resultContainer = new HorizontalBlockFlowPanel();
 99  
         
 100  0
         private final BlockingTask loadDataTask = new BlockingTask("Retrieving Data");
 101  
         
 102  
         private KSDocumentHeader header;
 103  
                 
 104  
         public DependencyAnalysisView(Controller controller) {
 105  0
                 super(controller, "Dependency Analysis", DependencyViews.MAIN);
 106  0
         this.initWidget(container);
 107  0
         this.addStyleName("blockLayout");
 108  0
         this.addStyleName("ks-dependency-container");
 109  0
         }
 110  
         
 111  
         @Override
 112  
         public void beforeShow(final Callback<Boolean> onReadyCallback) {
 113  0
         if (!initialized) {
 114  0
                     KSBlockingProgressIndicator.addTask(initializingTask);
 115  
 
 116  
                     //This loads search definitions for the dependency analysis search 
 117  0
             metadataServiceAsync.getMetadata("dependency", null, null, new KSAsyncCallback<Metadata>(){
 118  
 
 119  
                 @Override
 120  
                 public void handleFailure(Throwable caught) {
 121  0
                     KSBlockingProgressIndicator.removeTask(initializingTask);
 122  0
                     throw new RuntimeException("Failed to load search definitions.", caught);                        
 123  
                 }
 124  
 
 125  
                 @Override
 126  
                 public void onSuccess(Metadata result) {
 127  0
                         searchDefinition = new DataModelDefinition(result);
 128  0
                         init();
 129  0
                         onReadyCallback.exec(true);                        
 130  0
                     initialized = true;
 131  0
                     KSBlockingProgressIndicator.removeTask(initializingTask);
 132  0
                 }                
 133  
             });                
 134  
         } else {
 135  0
                 onReadyCallback.exec(true);
 136  
         }
 137  0
         }
 138  
 
 139  
         protected void init(){                
 140  0
                 this.header = new KSDocumentHeader();
 141  
                 
 142  0
         header.setTitle("Dependency Analysis");        
 143  
 
 144  
         //Get search definition for dependency analysis trigger search and create trigger picker          
 145  0
                 Metadata metaData = searchDefinition.getMetadata("courseId");
 146  0
                 final KSPicker triggerPicker = new Picker(metaData.getInitialLookup(), metaData.getAdditionalLookups());
 147  0
         ((HasWatermark)triggerPicker.getInputWidget()).setWatermarkText("Enter course code");                
 148  
 
 149  
         //Setup the "go" button for trigger picker
 150  0
         KSButton goButton = new KSButton("Go", ButtonStyle.PRIMARY_SMALL);
 151  0
                 goButton.addClickHandler(new ClickHandler(){
 152  
 
 153  
                         @Override
 154  
                         public void onClick(ClickEvent event) {                                
 155  0
                 selectedCourseId = triggerPicker.getValue().toString();
 156  0
                 KSSuggestBox suggestBox = (KSSuggestBox)triggerPicker.getInputWidget();
 157  0
                 IdableSuggestion selectedSuggestion = suggestBox.getCurrentSuggestion();
 158  
                 
 159  0
                 selectedCourseName = selectedSuggestion.getAttrMap().get("lu.resultColumn.luOptionalLongName");
 160  0
                 if (!selectedCourseId.equals(UtilConstants.IMPOSSIBLE_CHARACTERS)){
 161  0
                                     KSBlockingProgressIndicator.addTask(loadDataTask);
 162  0
                         selectedCourseCd = triggerPicker.getDisplayValue();                
 163  0
                         if (depResultPanel != null){
 164  0
                                 resultContainer.remove(depResultPanel);
 165  
                         }
 166  0
                         depResultPanel = new DependencyResultPanel();
 167  0
                         depResultPanel.setHeaderTitle(selectedCourseCd + " - " + selectedCourseName);                
 168  0
                         resultContainer.add(depResultPanel);
 169  0
                         resultContainer.setVisible(true);
 170  0
                         updateDependencyResults();
 171  
                 }
 172  0
                 ((DependencyAnalysisController) DependencyAnalysisView.this.getController()).showExport(isExportButtonActive());
 173  0
                 header.showPrint(true);
 174  0
                 header.setPrintContent(depResultPanel); // we only want to print the results panel
 175  0
                         }
 176  
                         
 177  
                 });
 178  
 
 179  
                 
 180  
         //Create search section with the trigger picker and go button
 181  0
                 HorizontalPanel pickerPanel = new HorizontalPanel();
 182  0
                 pickerPanel.add(triggerPicker);
 183  0
                 pickerPanel.add(goButton);
 184  
         
 185  0
                 FlowPanel searchPanel = new FlowPanel();
 186  0
                 searchPanel.addStyleName("ks-dependency-search");
 187  0
                 searchPanel.add(new KSLabel("Search for item to view its dependencies"));
 188  0
                 searchPanel.add(pickerPanel);                
 189  
                 
 190  
                 //Add widgets to view
 191  0
                 container.setTitleWidget(header);
 192  0
                 container.addStyleName("blockLayout");
 193  0
         container.addWidget(searchPanel);
 194  
         
 195  0
         List<LookupMetadata> lookups = new ArrayList<LookupMetadata>();
 196  0
         metaData = searchDefinition.getMetadata("filter");
 197  0
         lookups.add(metaData.getInitialLookup());
 198  
         
 199  0
         dependencyFilter = new KSFilterOptions(metaData.getAdditionalLookups());
 200  0
         dependencyFilter.addFilterEventHandler(new FilterEventHandler(){
 201  
 
 202  
                         @Override
 203  
                         public void onDeselect(FilterEvent e) {
 204  0
                                 depResultPanel.hide(e.getFilterKey(), e.getFilterValue());
 205  0
                         }
 206  
 
 207  
                         @Override
 208  
                         public void onSelect(FilterEvent e) {
 209  0
                                 if (e.isInitialSelect()){
 210  0
                                         depResultPanel.hideAll();
 211  
                                 }
 212  0
                                 depResultPanel.show(e.getFilterKey(), e.getFilterValue());                        
 213  0
                         }
 214  
                 
 215  
         });
 216  
         
 217  0
         dependencyFilter.addFilterResetEventHandler(new FilterResetEventHandler(){
 218  
 
 219  
                         @Override
 220  
                         public void onReset() {
 221  0
                                 depResultPanel.showAll();                                
 222  0
                         }                
 223  
         });
 224  
         
 225  0
         resultContainer.add(dependencyFilter);
 226  0
         resultContainer.setVisible(false);
 227  
         
 228  0
         container.addWidget(resultContainer);
 229  0
         }
 230  
 
 231  
         /*
 232  
          * This method calls the dependency analysis search with the selected trigger from the picker,
 233  
          * and updates the DependencyResultPanel with the results from the search. 
 234  
          */
 235  
         protected void updateDependencyResults(){
 236  
                 //Setup up sections for DependencyResultPanel                
 237  0
                 depResultPanel.addSection(LUUIConstants.DEP_SECTION_COURSE,"Course Dependencies");                
 238  0
                 depResultPanel.addSection(LUUIConstants.DEP_SECTION_PROGRAM,"Program Dependencies");
 239  0
                 depResultPanel.addSection(LUUIConstants.DEP_SECTION_COURSE_SET, "Course Set Inclusions");                
 240  
                         
 241  0
                 dependencyFilter.reset();
 242  
                 
 243  
                 //Setup and invoke the dependency analysis search and process the results
 244  0
                 SearchRequest searchRequest = new SearchRequest();
 245  0
                 searchRequest.setSearchKey("lu.search.dependencyAnalysis");
 246  
                 
 247  0
                 SearchParam searchParam = new SearchParam();
 248  0
                 searchParam.setKey("lu.queryParam.luOptionalCluId");
 249  0
                 searchParam.setValue(selectedCourseId);                                
 250  0
                 searchRequest.getParams().add(searchParam);
 251  
                                 
 252  0
                 searchServiceAsync.search(searchRequest, new KSAsyncCallback<SearchResult>(){
 253  
 
 254  
                         @Override
 255  
                         public void onSuccess(SearchResult searchResults) {                                
 256  0
                                 for (SearchResultRow searchResultRow : searchResults.getRows ()) {
 257  
                                         
 258  
                                         //TODO: This should not use hard-coded result columns 
 259  0
                                         String cluCode = "";
 260  0
                                         String cluName = "";
 261  0
                                         String cluType = "";
 262  0
                                         String dependencyType = "";
 263  0
                                         String dependencyTypeName = "";
 264  0
                                         String reqComponentIds = "";
 265  0
                                         String reqRootId = "";
 266  0
                                         String cluId = "";
 267  0
                                         String curriculumOversightNames = "";
 268  0
                                         String dependencySectionKey = "";
 269  0
                                         Boolean diffAdminOrg = false;
 270  
                                         
 271  0
                                         for (SearchResultCell searchResultCell : searchResultRow.getCells ()){
 272  0
                                                 if (searchResultCell.getKey().equals ("lu.resultColumn.luOptionalCode")) {
 273  0
                                                         cluCode = searchResultCell.getValue();        
 274  0
                                                 } if (searchResultCell.getKey().equals ("lu.resultColumn.cluId")) {
 275  0
                                                         cluId = searchResultCell.getValue();
 276  0
                                                 } else if (searchResultCell.getKey().equals("lu.resultColumn.luOptionalLongName")){
 277  0
                                                         cluName = searchResultCell.getValue();
 278  0
                                                 } else if (searchResultCell.getKey().equals("lu.resultColumn.cluType")){
 279  0
                                                         cluType = searchResultCell.getValue();
 280  0
                                                         if (cluType.equals(LUUIConstants.CLU_TYPE_CREDIT_COURSE)){
 281  0
                                                                 dependencySectionKey = LUUIConstants.DEP_SECTION_COURSE;
 282  0
                                                         } else if (cluType != null){
 283  0
                                                                 dependencySectionKey = LUUIConstants.DEP_SECTION_PROGRAM;
 284  
                                                         }
 285  0
                                                 } else if (searchResultCell.getKey().equals("lu.resultColumn.luOptionalDependencyType")){
 286  0
                                                         dependencyType = searchResultCell.getValue();
 287  0
                                                         if (dependencyType.equals("cluSet")){
 288  0
                                                                 dependencySectionKey = LUUIConstants.DEP_SECTION_COURSE_SET;
 289  0
                                                         } else if (LUUIConstants.DEP_TYPE_JOINT.equals(dependencyType) || 
 290  
                                                                                 LUUIConstants.DEP_TYPE_CROSS_LISTED.equals(dependencyType)){
 291  0
                                                                 dependencySectionKey = LUUIConstants.DEP_SECTION_COURSE;;
 292  
                                                         }
 293  0
                                                 } else if (searchResultCell.getKey().equals("lu.resultColumn.luOptionalDependencyTypeName")){
 294  0
                                                         dependencyTypeName = searchResultCell.getValue();
 295  0
                                                 } else if (searchResultCell.getKey().equals("lu.resultColumn.luOptionalDependencyRequirementComponentIds")){
 296  0
                                                         reqComponentIds = searchResultCell.getValue();
 297  0
                                                 } else if (searchResultCell.getKey().equals("lu.resultColumn.luOptionalDependencyRootId")){
 298  0
                                                         reqRootId = searchResultCell.getValue();
 299  0
                                                 } else if (searchResultCell.getKey().equals("lu.resultColumn.luOptionalOversightCommitteeNames")){
 300  0
                                                         curriculumOversightNames = searchResultCell.getValue();
 301  0
                                                 } else if (searchResultCell.getKey().equals("lu.resultColumn.luOptionalDependencyRequirementDifferentAdminOrg")){
 302  0
                                                         diffAdminOrg = ("true").equals(searchResultCell.getValue());
 303  
                                                 }
 304  
                                                         
 305  
                                         }
 306  
                                         
 307  
                                         //Get the dependency type section to add the dependency to, create new one if this is the first dependency for the t
 308  0
                                         DependencyTypeSection typeSection = depResultPanel.getDependencyTypeSection(dependencySectionKey, dependencyType);
 309  0
                                         if (typeSection == null){                                                
 310  0
                                                 typeSection = depResultPanel.addDependencyTypeSection(dependencySectionKey, dependencyType, getDependencyTypeLabel(dependencySectionKey, dependencyType, dependencyTypeName));
 311  
                                         }
 312  
                                         
 313  
                                         //If dependency has details, create the details widget
 314  0
                                         VerticalFieldLayout depDetails = null;
 315  0
                                         if (hasDependencyDetails(dependencyType)){
 316  0
                                                 depDetails = getDependencyDetails(dependencySectionKey, dependencyType, cluCode, reqRootId, reqComponentIds);
 317  0
                                                 KSLabel curricOversightLabel = new KSLabel("Curriculum Oversight: " + curriculumOversightNames);
 318  0
                                                 curricOversightLabel.addStyleName("ks-dependency-oversight");
 319  0
                                                 depDetails.addWidget(curricOversightLabel);
 320  
                                         }
 321  
 
 322  
                                         //Add the dependency to the dependency section
 323  0
                                         typeSection.addDependencyItem(getDependencyLabel(dependencySectionKey, dependencyType, cluId, cluCode, cluName, cluType, diffAdminOrg), depDetails);
 324  0
                                 }
 325  
                                 
 326  0
                                 depResultPanel.finishLoad();
 327  0
                                 KSBlockingProgressIndicator.removeTask(loadDataTask);
 328  0
                         }
 329  
                         
 330  
                 });
 331  0
         }
 332  
         
 333  
 
 334  
         private VerticalFieldLayout getDependencyDetails(String dependencySectionKey, String dependencyType, final String cluCode, final String rootId, String reqComponentIds){
 335  0
                 VerticalFieldLayout depDetails = new VerticalFieldLayout();
 336  0
                 depDetails.addStyleName("KS-Dependency-Details");
 337  0
                 if (reqComponentIds != null && !reqComponentIds.isEmpty()){
 338  0
                         List<String> reqComponentIdList = Arrays.asList(reqComponentIds.split(","));
 339  
 
 340  0
                         final VerticalFlowPanel simpleRequirement = new VerticalFlowPanel();                        
 341  0
                         simpleRequirement.addStyleName("KS-Dependency-Simple-Rule");
 342  
                         
 343  
                         //For programs, add ability to display both the simple requirement and complex requirement for the details
 344  0
                         if (LUUIConstants.DEP_SECTION_PROGRAM.equals(dependencySectionKey)){
 345  0
                                 final KSButton complexReqLabel = new KSButton("Display complex requirement", ButtonStyle.DEFAULT_ANCHOR);
 346  0
                                 final KSButton simpleReqLabel = new KSButton("Display simple requirement", ButtonStyle.DEFAULT_ANCHOR);
 347  
                                 
 348  
                                 //Initialize the complex requirement panel, set it so it is not initially open (ie. not visible)
 349  0
                                 final FlowPanel complexContent = new FlowPanel();
 350  0
                                 final CollapsablePanel complexRequirement = new CollapsablePanel("", complexContent, false, false);                                
 351  
                                 
 352  0
                                 complexContent.addStyleName("KS-Dependency-Complex-Rule");
 353  0
                                 depDetails.addWidget(simpleRequirement);
 354  0
                                 depDetails.addWidget(complexRequirement);
 355  0
                                 depDetails.addWidget(complexReqLabel);
 356  0
                                 depDetails.addWidget(simpleReqLabel);
 357  
                                 
 358  0
                                 simpleReqLabel.setVisible(false);
 359  
                                 
 360  
                                 //Click handler to display the complex requirement, which will go and fetch the requirement components
 361  
                                 //if displaying for first time.
 362  0
                                 complexReqLabel.addClickHandler(new ClickHandler(){
 363  
                                         public void onClick(ClickEvent event) {
 364  0
                                                 simpleReqLabel.setVisible(true);
 365  0
                                                 simpleRequirement.setVisible(false);
 366  0
                                                 complexReqLabel.setVisible(false);
 367  
 
 368  0
                                                 if (complexContent.getWidgetCount() <= 0){
 369  0
                                                         KSBlockingProgressIndicator.addTask(loadDataTask);
 370  
                                                         //TODO: This code copied from program screens, need common reusable code
 371  0
                                                         depRpcServiceAsync.getProgramRequirement(rootId, new KSAsyncCallback<ProgramRequirementInfo>(){
 372  
                                                                 public void onSuccess(ProgramRequirementInfo progReqInfo) {                                                                                                                        
 373  0
                                                                 int minCredits = (progReqInfo.getMinCredits() == null ? 0 : progReqInfo.getMinCredits());
 374  0
                                                                 int maxCredits = (progReqInfo.getMaxCredits() == null ? 0 : progReqInfo.getMaxCredits());
 375  0
                                                                 String plainDesc = (progReqInfo.getDescr() == null ? "" : progReqInfo.getDescr().getPlain());
 376  0
                                                                 final RulePreviewWidget rulePreviewWidget = new RulePreviewWidget(1, progReqInfo.getShortTitle(),
 377  
                                                                         getTotalCreditsString(minCredits, maxCredits),
 378  
                                                                         plainDesc, progReqInfo.getStatement(),
 379  
                                                                         true, getCluSetWidgetList(progReqInfo.getStatement()));
 380  0
                                                                 complexContent.add(rulePreviewWidget);
 381  0
                                                                 KSBlockingProgressIndicator.removeTask(loadDataTask);
 382  0
                                                                         complexRequirement.open();
 383  0
                                                                 }                                                        
 384  
                                                         });
 385  
                                                 } else {
 386  0
                                                         complexRequirement.open();
 387  
                                                 }
 388  0
                                         }                                        
 389  
                                 });
 390  
                                 
 391  
                                 //Click handler to display the simple requirement only
 392  0
                                 simpleReqLabel.addClickHandler(new ClickHandler(){
 393  
                                         public void onClick(ClickEvent event) {
 394  0
                                                 complexReqLabel.setVisible(true);                                                
 395  0
                                                 complexRequirement.close();
 396  0
                                                 simpleRequirement.setVisible(true);
 397  0
                                                 simpleReqLabel.setVisible(false);                                                
 398  0
                                         }
 399  
                                 });
 400  0
                         } else {
 401  0
                                 depDetails.addWidget(simpleRequirement);
 402  
                         }
 403  
                         
 404  0
                         depRpcServiceAsync.getRequirementComponentNL(reqComponentIdList, new KSAsyncCallback<List<String>>(){
 405  
                                 public void onSuccess(List<String> results) {
 406  0
                                         for (String reqCompNL:results){
 407  0
                                                 int codeIdx = reqCompNL.indexOf(selectedCourseCd);
 408  0
                                                 SpanPanel requirement = new SpanPanel();
 409  0
                                                 requirement.setHTML(reqCompNL.substring(0,codeIdx) + 
 410  
                                                                 " <b>" + selectedCourseCd + "</b>" + reqCompNL.substring(codeIdx + selectedCourseCd.length()));
 411  0
                                                 simpleRequirement.add(requirement);
 412  0
                                         }                                                                
 413  0
                                 }                                                        
 414  
                         });
 415  
                 }
 416  
 
 417  0
                 return depDetails;
 418  
         }
 419  
         
 420  
         //This generates the label for the dependency type section (eg. Pre-req requirement, course set inclusion, etc).
 421  
         private SpanPanel getDependencyTypeLabel(String dependencySectionKey, String dependencyType, String dependencyTypeName) {
 422  0
                 SpanPanel header = new SpanPanel();
 423  0
                 if (dependencyType.equals("joint") || dependencyType.equals("crossListed")){
 424  0
                         header.setHTML("<b>" + selectedCourseCd + "</b> is <b>" + dependencyTypeName + "</b> with the following ");
 425  0
                 } else if (dependencySectionKey.equals("course sets")){
 426  0
                         header.setHTML("<b>" + selectedCourseCd + "</b> belongs to the following course sets");
 427  
                 } else {
 428  0
                         header.setHTML("<b>" + selectedCourseCd + "</b> is a/an <b>" + dependencyTypeName + "</b> for the following " + dependencySectionKey);                        
 429  
                 }
 430  0
             header.setStyleName("KS-DependencyType-Label");
 431  0
                 return header;
 432  
         }
 433  
         
 434  
         /*
 435  
          * This generates the title for the actual dependency (eg. course, course set, program), which may include links to 
 436  
          * view the actual course, course set or program
 437  
          */
 438  
         private SpanPanel getDependencyLabel(final String dependencySectionKey, String dependencyType, final String cluId,  String cluCode, String cluName, String cluType, boolean diffAdminOrg){
 439  
                 
 440  
                 //Figure out the view hyperlink for course/program/course set screen based on dependencyType
 441  0
                 Anchor viewLinkAnchor = null;
 442  
                 final String viewLinkUrl;
 443  0
                 if (LUUIConstants.CLU_TYPE_CREDIT_COURSE.equals(cluType) && 
 444  
                                 !LUUIConstants.DEP_TYPE_CROSS_LISTED.equals(dependencyType)){
 445  0
                         viewLinkAnchor = new Anchor("View Course");
 446  0
                         viewLinkUrl = AppLocations.Locations.VIEW_COURSE.toString(); 
 447  0
                 } else if ("kuali.lu.type.MajorDiscipline".equals(cluType) || "kuali.lu.type.Variation".equals(cluType)){
 448  0
                         viewLinkAnchor = new Anchor("View Program ");
 449  0
                         viewLinkUrl = AppLocations.Locations.VIEW_PROGRAM.toString(); 
 450  0
                 } else if ("kuali.lu.type.CoreProgram".equals(cluType)){
 451  0
                         viewLinkAnchor = new Anchor("View Program ");
 452  0
                         viewLinkUrl = AppLocations.Locations.VIEW_CORE_PROGRAM.toString(); 
 453  0
                 } else if (cluType.startsWith("kuali.lu.type.credential")){
 454  0
                         viewLinkAnchor = new Anchor("View Program ");
 455  0
                         viewLinkUrl = AppLocations.Locations.VIEW_BACC_PROGRAM.toString(); 
 456  0
                 } else if (LUUIConstants.DEP_TYPE_COURSE_SET.equals(dependencyType)){
 457  0
                         viewLinkAnchor = new Anchor("View Course Set");
 458  0
                         viewLinkUrl = AppLocations.Locations.VIEW_CLU_SET.toString();
 459  
                 } else {
 460  0
                         viewLinkUrl = null;
 461  
                 }
 462  
                 
 463  
                 //Add click handler to open new window for user to view the course/program/cluset in more detail
 464  0
                 if (viewLinkAnchor != null){
 465  0
                     viewLinkAnchor.addStyleName("KS-Dependency-View-Link");
 466  0
                 viewLinkAnchor.addClickHandler(new ClickHandler(){
 467  
         
 468  
                                 @Override
 469  
                                 public void onClick(ClickEvent event) {
 470  0
                                         String url =  "http://" + Window.Location.getHost() + Window.Location.getPath() +
 471  
                                                 "?view=" + viewLinkUrl + "&docId=" + cluId;
 472  0
                                         String features = "height=600,width=960,dependent=0,directories=1," +
 473  
                                                         "fullscreen=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1";
 474  0
                                         Window.open(url, HTMLPanel.createUniqueId(), features);                                
 475  0
                                 }
 476  
                         });
 477  
                 }                
 478  
                         
 479  
                 //Determine if we need to display differing org highlight
 480  0
                 String orgHighlight = (diffAdminOrg ? " <span class=\"ks-dependency-highlight\">Different Org</span> ":"");
 481  
                 
 482  
                 //Create dependency item header label
 483  0
                 String headerLabel = "";
 484  0
                 if (LUUIConstants.DEP_TYPE_CROSS_LISTED.equals(dependencyType)){
 485  0
                         headerLabel = cluCode + " - " + selectedCourseName + orgHighlight;
 486  0
                 } else if (LUUIConstants.DEP_TYPE_COURSE_SET.equals(dependencyType)){
 487  0
                         headerLabel = cluName;
 488  
                 } else {
 489  0
                         headerLabel = cluCode + " - " + cluName + orgHighlight;
 490  
                 }
 491  
             
 492  
                 //Build header widget to return
 493  0
                 SpanPanel header = new SpanPanel();                
 494  0
                 header.setStyleName("KS-DependencyType-Label");        
 495  0
                 header.setHTML(headerLabel);
 496  0
                 if (viewLinkAnchor != null){
 497  0
                         header.add(viewLinkAnchor);
 498  
                 }
 499  
                 
 500  0
                 return header;                
 501  
         }
 502  
 
 503  
         protected boolean hasDependencyDetails(String dependencyType){
 504  
                 //Only course and programs have dependency details, since there could be multiple program types, easier to
 505  
                 //check those that don't have details to show.
 506  0
                 return !(LUUIConstants.DEP_TYPE_JOINT.equals(dependencyType) || 
 507  
                                         LUUIConstants.DEP_TYPE_CROSS_LISTED.equals(dependencyType) || 
 508  
                                         LUUIConstants.DEP_TYPE_COURSE_SET.equals(dependencyType));
 509  
         }
 510  
         
 511  
     private String getTotalCreditsString(int min, int max) {
 512  0
         return "Expected Total Credits:" + min + "-" + max;
 513  
     }
 514  
 
 515  
     //TODO: This code copied from Program summary, need to create reusable version for this and program summary
 516  
     protected Map<String, Widget> getCluSetWidgetList(StatementTreeViewInfo rule) {
 517  0
         Map<String, Widget> widgetList = new HashMap<String, Widget>();
 518  0
         Set<String> cluSetIds = new HashSet<String>();
 519  0
         findCluSetIds(rule, cluSetIds);
 520  0
         for (String clusetId : cluSetIds) {
 521  0
             widgetList.put(clusetId, new CluSetDetailsWidget(clusetId, cluSetRetriever));
 522  
         }
 523  
 
 524  0
         return widgetList;
 525  
     }
 526  
 
 527  
     //TODO: This code copied from Program summary, need to create reusable version for this and program summary
 528  
     private void findCluSetIds(StatementTreeViewInfo rule, Set<String> list) {
 529  
 
 530  0
         List<StatementTreeViewInfo> statements = rule.getStatements();
 531  0
         List<ReqComponentInfo> reqComponentInfos = rule.getReqComponents();
 532  
 
 533  0
         if ((statements != null) && (statements.size() > 0)) {
 534  
             // retrieve all statements
 535  0
             for (StatementTreeViewInfo statement : statements) {
 536  0
                 findCluSetIds(statement, list); // inside set the children of this statementTreeViewInfo
 537  
             }
 538  0
         } else if ((reqComponentInfos != null) && (reqComponentInfos.size() > 0)) {
 539  
             // retrieve all req. component LEAFS
 540  0
             for (ReqComponentInfo reqComponent : reqComponentInfos) {
 541  0
                 List<ReqCompFieldInfo> fieldInfos = reqComponent.getReqCompFields();
 542  0
                 for (ReqCompFieldInfo fieldInfo : fieldInfos) {
 543  0
                     if (RulesUtil.isCluSetWidget(fieldInfo.getType())) {
 544  0
                         list.add(fieldInfo.getValue());
 545  
                     }
 546  
                 }
 547  0
             }
 548  
         }
 549  0
     }
 550  
 
 551  
         public KSDocumentHeader getHeader() {
 552  0
                 return header;
 553  
         }
 554  
 
 555  
         @Override
 556  
         public boolean isExportButtonActive() {
 557  0
                 return true;
 558  
         }
 559  
 
 560  
         public DependencyResultPanel getDepResultPanel() {
 561  0
                 return depResultPanel;
 562  
         }
 563  
 
 564  
 }