View Javadoc

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