| 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.list.KSLabelList; |
| 26 | |
import org.kuali.student.common.ui.client.widgets.list.KSSelectedList; |
| 27 | |
import org.kuali.student.common.ui.client.widgets.menus.KSListPanel; |
| 28 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
| 29 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTable; |
| 30 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableBlock; |
| 31 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableModel; |
| 32 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableRow; |
| 33 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection; |
| 34 | |
|
| 35 | |
import com.google.gwt.user.client.Element; |
| 36 | |
import com.google.gwt.user.client.ui.ComplexPanel; |
| 37 | |
import com.google.gwt.user.client.ui.FlowPanel; |
| 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 | 0 | if (!fieldWidget.getParent().getElement().getStyle().getDisplay().equals("none")){ |
| 69 | 0 | if (fieldWidget instanceof HasText) { |
| 70 | 0 | HasText itemHasTextValue = (HasText) fieldWidget; |
| 71 | 0 | setFieldValue(exportItem, setFirstFieldValue, itemHasTextValue.getText()); |
| 72 | 0 | Element element = fieldWidget.getElement(); |
| 73 | 0 | System.out.println("Inner Html:" + element.getInnerHTML()); |
| 74 | 0 | Element parentElement = fieldWidget.getParent().getElement(); |
| 75 | 0 | System.out.println("Parent Inner Html:" + parentElement.getInnerHTML()); |
| 76 | |
|
| 77 | 0 | if (fieldWidget.getElement().getStyle().getFontStyle().equalsIgnoreCase("italic")){ |
| 78 | 0 | exportItem.setPrintType(ExportElement.ITALIC); |
| 79 | |
} |
| 80 | 0 | } else if (fieldWidget instanceof KSSelectedList) { |
| 81 | 0 | KSSelectedList selectedList = (KSSelectedList) fieldWidget; |
| 82 | 0 | List<KSItemLabel> selectedItems = selectedList.getSelectedItems(); |
| 83 | 0 | String values = new String(); |
| 84 | 0 | for (int j = 0; j < selectedItems.size(); j++) { |
| 85 | 0 | values = selectedItems.get(j).getDisplayText(); |
| 86 | |
} |
| 87 | 0 | setFieldValue(exportItem, setFirstFieldValue, values); |
| 88 | |
|
| 89 | 0 | } else if (fieldWidget instanceof KSPicker) { |
| 90 | 0 | KSPicker picker = (KSPicker) fieldWidget; |
| 91 | 0 | if (picker.getInputWidget() instanceof HasText) { |
| 92 | 0 | HasText item = (HasText) picker.getInputWidget(); |
| 93 | 0 | setFieldValue(exportItem, setFirstFieldValue, item.getText()); |
| 94 | 0 | } else if (picker.getInputWidget() instanceof KSLabelList) { |
| 95 | 0 | String fieldValue = null; |
| 96 | 0 | KSLabelList widget = (KSLabelList) picker.getInputWidget(); |
| 97 | 0 | List<String> selected = widget.getSelectedItemsForExport(); |
| 98 | 0 | for (int j = 0; j < selected.size(); j++) { |
| 99 | 0 | if (fieldValue == null) { |
| 100 | 0 | fieldValue = new String(selected.get(j)); |
| 101 | |
} else { |
| 102 | 0 | fieldValue = fieldValue + ", " + selected.get(j); |
| 103 | |
} |
| 104 | |
} |
| 105 | 0 | setFieldValue(exportItem, setFirstFieldValue, fieldValue); |
| 106 | |
} |
| 107 | |
|
| 108 | 0 | } else if (fieldWidget instanceof ListBox) { |
| 109 | 0 | ListBox listBox = (ListBox) fieldWidget; |
| 110 | 0 | setFieldValue(exportItem, setFirstFieldValue, listBox.getItemText(listBox.getSelectedIndex())); |
| 111 | 0 | } else if (fieldWidget instanceof SectionTitle) { |
| 112 | |
try { |
| 113 | 0 | SectionTitle sectionTitle = (SectionTitle) fieldWidget; |
| 114 | 0 | setFieldValue(exportItem, setFirstFieldValue, sectionTitle.getExportFieldValue()); |
| 115 | 0 | if (!exportItem.getValue().contains("<b>")){ |
| 116 | 0 | exportItem.setPrintType(ExportElement.BOLD); |
| 117 | |
} |
| 118 | 0 | } catch (Exception e) { |
| 119 | |
|
| 120 | 0 | } |
| 121 | |
|
| 122 | 0 | } else if (fieldWidget instanceof ReportExportWidget) { |
| 123 | |
|
| 124 | 0 | if (fieldWidget.isVisible()){ |
| 125 | 0 | ReportExportWidget widget = (ReportExportWidget) fieldWidget; |
| 126 | 0 | if (widget.isExportElement() ) { |
| 127 | 0 | exportItem.setSubset(widget.getExportElementSubset(exportItem)); |
| 128 | 0 | setFieldValue(exportItem, setFirstFieldValue, widget.getExportFieldValue()); |
| 129 | |
} |
| 130 | 0 | } |
| 131 | 0 | } else if (fieldWidget instanceof ComplexPanel) { |
| 132 | 0 | if(fieldWidget.isVisible()) { |
| 133 | 0 | exportItem.setSubset(ExportUtils.getDetailsForWidget(fieldWidget, viewName, sectionName)); |
| 134 | |
} |
| 135 | |
|
| 136 | |
} else { |
| 137 | |
|
| 138 | |
} |
| 139 | |
|
| 140 | |
|
| 141 | |
} |
| 142 | 0 | return exportItem; |
| 143 | |
} |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
private static void setFieldValue(ExportElement exportItem, boolean setFirstFieldValue, String fieldValue) { |
| 155 | 0 | if (setFirstFieldValue) { |
| 156 | 0 | exportItem.setFieldValue(fieldValue); |
| 157 | |
} else { |
| 158 | 0 | exportItem.setFieldValue2(fieldValue); |
| 159 | |
} |
| 160 | 0 | } |
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
public static Controller getController(Widget theWidget) { |
| 171 | |
|
| 172 | |
|
| 173 | 0 | if (theWidget != null) { |
| 174 | |
|
| 175 | 0 | if (theWidget instanceof Controller) { |
| 176 | 0 | Controller controller = (Controller) theWidget; |
| 177 | 0 | return controller; |
| 178 | |
} else { |
| 179 | 0 | return getController(theWidget.getParent()); |
| 180 | |
} |
| 181 | |
} else { |
| 182 | 0 | return null; |
| 183 | |
} |
| 184 | |
} |
| 185 | |
|
| 186 | |
public static void handleExportClickEvent(Controller currentController, String format, String reportTitle) { |
| 187 | 0 | List<ExportElement> exportElements = new ArrayList<ExportElement>(); |
| 188 | 0 | exportElements = currentController.getExportElementsFromView(); |
| 189 | 0 | if (exportElements != null && exportElements.size() > 0) { |
| 190 | 0 | debugExportElementsArray(exportElements); |
| 191 | 0 | currentController.doReportExport(exportElements, format, reportTitle); |
| 192 | |
} |
| 193 | 0 | } |
| 194 | |
|
| 195 | |
public static void debugExportElementsArray(List<ExportElement> exportElements) { |
| 196 | 0 | System.out.println(" "); |
| 197 | 0 | System.out.println(" "); |
| 198 | 0 | System.out.println(" "); |
| 199 | 0 | System.out.println(" "); |
| 200 | 0 | System.out.println(" "); |
| 201 | 0 | System.out.println(" "); |
| 202 | 0 | System.out.println(" "); |
| 203 | 0 | System.out.println(" "); |
| 204 | |
|
| 205 | 0 | for (int i = 0; i < exportElements.size(); i++) { |
| 206 | 0 | System.out.println(exportElements.get(i).toString()); |
| 207 | 0 | debutExportElementsArraySubList(exportElements.get(i).getSubset()); |
| 208 | |
} |
| 209 | 0 | } |
| 210 | |
|
| 211 | |
private static void debutExportElementsArraySubList(List<ExportElement> exportElements) { |
| 212 | 0 | if (exportElements != null) { |
| 213 | 0 | System.out.println("Sub list : "); |
| 214 | 0 | for (int j = 0; j < exportElements.size(); j++) { |
| 215 | 0 | ExportElement element = exportElements.get(j); |
| 216 | 0 | System.out.println(element.toString()); |
| 217 | 0 | debutExportElementsArraySubList(element.getSubset()); |
| 218 | |
|
| 219 | |
} |
| 220 | |
} |
| 221 | 0 | } |
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
public static ArrayList<ExportElement> getDetailsForWidget(SummaryTableSection tableSection, ArrayList<ExportElement> exportElements) { |
| 232 | 0 | SummaryTable sumTable = tableSection.getSummaryTable(); |
| 233 | 0 | SummaryTableModel model = sumTable.getModel(); |
| 234 | 0 | List<SummaryTableBlock> tableSectionList = model.getSectionList(); |
| 235 | 0 | for (int i = 0; i < tableSectionList.size(); i++) { |
| 236 | 0 | SummaryTableBlock item = tableSectionList.get(i); |
| 237 | 0 | String blockName = item.getTitle(); |
| 238 | 0 | List<SummaryTableRow> rowItems = item.getSectionRowList(); |
| 239 | 0 | for (int j = 0; j < rowItems.size(); j++) { |
| 240 | 0 | ExportElement element = new ExportElement(); |
| 241 | 0 | SummaryTableRow row = rowItems.get(j); |
| 242 | 0 | element.setSectionName(blockName); |
| 243 | 0 | element.setViewName(blockName); |
| 244 | 0 | element.setFieldLabel(row.getTitle()); |
| 245 | 0 | element.setMandatory(row.isRequired()); |
| 246 | 0 | Widget fdWidget = row.getCell1(); |
| 247 | 0 | if (row.isShown()) { |
| 248 | 0 | if (fdWidget != null) { |
| 249 | |
|
| 250 | 0 | if (fdWidget instanceof KSListPanel) { |
| 251 | 0 | element.setSubset(ExportUtils.getDetailsForWidget(fdWidget, blockName, blockName)); |
| 252 | |
} else { |
| 253 | |
|
| 254 | 0 | element = ExportUtils.getExportItemDetails(element, fdWidget, true, blockName, blockName); |
| 255 | |
} |
| 256 | |
} else { |
| 257 | 0 | if (row.getTitle() != null) { |
| 258 | 0 | element.setFieldLabel(row.getTitle()); |
| 259 | |
} |
| 260 | |
} |
| 261 | |
|
| 262 | 0 | Widget fdWidget2 = row.getCell2(); |
| 263 | 0 | if (fdWidget2 != null) { |
| 264 | 0 | element = ExportUtils.getExportItemDetails(element, fdWidget2, false, blockName, blockName); |
| 265 | |
|
| 266 | |
} else { |
| 267 | 0 | if (row.getTitle() != null) { |
| 268 | 0 | element.setFieldLabel(row.getTitle()); |
| 269 | |
} |
| 270 | |
} |
| 271 | 0 | if (element != null && element.getViewName() != null) { |
| 272 | 0 | exportElements.add(element); |
| 273 | |
} |
| 274 | |
} |
| 275 | |
|
| 276 | |
} |
| 277 | |
} |
| 278 | 0 | return exportElements; |
| 279 | |
} |
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
public static List<ExportElement> getDetailsForWidget(Widget currentViewWidget, String viewName, String sectionName) { |
| 291 | 0 | List<ExportElement> childElements = new ArrayList<ExportElement>(); |
| 292 | 0 | if (!currentViewWidget.getParent().getElement().getStyle().getDisplay().equals("none")){ |
| 293 | 0 | if (currentViewWidget instanceof Section) { |
| 294 | 0 | Section widgetHasFields = (Section) currentViewWidget; |
| 295 | 0 | List<FieldDescriptor> widgetFields = widgetHasFields.getFields(); |
| 296 | 0 | for (FieldDescriptor field : widgetFields) { |
| 297 | 0 | ExportElement exportItem = createExportElement(viewName, sectionName, childElements, field.getFieldElement().getFieldWidget()); |
| 298 | 0 | exportItem.setFieldLabel(field.getFieldLabel()); |
| 299 | 0 | } |
| 300 | 0 | } else if (currentViewWidget instanceof KSListPanel) { |
| 301 | 0 | KSListPanel ksListPanelWidget = (KSListPanel) currentViewWidget; |
| 302 | 0 | WidgetCollection children = ksListPanelWidget.getChildren(); |
| 303 | 0 | for (int i = 0; i < children.size(); i++) { |
| 304 | 0 | createExportElement(viewName, sectionName, childElements, children.get(i)); |
| 305 | |
} |
| 306 | |
|
| 307 | 0 | } else if (currentViewWidget instanceof ULPanel) { |
| 308 | 0 | ComplexPanel complexPanel = (ComplexPanel) currentViewWidget; |
| 309 | 0 | if (complexPanel.isVisible()){ |
| 310 | 0 | for (int i = 0; i < complexPanel.getWidgetCount(); i++) { |
| 311 | 0 | Widget child = complexPanel.getWidget(i); |
| 312 | 0 | if (child instanceof FlowPanel){ |
| 313 | 0 | List<ExportElement> subset = ExportUtils.getDetailsForWidget(child, viewName, sectionName); |
| 314 | 0 | if (subset != null && subset.size() > 0){ |
| 315 | 0 | subset.get(0).setPrintType(ExportElement.LIST); |
| 316 | 0 | childElements.addAll(subset); |
| 317 | |
} |
| 318 | |
|
| 319 | 0 | } else if (!(child instanceof KSButton) |
| 320 | |
&& !(child instanceof WarnContainer)) { |
| 321 | 0 | ExportElement exportItem = createExportElement(viewName, sectionName, childElements, child); |
| 322 | 0 | exportItem.setPrintType(ExportElement.LIST); |
| 323 | |
} |
| 324 | |
} |
| 325 | |
} |
| 326 | |
|
| 327 | 0 | } else if (currentViewWidget instanceof ComplexPanel) { |
| 328 | 0 | ComplexPanel complexPanel = (ComplexPanel) currentViewWidget; |
| 329 | 0 | if (complexPanel.isVisible()){ |
| 330 | 0 | for (int i = 0; i < complexPanel.getWidgetCount(); i++) { |
| 331 | 0 | Widget child = complexPanel.getWidget(i); |
| 332 | 0 | if (child instanceof FlowPanel){ |
| 333 | 0 | List<ExportElement> subset = ExportUtils.getDetailsForWidget(child, viewName, sectionName); |
| 334 | 0 | if (subset != null && subset.size() > 0){ |
| 335 | 0 | childElements.addAll(subset); |
| 336 | |
} |
| 337 | |
|
| 338 | 0 | } else if (!(child instanceof KSButton) |
| 339 | |
&& !(child instanceof WarnContainer)) { |
| 340 | 0 | createExportElement(viewName, sectionName, childElements, child); |
| 341 | |
} |
| 342 | |
} |
| 343 | |
} |
| 344 | 0 | } else { |
| 345 | |
|
| 346 | 0 | System.out.println("ExportUtils does not cater for this type..." + currentViewWidget.getClass().getName()); |
| 347 | |
|
| 348 | |
} |
| 349 | |
} |
| 350 | 0 | return childElements; |
| 351 | |
} |
| 352 | |
|
| 353 | |
public static ArrayList<ExportElement> getExportElementsFromView(Widget currentViewWidget, ArrayList<ExportElement> exportElements, String viewName, String sectionName) { |
| 354 | 0 | if (exportElements == null) { |
| 355 | 0 | exportElements = new ArrayList<ExportElement>(); |
| 356 | |
} |
| 357 | 0 | if (currentViewWidget.getParent() == null || !currentViewWidget.getParent().getElement().getStyle().getDisplay().equals("none")) { |
| 358 | 0 | if (currentViewWidget instanceof VerticalSectionView) { |
| 359 | 0 | Section widgetHasFields = (Section) currentViewWidget; |
| 360 | 0 | List<FieldDescriptor> widgetFields = widgetHasFields.getFields(); |
| 361 | 0 | for (FieldDescriptor field : widgetFields) { |
| 362 | 0 | Widget child = field.getFieldElement().getFieldWidget(); |
| 363 | 0 | ExportElement exportItem = createExportElement(viewName, sectionName, exportElements, child); |
| 364 | 0 | exportItem.setFieldLabel(field.getFieldLabel()); |
| 365 | 0 | } |
| 366 | 0 | if ((currentViewWidget instanceof BaseSection) && (widgetHasFields.getFields().size() == 0)) { |
| 367 | 0 | BaseSection bSection = (BaseSection) currentViewWidget; |
| 368 | 0 | createExportElement(viewName, sectionName, exportElements, bSection.getLayout()); |
| 369 | |
} |
| 370 | |
} |
| 371 | |
} |
| 372 | 0 | return exportElements; |
| 373 | |
} |
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
private static ExportElement createExportElement(String viewName, String sectionName, List<ExportElement> childElements, Widget child) { |
| 386 | 0 | ExportElement exportItem = new ExportElement(); |
| 387 | 0 | exportItem.setSectionName(sectionName); |
| 388 | 0 | exportItem.setViewName(viewName); |
| 389 | |
|
| 390 | 0 | exportItem = getExportItemDetails(exportItem, child, true, viewName, sectionName); |
| 391 | 0 | ExportUtils.addElementToElementArray(childElements, exportItem); |
| 392 | 0 | return exportItem; |
| 393 | |
} |
| 394 | |
|
| 395 | |
|
| 396 | |
public static List<ExportElement> addElementToElementArray(List<ExportElement> elementArray, ExportElement element) { |
| 397 | 0 | if (element.getFieldLabel() != null || element.getFieldValue() != null || element.getFieldValue2() != null || (element.getSubset() != null && element.getSubset().size() > 0)) { |
| 398 | 0 | elementArray.add(element); |
| 399 | |
} |
| 400 | 0 | return elementArray; |
| 401 | |
} |
| 402 | |
|
| 403 | |
} |