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.views.VerticalSectionView; |
19 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
20 | |
import org.kuali.student.common.ui.client.mvc.View; |
21 | |
import org.kuali.student.common.ui.client.widgets.KSItemLabel; |
22 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
23 | |
import org.kuali.student.common.ui.client.widgets.list.KSLabelList; |
24 | |
import org.kuali.student.common.ui.client.widgets.list.KSSelectedList; |
25 | |
import org.kuali.student.common.ui.client.widgets.menus.KSListPanel; |
26 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
27 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTable; |
28 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableBlock; |
29 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableModel; |
30 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableRow; |
31 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection; |
32 | |
|
33 | |
import com.google.gwt.user.client.ui.ComplexPanel; |
34 | |
import com.google.gwt.user.client.ui.HasText; |
35 | |
import com.google.gwt.user.client.ui.ListBox; |
36 | |
import com.google.gwt.user.client.ui.Widget; |
37 | |
import com.google.gwt.user.client.ui.WidgetCollection; |
38 | |
|
39 | 0 | public class ExportUtils { |
40 | |
public static final String PDF = "PDF"; |
41 | |
public static final String DOC = "DOC"; |
42 | |
public static final String XLS = "XLS"; |
43 | |
|
44 | |
public static ExportElement getExportItemDetails(ExportElement exportItem, Widget fieldWidget, boolean setFirstFieldValue, String viewName, String sectionName) { |
45 | 0 | ArrayList<ExportElement> subExportElements = new ArrayList<ExportElement>(); |
46 | 0 | String fieldValue = null; |
47 | 0 | if (fieldWidget instanceof HasText) { |
48 | 0 | HasText itemHasTextValue = (HasText) fieldWidget; |
49 | 0 | fieldValue = itemHasTextValue.getText(); |
50 | |
|
51 | 0 | } else if (fieldWidget instanceof KSLabel) { |
52 | |
|
53 | 0 | } else if (fieldWidget instanceof KSSelectedList) { |
54 | 0 | KSSelectedList selectedList = (KSSelectedList) fieldWidget; |
55 | 0 | List<KSItemLabel> selectedItems = selectedList.getSelectedItems(); |
56 | 0 | String values = new String(); |
57 | 0 | for (int j = 0; j < selectedItems.size(); j++) { |
58 | 0 | values = selectedItems.get(j).getDisplayText(); |
59 | |
} |
60 | 0 | fieldValue = values; |
61 | 0 | } else if (fieldWidget instanceof KSPicker) { |
62 | 0 | KSPicker picker = (KSPicker) fieldWidget; |
63 | 0 | if (picker.getInputWidget() instanceof HasText) { |
64 | 0 | HasText item = (HasText) picker.getInputWidget(); |
65 | 0 | fieldValue = item.getText(); |
66 | 0 | } else if (picker.getInputWidget() instanceof KSLabelList) { |
67 | 0 | KSLabelList widget = (KSLabelList) picker.getInputWidget(); |
68 | 0 | List<String> selected = widget.getSelectedItems(); |
69 | 0 | for (int j = 0; j < selected.size(); j++) { |
70 | 0 | if (fieldValue == null) { |
71 | 0 | fieldValue = new String(selected.get(j)); |
72 | |
} else { |
73 | 0 | fieldValue = fieldValue + ", " + selected.get(j); |
74 | |
} |
75 | |
} |
76 | |
} |
77 | 0 | } else if (fieldWidget instanceof ListBox) { |
78 | 0 | ListBox listBox = (ListBox) fieldWidget; |
79 | 0 | fieldValue = listBox.getItemText(listBox.getSelectedIndex()); |
80 | 0 | } else if (fieldWidget instanceof SectionTitle) { |
81 | 0 | SectionTitle sectionTitle = (SectionTitle) fieldWidget; |
82 | 0 | fieldValue = sectionTitle.getElement().getInnerText(); |
83 | 0 | } else if (fieldWidget instanceof ComplexPanel) { |
84 | 0 | subExportElements = ExportUtils.getDetailsForWidget(fieldWidget, subExportElements, viewName, sectionName); |
85 | |
} else |
86 | |
{ |
87 | |
|
88 | |
|
89 | |
} |
90 | 0 | if (setFirstFieldValue) { |
91 | 0 | exportItem.setFieldValue(fieldValue); |
92 | |
} else { |
93 | 0 | exportItem.setFieldValue2(fieldValue); |
94 | |
} |
95 | 0 | if (subExportElements != null && subExportElements.size() > 0) { |
96 | 0 | exportItem.setSubset(subExportElements); |
97 | |
} |
98 | |
|
99 | |
|
100 | 0 | return exportItem; |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public static Controller getController(Widget theWidget) { |
110 | |
|
111 | 0 | if (theWidget != null) { |
112 | |
|
113 | 0 | if (theWidget instanceof Controller) { |
114 | 0 | Controller controller = (Controller) theWidget; |
115 | 0 | return controller; |
116 | |
} else { |
117 | 0 | return getController(theWidget.getParent()); |
118 | |
} |
119 | |
} else { |
120 | 0 | return null; |
121 | |
} |
122 | |
} |
123 | |
|
124 | |
public static void handleExportClickEvent(Controller currentController, String format, String reportTitle) { |
125 | 0 | ArrayList<ExportElement> exportElements = new ArrayList<ExportElement>(); |
126 | |
|
127 | 0 | exportElements = currentController.getExportElementsFromView(); |
128 | |
|
129 | |
|
130 | 0 | if (exportElements != null && exportElements.size() > 0) { |
131 | 0 | debutExportElementsArray(exportElements); |
132 | 0 | currentController.doReportExport(exportElements, format, reportTitle); |
133 | |
} |
134 | 0 | } |
135 | |
|
136 | |
private static void debutExportElementsArray(ArrayList<ExportElement> exportElements) { |
137 | 0 | System.out.println(" "); |
138 | 0 | System.out.println(" "); |
139 | 0 | System.out.println(" "); |
140 | 0 | System.out.println(" "); |
141 | 0 | System.out.println(" "); |
142 | 0 | System.out.println(" "); |
143 | 0 | System.out.println(" "); |
144 | 0 | System.out.println(" "); |
145 | |
|
146 | 0 | for (int i = 0; i < exportElements.size(); i++) { |
147 | 0 | System.out.println(exportElements.get(i).printLine()); |
148 | 0 | debutExportElementsArraySubList(exportElements.get(i).getSubset()); |
149 | |
} |
150 | 0 | } |
151 | |
|
152 | |
private static void debutExportElementsArraySubList(List<ExportElement> exportElements) { |
153 | 0 | if (exportElements != null) { |
154 | 0 | System.out.println("Sub list : "); |
155 | 0 | for (int j = 0; j < exportElements.size(); j++) { |
156 | 0 | ExportElement element = exportElements.get(j); |
157 | 0 | System.out.println(element.printLine()); |
158 | 0 | debutExportElementsArraySubList(element.getSubset()); |
159 | |
|
160 | |
} |
161 | |
} |
162 | 0 | } |
163 | |
|
164 | |
public static ArrayList<ExportElement> getDetailsForWidget(SummaryTableSection tableSection, ArrayList<ExportElement> exportElements) { |
165 | 0 | SummaryTable sumTable = tableSection.getSummaryTable(); |
166 | 0 | SummaryTableModel model = sumTable.getModel(); |
167 | 0 | List<SummaryTableBlock> tableSectionList = model.getSectionList(); |
168 | 0 | for (int i = 0; i < tableSectionList.size(); i++) { |
169 | 0 | SummaryTableBlock item = tableSectionList.get(i); |
170 | 0 | String blockName = item.getTitle(); |
171 | 0 | List<SummaryTableRow> rowItems = item.getSectionRowList(); |
172 | 0 | for (int j = 0; j < rowItems.size(); j++) { |
173 | 0 | ExportElement element = new ExportElement(); |
174 | 0 | SummaryTableRow row = rowItems.get(j); |
175 | 0 | element.setSectionName(blockName); |
176 | 0 | element.setViewName(blockName); |
177 | 0 | element.setFieldLabel(row.getTitle()); |
178 | 0 | element.setMandatory(row.isRequired()); |
179 | 0 | Widget fdWidget = row.getCell1(); |
180 | 0 | if (row.isShown()) { |
181 | 0 | if (fdWidget != null) { |
182 | |
|
183 | 0 | if (fdWidget instanceof KSListPanel) { |
184 | 0 | ArrayList<ExportElement> subExportElements = new ArrayList<ExportElement>(); |
185 | 0 | subExportElements = ExportUtils.getDetailsForWidget(fdWidget, subExportElements, blockName, blockName); |
186 | 0 | element.setSubset(subExportElements); |
187 | 0 | } else { |
188 | |
|
189 | 0 | element = ExportUtils.getExportItemDetails(element,fdWidget,true, blockName, blockName); |
190 | |
} |
191 | |
} else { |
192 | 0 | if (row.getTitle() != null) { |
193 | 0 | element.setFieldLabel(row.getTitle()); |
194 | |
} |
195 | |
} |
196 | |
|
197 | 0 | Widget fdWidget2 = row.getCell2(); |
198 | 0 | if (fdWidget2 != null) { |
199 | 0 | element = ExportUtils.getExportItemDetails(element,fdWidget2,false, blockName, blockName); |
200 | |
|
201 | |
} else { |
202 | 0 | if (row.getTitle() != null) { |
203 | 0 | element.setFieldLabel(row.getTitle()); |
204 | |
} |
205 | |
} |
206 | 0 | if (element != null && element.getViewName() != null) { |
207 | 0 | exportElements.add(element); |
208 | |
} |
209 | |
} |
210 | |
} |
211 | |
} |
212 | 0 | return exportElements; |
213 | |
} |
214 | |
|
215 | |
public static ArrayList<ExportElement> getDetailsForWidget(Widget currentViewWidget, ArrayList<ExportElement> exportElements, String viewName, String sectionName) { |
216 | 0 | if (currentViewWidget instanceof Section) { |
217 | 0 | Section widgetHasFields = (Section) currentViewWidget; |
218 | 0 | List<FieldDescriptor> widgetFields = widgetHasFields.getFields(); |
219 | 0 | for (FieldDescriptor field : widgetFields) { |
220 | 0 | ExportElement exportItem = new ExportElement(); |
221 | 0 | exportItem.setSectionName(sectionName + viewName); |
222 | 0 | exportItem.setViewName(sectionName + viewName); |
223 | 0 | exportItem.setFieldLabel(field.getFieldLabel()); |
224 | 0 | Widget fieldWidget = field.getFieldElement().getFieldWidget(); |
225 | |
|
226 | 0 | exportElements.add(getExportItemDetails(exportItem, fieldWidget, true, viewName, sectionName)); |
227 | 0 | } |
228 | 0 | } else if (currentViewWidget instanceof KSListPanel) { |
229 | 0 | KSListPanel ksListPanelWidget = (KSListPanel) currentViewWidget; |
230 | 0 | WidgetCollection children = ksListPanelWidget.getChildren(); |
231 | 0 | for (int i = 0; i < children.size(); i++) { |
232 | 0 | Widget child = children.get(i); |
233 | |
|
234 | 0 | ExportElement exportItem = new ExportElement(); |
235 | 0 | exportItem.setSectionName(sectionName + viewName); |
236 | 0 | exportItem.setViewName(sectionName + viewName); |
237 | 0 | exportItem.setFieldLabel(""); |
238 | 0 | exportElements.add(getExportItemDetails(exportItem, child, true, viewName, sectionName)); |
239 | |
} |
240 | |
|
241 | 0 | } else if (currentViewWidget instanceof ComplexPanel){ |
242 | 0 | ComplexPanel complexPanel = (ComplexPanel) currentViewWidget; |
243 | 0 | for (int i = 0; i < complexPanel .getWidgetCount(); i++) { |
244 | 0 | Widget child = complexPanel .getWidget(i); |
245 | 0 | ExportElement exportItem = new ExportElement(); |
246 | 0 | exportItem.setSectionName(sectionName + viewName + " Complexpanel sublist"); |
247 | 0 | exportItem.setViewName(sectionName + viewName + " Complexpanel sublist"); |
248 | 0 | ExportElement exportItemDetails = getExportItemDetails(exportItem, child, true, viewName, sectionName); |
249 | 0 | if (exportItemDetails.getFieldValue() != null || (exportItemDetails.getSubset() != null && exportItemDetails.getSubset().size() > 0)) { |
250 | 0 | exportElements.add(exportItemDetails); |
251 | |
} |
252 | |
} |
253 | |
|
254 | |
|
255 | |
|
256 | 0 | } |
257 | |
else { |
258 | |
|
259 | 0 | System.out.println("ExportUtils does not cater for this type..." + currentViewWidget.getClass().getName()); |
260 | |
|
261 | |
} |
262 | 0 | return exportElements; |
263 | |
} |
264 | |
|
265 | |
private static String getViewName(Widget currentViewWidget) { |
266 | 0 | if (currentViewWidget instanceof View) { |
267 | 0 | View currentView = (View) currentViewWidget; |
268 | 0 | return currentView.getName(); |
269 | |
} |
270 | 0 | return null; |
271 | |
} |
272 | |
|
273 | |
public static ArrayList<ExportElement> getExportElementsFromView(Widget currentViewWidget, ArrayList<ExportElement> exportElements, String viewName, String sectionName) { |
274 | 0 | if (exportElements == null) { |
275 | 0 | exportElements = new ArrayList<ExportElement>(); |
276 | |
} |
277 | 0 | if (currentViewWidget instanceof VerticalSectionView) { |
278 | 0 | Section widgetHasFields = (Section) currentViewWidget; |
279 | 0 | List<FieldDescriptor> widgetFields = widgetHasFields.getFields(); |
280 | 0 | for (FieldDescriptor field : widgetFields) { |
281 | 0 | ExportElement exportItem = new ExportElement(); |
282 | 0 | exportItem.setSectionName(sectionName + viewName); |
283 | 0 | exportItem.setViewName(sectionName + viewName); |
284 | 0 | exportItem.setFieldLabel(field.getFieldLabel()); |
285 | 0 | Widget fieldWidget = field.getFieldElement().getFieldWidget(); |
286 | |
|
287 | 0 | exportElements.add(getExportItemDetails(exportItem, fieldWidget,true,viewName, sectionName)); |
288 | 0 | } |
289 | 0 | if ((currentViewWidget instanceof BaseSection) && (widgetHasFields.getFields().size() == 0)) { |
290 | 0 | BaseSection bSection = (BaseSection) currentViewWidget; |
291 | 0 | ExportElement exportItem = new ExportElement(); |
292 | 0 | exportItem.setSectionName(sectionName + viewName); |
293 | 0 | exportItem.setViewName(sectionName + viewName); |
294 | 0 | exportItem.setFieldLabel("???00"); |
295 | 0 | exportItem = getExportItemDetails(exportItem, bSection.getLayout(), true, viewName, sectionName); |
296 | 0 | exportElements.add(exportItem); |
297 | |
|
298 | |
} |
299 | |
|
300 | |
|
301 | |
} |
302 | 0 | return exportElements; |
303 | |
} |
304 | |
|
305 | |
} |