1 | |
package org.kuali.student.common.ui.client.widgets.headers; |
2 | |
|
3 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
4 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
5 | |
import org.kuali.student.common.ui.client.util.ExportUtils; |
6 | |
import org.kuali.student.common.ui.client.util.PrintUtils; |
7 | |
import org.kuali.student.common.ui.client.widgets.ApplicationPanel; |
8 | |
import org.kuali.student.common.ui.client.widgets.dialog.ReportExportDialog; |
9 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel; |
10 | |
|
11 | |
import com.google.gwt.core.client.GWT; |
12 | |
import com.google.gwt.event.dom.client.ClickEvent; |
13 | |
import com.google.gwt.event.dom.client.ClickHandler; |
14 | |
import com.google.gwt.uibinder.client.UiBinder; |
15 | |
import com.google.gwt.uibinder.client.UiField; |
16 | |
import com.google.gwt.user.client.ui.Composite; |
17 | |
import com.google.gwt.user.client.ui.HTML; |
18 | |
import com.google.gwt.user.client.ui.Image; |
19 | |
import com.google.gwt.user.client.ui.Widget; |
20 | |
|
21 | 0 | public class KSDocumentHeader extends Composite { |
22 | |
|
23 | 0 | private static KSDocumentHeaderUiBinder uiBinder = GWT.create(KSDocumentHeaderUiBinder.class); |
24 | |
|
25 | 0 | private ReportExportDialog exportDialog = null; |
26 | |
|
27 | |
interface KSDocumentHeaderUiBinder extends UiBinder<Widget, KSDocumentHeader> {} |
28 | |
|
29 | |
@UiField |
30 | |
HTML headerHTML; |
31 | |
|
32 | |
@UiField |
33 | |
HTML infoLabel; |
34 | |
|
35 | |
@UiField |
36 | |
SpanPanel widgetPanel; |
37 | |
|
38 | |
@UiField |
39 | |
Image printImage; |
40 | |
|
41 | |
@UiField |
42 | |
Image jasperImage; |
43 | |
|
44 | 0 | private boolean hasSeparator = true; |
45 | |
|
46 | 0 | public KSDocumentHeader() { |
47 | 0 | initWidget(uiBinder.createAndBindUi(this)); |
48 | 0 | setupPrint(); |
49 | 0 | setupJasperPrint(); |
50 | 0 | } |
51 | |
|
52 | 0 | public KSDocumentHeader(boolean hasContentWidgetSeparator) { |
53 | 0 | this.hasSeparator = hasContentWidgetSeparator; |
54 | 0 | initWidget(uiBinder.createAndBindUi(this)); |
55 | 0 | setupPrint(); |
56 | 0 | setupJasperPrint(); |
57 | 0 | } |
58 | |
|
59 | |
private void setupPrint() { |
60 | 0 | printImage.setVisible(false); |
61 | 0 | printImage.addClickHandler(new ClickHandler() { |
62 | |
|
63 | |
@Override |
64 | |
public void onClick(ClickEvent event) { |
65 | 0 | PrintUtils.print(ApplicationPanel.get().getWidget(0)); |
66 | 0 | } |
67 | |
}); |
68 | 0 | } |
69 | |
|
70 | |
private void setupJasperPrint() { |
71 | 0 | exportDialog = new ReportExportDialog(); |
72 | 0 | jasperImage.setVisible(false); |
73 | 0 | jasperImage.addClickHandler(new ClickHandler() { |
74 | |
|
75 | |
@Override |
76 | |
public void onClick(ClickEvent event) { |
77 | 0 | if (exportDialog != null) { |
78 | 0 | exportDialog.show(); |
79 | |
} |
80 | |
|
81 | 0 | } |
82 | |
}); |
83 | |
|
84 | 0 | exportDialog.addSelectCompleteCallback(new Callback<String>() { |
85 | |
@Override |
86 | |
public void exec(String format) { |
87 | 0 | Controller currController = ExportUtils.getController(KSDocumentHeader.this); |
88 | 0 | ExportUtils.handleExportClickEvent(currController, format, KSDocumentHeader.this.headerHTML.getTitle()); |
89 | 0 | } |
90 | |
}); |
91 | 0 | } |
92 | |
|
93 | |
public void setTitle(String header) { |
94 | 0 | headerHTML.setHTML("<h2>" + header + "</h2>"); |
95 | 0 | } |
96 | |
|
97 | |
public void addWidget(Widget w) { |
98 | 0 | if (w != null) { |
99 | 0 | if (hasSeparator) { |
100 | 0 | if (widgetPanel.getElement().hasChildNodes()) { |
101 | 0 | widgetPanel.add(new HTML("<span style='float: left; margin-left: .7em; margin-right: .7em'>|</span>")); |
102 | |
} |
103 | |
} |
104 | 0 | widgetPanel.add(w); |
105 | |
} |
106 | 0 | w.getElement().setAttribute("style", "float: left"); |
107 | 0 | } |
108 | |
|
109 | |
public HTML getInfoLabel() { |
110 | 0 | return infoLabel; |
111 | |
} |
112 | |
|
113 | |
public void showPrint(boolean show) { |
114 | 0 | printImage.setVisible(true); |
115 | 0 | } |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public void showJasper(boolean show) { |
123 | 0 | jasperImage.setVisible(show); |
124 | 0 | } |
125 | |
|
126 | |
public Image getJasperImage() { |
127 | 0 | return jasperImage; |
128 | |
} |
129 | |
} |