Coverage Report - org.kuali.student.lum.common.client.widgets.CluSetDetailsWidget
 
Classes in this File Line Coverage Branch Coverage Complexity
CluSetDetailsWidget
0%
0/171
0%
0/76
3.588
CluSetDetailsWidget$1
0%
0/6
0%
0/2
3.588
CluSetDetailsWidget$2
0%
0/4
0%
0/2
3.588
CluSetDetailsWidget$3
0%
0/5
N/A
3.588
CluSetDetailsWidget$4
0%
0/13
0%
0/10
3.588
CluSetDetailsWidget$4$1
0%
0/5
0%
0/2
3.588
CluSetDetailsWidget$5
0%
0/5
N/A
3.588
 
 1  
 package org.kuali.student.lum.common.client.widgets;
 2  
 
 3  
 import java.text.SimpleDateFormat;
 4  
 import java.util.ArrayList;
 5  
 import java.util.Date;
 6  
 import java.util.HashMap;
 7  
 import java.util.List;
 8  
 import java.util.Map;
 9  
 
 10  
 import com.google.gwt.user.client.ui.*;
 11  
 
 12  
 import org.kuali.student.common.search.dto.SearchParam;
 13  
 import org.kuali.student.common.ui.client.mvc.Callback;
 14  
 import org.kuali.student.common.ui.client.reporting.ReportExportWidget;
 15  
 import org.kuali.student.common.ui.client.util.ExportElement;
 16  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 17  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 18  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 19  
 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
 20  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 21  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 22  
 import org.kuali.student.lum.lu.dto.CluSetInfo;
 23  
 import org.kuali.student.lum.lu.dto.MembershipQueryInfo;
 24  
 
 25  
 import com.google.gwt.dom.client.Style;
 26  
 import com.google.gwt.event.dom.client.ClickEvent;
 27  
 import com.google.gwt.event.dom.client.ClickHandler;
 28  
 import com.google.gwt.user.client.Window;
 29  
 
 30  0
 public class CluSetDetailsWidget extends Composite implements ReportExportWidget {
 31  
 
 32  
     private CluSetInformation cluSetInformation;
 33  
     private SimplePanel mainPanel;
 34  0
     private FlexTable detailsTable = new FlexTable();
 35  
     private boolean showClus;
 36  0
     private Map<String, Boolean> showCluSetFlags = new HashMap<String, Boolean>();
 37  0
     private static final SimpleDateFormat DT_FOMRAT = new SimpleDateFormat("MM/dd/yyyy");
 38  
     private CluSetRetriever cluSetRetriever;
 39  
     // private CluSetManagementRpcServiceAsync cluSetManagementRpcServiceAsync;
 40  0
     private BlockingTask retrievingTask = new BlockingTask("Retrieving details");
 41  
 
 42  0
     public CluSetDetailsWidget(CluSetInformation cluSetInformation, CluSetRetriever cluSetRetriever) {
 43  0
         mainPanel = new SimplePanel();
 44  0
         this.initWidget(mainPanel);
 45  0
         this.cluSetRetriever = cluSetRetriever;
 46  0
         setCluSetInformation(cluSetInformation);
 47  0
         redraw();
 48  0
     }
 49  
 
 50  0
     public CluSetDetailsWidget(String cluSetId, CluSetRetriever cluSetRetriever) {
 51  0
         mainPanel = new SimplePanel();
 52  0
         this.initWidget(mainPanel);
 53  0
         this.cluSetRetriever = cluSetRetriever;
 54  
 
 55  0
         KSBlockingProgressIndicator.addTask(retrievingTask);
 56  0
         cluSetRetriever.getCluSetInformation(cluSetId, new Callback<CluSetInformation>() {
 57  
             @Override
 58  
             public void exec(CluSetInformation result) {
 59  0
                 if (result != null) {
 60  0
                     setCluSetInformation(result);
 61  0
                     redraw();
 62  
                 }
 63  0
                 KSBlockingProgressIndicator.removeTask(retrievingTask);
 64  0
             }
 65  
         });
 66  0
     }
 67  
 
 68  
     private void redraw() {
 69  0
         List<CluInformation> clus = null;
 70  0
         List<CluSetInfo> cluSets = null;
 71  0
         MembershipQueryInfo membershipQueryInfo = null;
 72  0
         List<CluInformation> clusInRange = null;
 73  0
         int rowIndex = 0;
 74  0
         mainPanel.clear();
 75  0
         detailsTable.clear();
 76  0
         if (cluSetInformation == null) {
 77  0
             return;
 78  
         } else {
 79  0
             clus = cluSetInformation.getClus();
 80  0
             cluSets = cluSetInformation.getCluSets();
 81  0
             membershipQueryInfo = cluSetInformation.getMembershipQueryInfo();
 82  0
             clusInRange = cluSetInformation.getClusInRange();
 83  
         }
 84  0
         StringBuilder titleTextSb = new StringBuilder();
 85  0
         titleTextSb.append("INDIVIDUAL COURSE(S)");
 86  0
         KSLabel coursesHeader = new KSLabel(titleTextSb.toString());
 87  
         // coursesHeader.getElement().getStyle().setProperty("borderBottom", "1px solid #D8D8D8");
 88  0
         detailsTable.setWidget(rowIndex, 0, coursesHeader);
 89  0
         detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 2);
 90  0
         if (cluSets != null && cluSets.size() > 0 || clusInRange != null && clusInRange.size() > 0) {
 91  0
             coursesHeader.setVisible(true);
 92  
         } else {
 93  0
             coursesHeader.setVisible(false);
 94  
         }
 95  
         {
 96  
             // show/hide clus
 97  0
             int numClus = (clus == null) ? 0 : clus.size();
 98  0
             StringBuilder hideClusTextSb = new StringBuilder();
 99  0
             showClus = true;
 100  0
             if (showClus) {
 101  0
                 hideClusTextSb.append("Hide courses(").append(numClus).append(")");
 102  
             } else {
 103  0
                 hideClusTextSb.append("Show courses(").append(numClus).append(")");
 104  
             }
 105  0
             KSButton hideClusButton = new KSButton(hideClusTextSb.toString(), ButtonStyle.DEFAULT_ANCHOR);
 106  0
             detailsTable.setWidget(rowIndex, 1, hideClusButton);
 107  0
             hideClusButton.addClickHandler(new ClickHandler() {
 108  
                 @Override
 109  
                 public void onClick(ClickEvent event) {
 110  0
                     showClus = !showClus;
 111  0
                     redraw();
 112  0
                 }
 113  
             });
 114  0
             if (numClus > 10) {
 115  0
                 hideClusButton.setVisible(true);
 116  
             } else {
 117  0
                 hideClusButton.setVisible(false);
 118  
             }
 119  
         }
 120  
 
 121  0
         rowIndex++;
 122  0
         if (clus != null && showClus) {
 123  0
             for (CluInformation clu : clus) {
 124  0
                 addClusDisplayToTable(rowIndex, clu);
 125  0
                 rowIndex++;
 126  
             }
 127  
         }
 128  0
         if (cluSets != null) {
 129  0
             if (cluSets.size() > 0) {
 130  0
                 KSLabel spacer = new KSLabel();
 131  0
                 spacer.getElement().getStyle().setPaddingTop(10, Style.Unit.PX);
 132  0
                 detailsTable.setWidget(rowIndex, 0, spacer);
 133  0
                 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 3);
 134  0
                 rowIndex++;
 135  
             }
 136  0
             for (final CluSetInfo cluSet : cluSets) {
 137  0
                 int columnIndex = 0;
 138  0
                 final String cluSetId = cluSet.getId();
 139  0
                 HorizontalPanel cluSetNamePanel = new HorizontalPanel();
 140  0
                 Anchor cluSetNameLabel = new Anchor(cluSet.getName());
 141  0
                 cluSetNameLabel.addClickHandler(new ClickHandler() {
 142  
 
 143  
                     @Override
 144  
                     public void onClick(ClickEvent event) {
 145  0
                         String url = "http://" + Window.Location.getHost() + Window.Location.getPath() + "?view=" + AppLocations.Locations.VIEW_CLU_SET + "&docId=" + cluSetId;
 146  0
                         String features = "height=600,width=960,dependent=0,directories=1," + "fullscreen=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1";
 147  0
                         Window.open(url, HTMLPanel.createUniqueId(), features);
 148  
 
 149  0
                     }
 150  
                 });
 151  0
                 KSLabel itemType = new KSLabel("Course Set");
 152  0
                 itemType.getElement().getStyle().setProperty("color", "grey");
 153  0
                 itemType.getElement().getStyle().setPaddingLeft(5, Style.Unit.PX);
 154  0
                 cluSetNamePanel.add(cluSetNameLabel);
 155  0
                 cluSetNamePanel.add(itemType);
 156  0
                 boolean showCluSet = (showCluSetFlags.get(cluSet.getId()) == null) ? false : showCluSetFlags.get(cluSet.getId()).booleanValue();
 157  0
                 detailsTable.setWidget(rowIndex, columnIndex, cluSetNamePanel);
 158  0
                 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1);
 159  0
                 columnIndex++;
 160  
 
 161  
                 // show/hide sub cluSet details
 162  
                 // increment columnIndex to make the show/hide link to show at the right most column
 163  0
                 columnIndex++;
 164  0
                 StringBuilder hideCluSetTextSb = new StringBuilder();
 165  0
                 if (showCluSet) {
 166  0
                     hideCluSetTextSb.append("Hide Courses");
 167  
                 } else {
 168  0
                     hideCluSetTextSb.append("Show Courses");
 169  
                 }
 170  0
                 KSButton hideCluSetButton = new KSButton(hideCluSetTextSb.toString(), ButtonStyle.DEFAULT_ANCHOR);
 171  0
                 detailsTable.setWidget(rowIndex, columnIndex, hideCluSetButton);
 172  0
                 rowIndex++;
 173  0
                 hideCluSetButton.addClickHandler(new ClickHandler() {
 174  
                     @Override
 175  
                     public void onClick(ClickEvent event) {
 176  0
                         Boolean showCluSetDetails = showCluSetFlags.get(cluSet.getId());
 177  0
                         showCluSetDetails = (showCluSetDetails == null) ? false : showCluSetDetails;
 178  0
                         showCluSetFlags.put(cluSet.getId(), !showCluSetDetails);
 179  0
                         Boolean newShowCluSetDetails = !showCluSetDetails;
 180  0
                         if (newShowCluSetDetails) {
 181  0
                             CluSetInformation subCluSetInformation = cluSetInformation.getSubCluSetInformations().get(cluSet.getId());
 182  0
                             if (subCluSetInformation == null) {
 183  0
                                 cluSetRetriever.getCluSetInformation(cluSet.getId(), new Callback<CluSetInformation>() {
 184  
                                     @Override
 185  
                                     public void exec(CluSetInformation result) {
 186  0
                                         if (result != null) {
 187  0
                                             cluSetInformation.getSubCluSetInformations().put(cluSet.getId(), result);
 188  0
                                             redraw();
 189  
                                         }
 190  0
                                     }
 191  
                                 });
 192  
                             } else {
 193  0
                                 redraw();
 194  
                             }
 195  0
                         } else {
 196  0
                             redraw();
 197  
                         }
 198  0
                     }
 199  
                 });
 200  0
                 if (showCluSet) {
 201  0
                     CluSetInformation subCluSetInformation = cluSetInformation.getSubCluSetInformations().get(cluSet.getId());
 202  0
                     CluSetDetailsWidget subCluSetWidget = new CluSetDetailsWidget(subCluSetInformation, cluSetRetriever);
 203  0
                     subCluSetWidget.getElement().getStyle().setPaddingLeft(20, Style.Unit.PX);
 204  0
                     detailsTable.setWidget(rowIndex, 0, subCluSetWidget);
 205  0
                     detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 3);
 206  0
                     rowIndex++;
 207  
                 }
 208  
 
 209  0
             }
 210  
         }
 211  0
         if (membershipQueryInfo != null) {
 212  0
             List<SearchParam> searchParams = membershipQueryInfo.getQueryParamValueList();
 213  0
             if (searchParams != null) {
 214  0
                 HorizontalPanel queryDisplayPanel = new HorizontalPanel();
 215  0
                 for (SearchParam searchParam : searchParams) {
 216  0
                     KSLabel paramDescLabel = new KSLabel();
 217  0
                     KSLabel paramValueLabel = new KSLabel();
 218  0
                     String paramDesc = translateSearchKey(searchParam.getKey());
 219  0
                     paramDescLabel.setText(paramDesc);
 220  0
                     Object value = searchParam.getValue();
 221  0
                     String displayValue = "";
 222  0
                     if (value instanceof Date) {
 223  0
                         displayValue = DT_FOMRAT.format((Date) value);
 224  
                     } else {
 225  0
                         displayValue = value.toString();
 226  
                     }
 227  0
                     paramDescLabel.getElement().getStyle().setProperty("color", "grey");
 228  0
                     paramDescLabel.getElement().getStyle().setPaddingRight(5, Style.Unit.PX);
 229  0
                     paramValueLabel.setText(displayValue);
 230  0
                     paramValueLabel.getElement().getStyle().setPaddingRight(10, Style.Unit.PX);
 231  0
                     queryDisplayPanel.getElement().getStyle().setPaddingTop(10, Style.Unit.PX);
 232  0
                     queryDisplayPanel.add(paramDescLabel);
 233  0
                     queryDisplayPanel.add(paramValueLabel);
 234  0
                 }
 235  0
                 detailsTable.setWidget(rowIndex, 0, queryDisplayPanel);
 236  0
                 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 2);
 237  0
                 rowIndex++;
 238  
             }
 239  0
             if (clusInRange != null) {
 240  0
                 for (CluInformation clu : clusInRange) {
 241  0
                     addClusDisplayToTable(rowIndex, clu);
 242  0
                     rowIndex++;
 243  
                 }
 244  
             } else {
 245  0
                 Window.alert("num clusInRange is null");
 246  
             }
 247  
         }
 248  0
         mainPanel.setWidget(detailsTable);
 249  0
     }
 250  
 
 251  
     private void addClusDisplayToTable(int rowIndex, final CluInformation clu) {
 252  0
         int columnIndex = 0;
 253  0
         KSButton cluCodeLink = new KSButton(clu.getCode(), ButtonStyle.DEFAULT_ANCHOR);
 254  0
         cluCodeLink.getElement().getStyle().setPaddingLeft(10, Style.Unit.PX);
 255  0
         detailsTable.setWidget(rowIndex, columnIndex, cluCodeLink);
 256  0
         detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1);
 257  0
         cluCodeLink.addClickHandler(new ClickHandler() {
 258  
             @Override
 259  
             public void onClick(ClickEvent event) {
 260  0
                 String url = "http://" + Window.Location.getHost() + Window.Location.getPath() + "?view=" + AppLocations.Locations.VIEW_COURSE + "&idType=" + IdType.OBJECT_ID + "&docId=" + clu.getVerIndependentId();
 261  0
                 String features = "height=600,width=960,dependent=0,directories=1," + "fullscreen=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1";
 262  0
                 Window.open(url, HTMLPanel.createUniqueId(), features);
 263  0
             }
 264  
         });
 265  0
         columnIndex++;
 266  
 
 267  0
         HTML cluTitleLabel = new HTML("<h5>" + clu.getTitle() + "</h5>");
 268  0
         detailsTable.setWidget(rowIndex, columnIndex, cluTitleLabel);
 269  0
         detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1);
 270  0
         columnIndex++;
 271  
 
 272  0
         if (clu.getCredits() != null && !clu.getCredits().trim().isEmpty()) {
 273  0
             HTML cluCreditsLabel = new HTML("<h5>" + clu.getCredits() + " credits" + "</h5>");
 274  0
             detailsTable.setWidget(rowIndex, columnIndex, cluCreditsLabel);
 275  0
             detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1);
 276  0
             columnIndex++;
 277  
         }
 278  0
     }
 279  
 
 280  
     private String translateSearchKey(String searchKey) {
 281  0
         String result = "";
 282  0
         if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalDivision")) {
 283  0
             result = "Department";
 284  0
         } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalCrsNoRange")) {
 285  0
             result = "Course Number Range";
 286  0
         } else if (searchKey != null && searchKey.equals("lo.queryParam.loDescPlain")) {
 287  0
             result = "Description";
 288  0
         } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate1")) {
 289  0
             result = "Effective From";
 290  0
         } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate2")) {
 291  0
             result = "Effective To";
 292  0
         } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate2")) {
 293  
 
 294  
         }
 295  
 
 296  0
         return result;
 297  
     }
 298  
 
 299  
     public CluSetInformation getCluSetInformation() {
 300  0
         return cluSetInformation;
 301  
     }
 302  
 
 303  
     public void setCluSetInformation(CluSetInformation cluSetInformation) {
 304  0
         this.cluSetInformation = cluSetInformation;
 305  0
     }
 306  
 
 307  
     public String toString() {
 308  0
         return detailsTable.toString();
 309  
     }
 310  
 
 311  
     @Override
 312  
     public boolean isExportElement() {
 313  0
         return true;
 314  
     }
 315  
 
 316  
     @Override
 317  
     public List<ExportElement> getExportElementSubset(ExportElement parent) {
 318  0
         List<CluInformation> items = this.cluSetInformation.getClus();
 319  0
         ArrayList<ExportElement> subItems = new ArrayList<ExportElement>();
 320  0
         for (int i = 0; i < items.size(); i++) {
 321  0
             ExportElement subelement = new ExportElement(parent.getViewName(), parent.getSectionName());
 322  0
             subelement.setFieldValue(items.get(i).getCode() + " " + items.get(i).getTitle() + " " + items.get(i).getCredits() + " credits");
 323  0
             subItems.add(subelement);
 324  
         }
 325  0
         return subItems;
 326  
     }
 327  
 
 328  
     @Override
 329  
     public String getExportFieldValue() {
 330  0
         return null;
 331  
     }
 332  
 
 333  
 }