1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
package org.kuali.student.common.ui.client.util; |
10 | |
|
11 | |
import java.util.ArrayList; |
12 | |
import java.util.List; |
13 | |
|
14 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
15 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
16 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection; |
17 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
18 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.WarnContainer; |
19 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; |
20 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
21 | |
import org.kuali.student.common.ui.client.reporting.ReportExportWidget; |
22 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
23 | |
import org.kuali.student.common.ui.client.widgets.KSItemLabel; |
24 | |
import org.kuali.student.common.ui.client.widgets.ULPanel; |
25 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement; |
26 | |
import org.kuali.student.common.ui.client.widgets.list.KSLabelList; |
27 | |
import org.kuali.student.common.ui.client.widgets.list.KSSelectedList; |
28 | |
import org.kuali.student.common.ui.client.widgets.menus.KSListPanel; |
29 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
30 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTable; |
31 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableBlock; |
32 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableModel; |
33 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableRow; |
34 | |
|
35 | |
import com.google.gwt.user.client.ui.ComplexPanel; |
36 | |
import com.google.gwt.user.client.ui.FlowPanel; |
37 | |
import com.google.gwt.user.client.ui.HasHTML; |
38 | |
import com.google.gwt.user.client.ui.HasText; |
39 | |
import com.google.gwt.user.client.ui.ListBox; |
40 | |
import com.google.gwt.user.client.ui.Widget; |
41 | |
import com.google.gwt.user.client.ui.WidgetCollection; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 0 | public class ExportUtils { |
51 | |
public static final String PDF = "PDF"; |
52 | |
public static final String DOC = "DOC"; |
53 | |
public static final String XLS = "XLS"; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public static ExportElement getExportItemDetails(ExportElement exportItem, Widget fieldWidget, boolean setFirstFieldValue, String viewName, String sectionName) { |
67 | |
|
68 | |
|
69 | 0 | if (!fieldWidget.getParent().getElement().getStyle().getDisplay().equals("none")){ |
70 | |
|
71 | 0 | if (fieldWidget instanceof HasHTML) { |
72 | |
|
73 | 0 | HasHTML itemHasHTML = (HasHTML) fieldWidget; |
74 | 0 | setFieldValue(exportItem, setFirstFieldValue, itemHasHTML.getHTML()); |
75 | |
|
76 | 0 | } else if (fieldWidget instanceof HasText) { |
77 | |
|
78 | 0 | HasText itemHasTextValue = (HasText) fieldWidget; |
79 | 0 | setFieldValue(exportItem, setFirstFieldValue, itemHasTextValue.getText()); |
80 | |
|
81 | 0 | } else if (fieldWidget instanceof KSSelectedList) { |
82 | 0 | KSSelectedList selectedList = (KSSelectedList) fieldWidget; |
83 | 0 | List<KSItemLabel> selectedItems = selectedList.getSelectedItems(); |
84 | 0 | String values = new String(); |
85 | 0 | for (int j = 0; j < selectedItems.size(); j++) { |
86 | 0 | values = selectedItems.get(j).getDisplayText(); |
87 | |
} |
88 | 0 | setFieldValue(exportItem, setFirstFieldValue, values); |
89 | |
|
90 | 0 | } else if (fieldWidget instanceof KSPicker) { |
91 | 0 | KSPicker picker = (KSPicker) fieldWidget; |
92 | 0 | if (picker.getInputWidget() instanceof HasText) { |
93 | 0 | HasText item = (HasText) picker.getInputWidget(); |
94 | 0 | setFieldValue(exportItem, setFirstFieldValue, item.getText()); |
95 | 0 | } else if (picker.getInputWidget() instanceof KSLabelList) { |
96 | 0 | String fieldValue = null; |
97 | 0 | KSLabelList widget = (KSLabelList) picker.getInputWidget(); |
98 | 0 | List<String> selected = widget.getSelectedItemsForExport(); |
99 | 0 | for (int j = 0; j < selected.size(); j++) { |
100 | 0 | if (fieldValue == null) { |
101 | 0 | fieldValue = new String(selected.get(j)); |
102 | |
} else { |
103 | 0 | fieldValue = fieldValue + ", " + selected.get(j); |
104 | |
} |
105 | |
} |
106 | 0 | setFieldValue(exportItem, setFirstFieldValue, fieldValue); |
107 | |
} |
108 | |
|
109 | 0 | } else if (fieldWidget instanceof ListBox) { |
110 | |
|
111 | 0 | ListBox listBox = (ListBox) fieldWidget; |
112 | 0 | setFieldValue(exportItem, setFirstFieldValue, listBox.getItemText(listBox.getSelectedIndex())); |
113 | |
|
114 | 0 | } else if (fieldWidget instanceof SectionTitle) { |
115 | |
try { |
116 | |
|
117 | 0 | SectionTitle sectionTitle = (SectionTitle) fieldWidget; |
118 | 0 | setFieldValue(exportItem, setFirstFieldValue, sectionTitle.getExportFieldValue()); |
119 | |
|
120 | 0 | if (!exportItem.getValue().contains("<b>")){ |
121 | 0 | exportItem.setPrintType(ExportElement.BOLD); |
122 | |
} |
123 | 0 | } catch (Exception e) { |
124 | |
|
125 | 0 | } |
126 | |
|
127 | 0 | } else if (fieldWidget instanceof SummaryTable) { |
128 | |
|
129 | 0 | if (fieldWidget.isVisible()){ |
130 | 0 | exportItem.setSubset(ExportUtils.getDetailsForWidget((SummaryTable)fieldWidget)); |
131 | |
} |
132 | |
|
133 | 0 | } else if (fieldWidget instanceof ReportExportWidget) { |
134 | |
|
135 | 0 | if (fieldWidget.isVisible()){ |
136 | 0 | ReportExportWidget widget = (ReportExportWidget) fieldWidget; |
137 | 0 | if (widget.isExportElement() ) { |
138 | 0 | exportItem.setSubset(widget.getExportElementSubset(exportItem)); |
139 | 0 | setFieldValue(exportItem, setFirstFieldValue, widget.getExportFieldValue()); |
140 | |
} |
141 | 0 | } |
142 | |
|
143 | 0 | } else if (fieldWidget instanceof ComplexPanel) { |
144 | |
|
145 | 0 | if(fieldWidget.isVisible()) { |
146 | 0 | exportItem.setSubset(ExportUtils.getDetailsForWidget(fieldWidget, viewName, sectionName)); |
147 | |
} |
148 | |
|
149 | 0 | } else if (fieldWidget instanceof FieldElement) { |
150 | |
|
151 | 0 | if(fieldWidget.isVisible()) { |
152 | 0 | Widget widget = ((FieldElement)fieldWidget).getFieldWidget(); |
153 | 0 | exportItem = getExportItemDetails(exportItem, widget, true, viewName, sectionName); |
154 | 0 | exportItem.setPrintType(ExportElement.PARAGRAPH); |
155 | |
} |
156 | |
|
157 | |
} else { |
158 | |
|
159 | |
} |
160 | |
|
161 | |
|
162 | |
} |
163 | 0 | return exportItem; |
164 | |
} |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
private static void setFieldValue(ExportElement exportItem, boolean setFirstFieldValue, String fieldValue) { |
176 | 0 | if (setFirstFieldValue) { |
177 | 0 | exportItem.setFieldValue(fieldValue); |
178 | |
} else { |
179 | 0 | exportItem.setFieldValue2(fieldValue); |
180 | |
} |
181 | 0 | } |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
public static Controller getController(Widget theWidget) { |
192 | |
|
193 | |
|
194 | 0 | if (theWidget != null) { |
195 | |
|
196 | 0 | if (theWidget instanceof Controller) { |
197 | 0 | Controller controller = (Controller) theWidget; |
198 | 0 | return controller; |
199 | |
} else { |
200 | 0 | return getController(theWidget.getParent()); |
201 | |
} |
202 | |
} else { |
203 | 0 | return null; |
204 | |
} |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
public static void handleExportClickEvent(Controller currentController, String format, String reportTitle) { |
215 | 0 | List<ExportElement> exportElements = new ArrayList<ExportElement>(); |
216 | 0 | exportElements = currentController.getExportElementsFromView(); |
217 | 0 | if (exportElements != null && exportElements.size() > 0) { |
218 | 0 | currentController.doReportExport(exportElements, format, reportTitle); |
219 | |
} |
220 | 0 | } |
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
public static List<ExportElement> getDetailsForWidget(SummaryTable sumTable) { |
231 | 0 | List<ExportElement> exportElements = new ArrayList<ExportElement>(); |
232 | 0 | SummaryTableModel model = sumTable.getModel(); |
233 | |
|
234 | |
|
235 | 0 | for (SummaryTableBlock block : model.getSectionList()) { |
236 | 0 | String blockName = block.getTitle(); |
237 | |
|
238 | |
|
239 | 0 | for (SummaryTableRow row : block.getSectionRowList()) { |
240 | 0 | ExportElement element = new ExportElement(); |
241 | 0 | element.setSectionName(blockName); |
242 | 0 | element.setViewName(blockName); |
243 | 0 | element.setFieldLabel(row.getTitle()); |
244 | 0 | element.setMandatory(row.isRequired()); |
245 | |
|
246 | |
|
247 | 0 | if (row.isShown()) { |
248 | |
|
249 | 0 | element = setSummaryElement(blockName, row, element, row.getCell1(), true); |
250 | |
|
251 | 0 | element = setSummaryElement(blockName, row, element, row.getCell2(), false); |
252 | |
|
253 | 0 | if (element != null && element.getViewName() != null) { |
254 | 0 | exportElements.add(element); |
255 | |
} |
256 | |
} |
257 | |
|
258 | 0 | } |
259 | 0 | } |
260 | 0 | return exportElements; |
261 | |
} |
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
private static ExportElement setSummaryElement(String blockName, SummaryTableRow row, ExportElement element, Widget fdWidget, boolean setFirstFieldValue) { |
274 | 0 | if (fdWidget != null) { |
275 | 0 | if (fdWidget instanceof KSListPanel) { |
276 | 0 | element.setSubset(ExportUtils.getDetailsForWidget(fdWidget, blockName, blockName)); |
277 | |
} else { |
278 | 0 | element = ExportUtils.getExportItemDetails(element, fdWidget, setFirstFieldValue, blockName, blockName); |
279 | |
} |
280 | |
} else { |
281 | 0 | if (row.getTitle() != null) { |
282 | 0 | element.setFieldLabel(row.getTitle()); |
283 | |
} |
284 | |
} |
285 | 0 | return element; |
286 | |
} |
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
public static List<ExportElement> getDetailsForWidget(Widget currentViewWidget, String viewName, String sectionName) { |
298 | 0 | List<ExportElement> childElements = new ArrayList<ExportElement>(); |
299 | 0 | if (!currentViewWidget.getParent().getElement().getStyle().getDisplay().equals("none")){ |
300 | 0 | if (currentViewWidget instanceof Section) { |
301 | 0 | Section widgetHasFields = (Section) currentViewWidget; |
302 | 0 | List<FieldDescriptor> widgetFields = widgetHasFields.getFields(); |
303 | 0 | for (FieldDescriptor field : widgetFields) { |
304 | 0 | ExportElement exportItem = createExportElement(viewName, sectionName, childElements, field.getFieldElement().getFieldWidget()); |
305 | 0 | exportItem.setFieldLabel(field.getFieldLabel()); |
306 | 0 | } |
307 | 0 | } else if (currentViewWidget instanceof KSListPanel) { |
308 | 0 | KSListPanel ksListPanelWidget = (KSListPanel) currentViewWidget; |
309 | 0 | WidgetCollection children = ksListPanelWidget.getChildren(); |
310 | 0 | for (int i = 0; i < children.size(); i++) { |
311 | 0 | createExportElement(viewName, sectionName, childElements, children.get(i)); |
312 | |
} |
313 | |
|
314 | 0 | } else if (currentViewWidget instanceof ULPanel) { |
315 | 0 | ComplexPanel complexPanel = (ComplexPanel) currentViewWidget; |
316 | 0 | if (complexPanel.isVisible()){ |
317 | 0 | for (int i = 0; i < complexPanel.getWidgetCount(); i++) { |
318 | 0 | Widget child = complexPanel.getWidget(i); |
319 | 0 | if (child instanceof FlowPanel){ |
320 | 0 | List<ExportElement> subset = ExportUtils.getDetailsForWidget(child, viewName, sectionName); |
321 | 0 | if (subset != null && subset.size() > 0){ |
322 | 0 | subset.get(0).setPrintType(ExportElement.LIST); |
323 | 0 | childElements.addAll(subset); |
324 | |
} |
325 | |
|
326 | 0 | } else if (!(child instanceof KSButton) |
327 | |
&& !(child instanceof WarnContainer)) { |
328 | 0 | ExportElement exportItem = createExportElement(viewName, sectionName, childElements, child); |
329 | 0 | exportItem.setPrintType(ExportElement.LIST); |
330 | |
} |
331 | |
} |
332 | |
} |
333 | |
|
334 | 0 | } else if (currentViewWidget instanceof ComplexPanel) { |
335 | 0 | ComplexPanel complexPanel = (ComplexPanel) currentViewWidget; |
336 | 0 | if (complexPanel.isVisible()){ |
337 | 0 | for (int i = 0; i < complexPanel.getWidgetCount(); i++) { |
338 | 0 | Widget child = complexPanel.getWidget(i); |
339 | 0 | if (child instanceof FlowPanel){ |
340 | 0 | List<ExportElement> subset = ExportUtils.getDetailsForWidget(child, viewName, sectionName); |
341 | 0 | if (subset != null && subset.size() > 0){ |
342 | 0 | childElements.addAll(subset); |
343 | |
} |
344 | |
|
345 | 0 | } else if (!(child instanceof KSButton) |
346 | |
&& !(child instanceof WarnContainer)) { |
347 | 0 | createExportElement(viewName, sectionName, childElements, child); |
348 | |
} |
349 | |
} |
350 | |
} |
351 | 0 | } else { |
352 | |
|
353 | 0 | System.out.println("ExportUtils does not cater for this type..." + currentViewWidget.getClass().getName()); |
354 | |
|
355 | |
} |
356 | |
} |
357 | 0 | return childElements; |
358 | |
} |
359 | |
|
360 | |
|
361 | |
public static List<ExportElement> getDetailsForWidget(ExportElement element, Widget currentViewWidget, boolean setFirstFieldValue, String viewName, String sectionName) { |
362 | 0 | List<ExportElement> childElements = new ArrayList<ExportElement>(); |
363 | 0 | if (!currentViewWidget.getParent().getElement().getStyle().getDisplay().equals("none")){ |
364 | 0 | if (currentViewWidget instanceof Section) { |
365 | 0 | Section widgetHasFields = (Section) currentViewWidget; |
366 | 0 | List<FieldDescriptor> widgetFields = widgetHasFields.getFields(); |
367 | 0 | for (FieldDescriptor field : widgetFields) { |
368 | 0 | ExportElement exportItem = createExportElement(viewName, sectionName, childElements, field.getFieldElement().getFieldWidget()); |
369 | 0 | exportItem.setFieldLabel(field.getFieldLabel()); |
370 | 0 | } |
371 | 0 | } else if (currentViewWidget instanceof KSListPanel) { |
372 | 0 | KSListPanel ksListPanelWidget = (KSListPanel) currentViewWidget; |
373 | 0 | WidgetCollection children = ksListPanelWidget.getChildren(); |
374 | 0 | for (int i = 0; i < children.size(); i++) { |
375 | 0 | if (!element.getSubset().isEmpty() && i < element.getSubset().size()) |
376 | 0 | createExportElementOld(element.getSubset().get(i), viewName, sectionName, childElements, children.get(i)); |
377 | |
else |
378 | 0 | createExportElement2(viewName, sectionName, childElements, children.get(i)); |
379 | |
} |
380 | 0 | } else if (currentViewWidget instanceof ULPanel) { |
381 | 0 | ComplexPanel complexPanel = (ComplexPanel) currentViewWidget; |
382 | 0 | if (complexPanel.isVisible()){ |
383 | 0 | for (int i = 0; i < complexPanel.getWidgetCount(); i++) { |
384 | 0 | Widget child = complexPanel.getWidget(i); |
385 | 0 | if (child instanceof FlowPanel){ |
386 | 0 | List<ExportElement> subset = ExportUtils.getDetailsForWidget(child, viewName, sectionName); |
387 | 0 | if (subset != null && subset.size() > 0){ |
388 | 0 | subset.get(0).setPrintType(ExportElement.LIST); |
389 | 0 | childElements.addAll(subset); |
390 | |
} |
391 | |
|
392 | 0 | } else if (!(child instanceof KSButton) |
393 | |
&& !(child instanceof WarnContainer)) { |
394 | 0 | ExportElement exportItem = createExportElement(viewName, sectionName, childElements, child); |
395 | 0 | exportItem.setPrintType(ExportElement.LIST); |
396 | |
} |
397 | |
} |
398 | |
} |
399 | |
|
400 | 0 | } else if (currentViewWidget instanceof ComplexPanel) { |
401 | 0 | ComplexPanel complexPanel = (ComplexPanel) currentViewWidget; |
402 | 0 | if (complexPanel.isVisible()){ |
403 | 0 | for (int i = 0; i < complexPanel.getWidgetCount(); i++) { |
404 | 0 | Widget child = complexPanel.getWidget(i); |
405 | 0 | if (child instanceof FlowPanel){ |
406 | 0 | List<ExportElement> subset = ExportUtils.getDetailsForWidget(child, viewName, sectionName); |
407 | 0 | if (subset != null && subset.size() > 0){ |
408 | 0 | childElements.addAll(subset); |
409 | |
} |
410 | |
|
411 | 0 | } else if (!(child instanceof KSButton) |
412 | |
&& !(child instanceof WarnContainer)) { |
413 | 0 | createExportElement(viewName, sectionName, childElements, child); |
414 | |
} |
415 | |
} |
416 | |
} |
417 | 0 | } else { |
418 | |
|
419 | 0 | System.out.println("ExportUtils does not cater for this type..." + currentViewWidget.getClass().getName()); |
420 | |
|
421 | |
} |
422 | |
} |
423 | 0 | return childElements; |
424 | |
} |
425 | |
|
426 | |
public static ArrayList<ExportElement> getExportElementsFromView(Widget currentViewWidget, ArrayList<ExportElement> exportElements, String viewName, String sectionName) { |
427 | 0 | if (exportElements == null) { |
428 | 0 | exportElements = new ArrayList<ExportElement>(); |
429 | |
} |
430 | 0 | if (currentViewWidget.getParent() == null || !currentViewWidget.getParent().getElement().getStyle().getDisplay().equals("none")) { |
431 | 0 | if (currentViewWidget instanceof VerticalSectionView) { |
432 | 0 | Section widgetHasFields = (Section) currentViewWidget; |
433 | 0 | List<FieldDescriptor> widgetFields = widgetHasFields.getFields(); |
434 | 0 | for (FieldDescriptor field : widgetFields) { |
435 | 0 | Widget child = field.getFieldElement().getFieldWidget(); |
436 | 0 | ExportElement exportItem = createExportElement(viewName, sectionName, exportElements, child); |
437 | 0 | exportItem.setFieldLabel(field.getFieldLabel()); |
438 | 0 | } |
439 | 0 | if ((currentViewWidget instanceof BaseSection) && (widgetHasFields.getFields().size() == 0)) { |
440 | 0 | BaseSection bSection = (BaseSection) currentViewWidget; |
441 | 0 | createExportElement(viewName, sectionName, exportElements, bSection.getLayout()); |
442 | |
} |
443 | |
} |
444 | |
} |
445 | 0 | return exportElements; |
446 | |
} |
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
private static ExportElement createExportElement(String viewName, String sectionName, List<ExportElement> childElements, Widget child) { |
459 | 0 | ExportElement exportItem = new ExportElement(); |
460 | 0 | exportItem.setSectionName(sectionName); |
461 | 0 | exportItem.setViewName(viewName); |
462 | |
|
463 | 0 | exportItem = getExportItemDetails(exportItem, child, true, viewName, sectionName); |
464 | 0 | ExportUtils.addElementToElementArray(childElements, exportItem); |
465 | 0 | return exportItem; |
466 | |
} |
467 | |
|
468 | |
private static ExportElement createExportElement2(String viewName, String sectionName, List<ExportElement> childElements, Widget child) { |
469 | 0 | ExportElement exportItem = new ExportElement(); |
470 | 0 | exportItem.setSectionName(sectionName); |
471 | 0 | exportItem.setViewName(viewName); |
472 | |
|
473 | 0 | exportItem = getExportItemDetails(exportItem, child, false, viewName, sectionName); |
474 | 0 | ExportUtils.addElementToElementArray(childElements, exportItem); |
475 | 0 | return exportItem; |
476 | |
} |
477 | |
|
478 | |
private static ExportElement createExportElementOld(ExportElement exportItem, String viewName, String sectionName, List<ExportElement> childElements, Widget child) { |
479 | 0 | exportItem = getExportItemDetails(exportItem, child, false, viewName, sectionName); |
480 | 0 | ExportUtils.addElementToElementArray(childElements, exportItem); |
481 | 0 | return exportItem; |
482 | |
} |
483 | |
|
484 | |
|
485 | |
public static List<ExportElement> addElementToElementArray(List<ExportElement> elementArray, ExportElement element) { |
486 | 0 | if (element.getFieldLabel() != null || element.getFieldValue() != null || element.getFieldValue2() != null || (element.getSubset() != null && element.getSubset().size() > 0)) { |
487 | 0 | elementArray.add(element); |
488 | |
} |
489 | 0 | return elementArray; |
490 | |
} |
491 | |
|
492 | |
} |