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