| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PrintUtils |
|
| 2.0;2 |
| 1 | package org.kuali.student.common.ui.client.util; | |
| 2 | ||
| 3 | import com.google.gwt.dom.client.Document; | |
| 4 | import com.google.gwt.dom.client.NodeList; | |
| 5 | import com.google.gwt.user.client.Window; | |
| 6 | import com.google.gwt.user.client.ui.UIObject; | |
| 7 | import com.google.gwt.user.client.ui.Widget; | |
| 8 | ||
| 9 | 0 | public class PrintUtils { |
| 10 | 0 | private static int num = 0; |
| 11 | /** | |
| 12 | * Shows the uiObject content in a printable form in a new window | |
| 13 | * @param uiObject | |
| 14 | */ | |
| 15 | public static void print(UIObject uiObject){ | |
| 16 | 0 | String headTag = ""; |
| 17 | 0 | String styleTags = ""; |
| 18 | 0 | NodeList<com.google.gwt.dom.client.Element> head = Document.get().getElementsByTagName("head"); |
| 19 | 0 | if(head.getItem(0) != null){ |
| 20 | 0 | com.google.gwt.dom.client.Element e = head.getItem(0); |
| 21 | 0 | NodeList<com.google.gwt.dom.client.Element> styles = e.getElementsByTagName("style"); |
| 22 | 0 | for(int i = 0; i < styles.getLength(); i++){ |
| 23 | 0 | styleTags = styleTags + styles.getItem(i).getString(); |
| 24 | ||
| 25 | } | |
| 26 | } | |
| 27 | 0 | headTag = "<HEAD><TITLE>Print - " + Window.getTitle() + "</TITLE>" + styleTags + "</HEAD>"; |
| 28 | 0 | openPrintWindow(uiObject.getElement().getString(), headTag, num); |
| 29 | 0 | num++; |
| 30 | 0 | } |
| 31 | ||
| 32 | private static native void openPrintWindow(String html, String headTag, int num)/*-{ | |
| 33 | var win = $wnd.open("", num, "width=900,height=600,scrollbars=1"); | |
| 34 | var doc = win.document; | |
| 35 | doc.open("text/html", "replace"); | |
| 36 | doc.write("<HTML style='overflow: visible;'>"); | |
| 37 | doc.write(headTag); | |
| 38 | doc.write("<BODY style='overflow: visible;'>"); | |
| 39 | doc.write("<a class='ks-button-primary' style='cursor: pointer;' onClick='print();'>Print</a>"); | |
| 40 | doc.write("<DIV class='printPage'>"); | |
| 41 | doc.writeln(html); | |
| 42 | doc.writeln("</DIV></BODY></HTML>"); | |
| 43 | doc.close(); | |
| 44 | | |
| 45 | }-*/; | |
| 46 | ||
| 47 | // public static void printJasper(UIObject uiObject) { | |
| 48 | // System.out.println("Nina se jasperprint event..."); | |
| 49 | // String headTag = ""; | |
| 50 | // String styleTags = ""; | |
| 51 | // NodeList<com.google.gwt.dom.client.Element> head = Document.get().getElementsByTagName("head"); | |
| 52 | // if(head.getItem(0) != null){ | |
| 53 | // com.google.gwt.dom.client.Element e = head.getItem(0); | |
| 54 | // NodeList<com.google.gwt.dom.client.Element> styles = e.getElementsByTagName("style"); | |
| 55 | // for(int i = 0; i < styles.getLength(); i++){ | |
| 56 | // styleTags = styleTags + styles.getItem(i).getString(); | |
| 57 | // | |
| 58 | // } | |
| 59 | // } | |
| 60 | // headTag = "<HEAD><TITLE>Print - " + Window.getTitle() + "</TITLE>" + styleTags + "</HEAD>"; | |
| 61 | // String uiObjElement = uiObject.getElement().getString(); | |
| 62 | //// openPrintWindow(uiObjElement, headTag, num); | |
| 63 | // num++; | |
| 64 | // } | |
| 65 | } |