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