1 package org.kuali.student.common.ui.client.widgets.headers;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.kuali.student.common.ui.client.configurable.mvc.LayoutController;
7 import org.kuali.student.common.ui.client.mvc.Callback;
8 import org.kuali.student.common.ui.client.mvc.Controller;
9 import org.kuali.student.common.ui.client.util.ExportUtils;
10 import org.kuali.student.common.ui.client.util.PrintUtils;
11 import org.kuali.student.common.ui.client.widgets.ApplicationPanel;
12 import org.kuali.student.common.ui.client.widgets.dialog.ReportExportDialog;
13 import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel;
14
15 import com.google.gwt.core.client.GWT;
16 import com.google.gwt.event.dom.client.ClickEvent;
17 import com.google.gwt.event.dom.client.ClickHandler;
18 import com.google.gwt.event.dom.client.MouseOutEvent;
19 import com.google.gwt.event.dom.client.MouseOutHandler;
20 import com.google.gwt.event.dom.client.MouseOverEvent;
21 import com.google.gwt.event.dom.client.MouseOverHandler;
22 import com.google.gwt.uibinder.client.UiBinder;
23 import com.google.gwt.uibinder.client.UiField;
24 import com.google.gwt.user.client.ui.Composite;
25 import com.google.gwt.user.client.ui.HTML;
26 import com.google.gwt.user.client.ui.HTMLPanel;
27 import com.google.gwt.user.client.ui.Image;
28 import com.google.gwt.user.client.ui.PopupPanel;
29 import com.google.gwt.user.client.ui.Widget;
30
31 @Deprecated
32 public class KSDocumentHeader extends Composite {
33
34 protected static KSDocumentHeaderUiBinder uiBinder = GWT.create(KSDocumentHeaderUiBinder.class);
35
36 protected ReportExportDialog exportDialog = null;
37
38 protected PopupPanel hoverPopup = new PopupPanel();
39
40 protected PopupPanel hoverPopup1 = new PopupPanel();
41
42 interface KSDocumentHeaderUiBinder extends UiBinder<Widget, KSDocumentHeader> {}
43
44 @UiField
45 protected HTML headerHTML;
46
47 @UiField
48 protected HTML infoLabel;
49
50 @UiField
51 protected SpanPanel widgetPanel;
52
53 @UiField
54 protected Image printImage;
55
56 @UiField
57 protected Image exportImage;
58
59 protected Widget printContent = null;
60
61 protected boolean hasSeparator = true;
62
63 List<String> exportTypes = new ArrayList<String>();
64
65 public KSDocumentHeader() {
66 initWidget(uiBinder.createAndBindUi(this));
67 setupPrint();
68 setupExportPrint();
69 }
70
71 public KSDocumentHeader(boolean hasContentWidgetSeparator) {
72 this.hasSeparator = hasContentWidgetSeparator;
73 initWidget(uiBinder.createAndBindUi(this));
74 setupPrint();
75 setupExportPrint();
76 }
77
78 public KSDocumentHeader(List<String> fileTypes) {
79 initWidget(uiBinder.createAndBindUi(this));
80 setExportTypes(fileTypes);
81 setupPrint();
82 setupExportPrint();
83 }
84
85 public void setExportTypes(List<String> fileTypes) {
86 exportTypes=fileTypes;
87 }
88
89
90
91
92
93
94 public Widget getPrintContent(){
95 return this.printContent;
96 }
97
98
99
100
101
102
103
104
105 public void setPrintContent(Widget pContent){
106 this.printContent = pContent;
107 }
108
109 protected void setupPrint() {
110
111
112 if(this.printContent == null){
113 this.setPrintContent(ApplicationPanel.get().getWidget(0));
114 }
115 hoverPopup.add(new HTMLPanel("Print Page"));
116 hoverPopup.setStyleName("ks-help-popup");
117
118 printImage.addMouseOverHandler(new MouseOverHandler(){
119 @Override
120 public void onMouseOver(MouseOverEvent event) {
121 hoverPopup.setPopupPosition(printImage.getAbsoluteLeft()-10 ,
122 printImage.getAbsoluteTop()-exportImage.getOffsetWidth()-15);
123 hoverPopup.show();
124 }
125 });
126 printImage.addMouseOutHandler(new MouseOutHandler(){
127
128 @Override
129 public void onMouseOut(MouseOutEvent event) {
130 hoverPopup.hide();
131 }
132 });
133 printImage.setVisible(false);
134 printImage.addClickHandler(new ClickHandler() {
135
136 @Override
137 public void onClick(ClickEvent event) {
138 PrintUtils.print(getPrintContent());
139 }
140 });
141 }
142
143 protected void setupExportPrint() {
144 if(exportTypes==null||exportTypes.isEmpty()){
145 exportDialog = new ReportExportDialog();
146 }
147 else{
148 exportDialog = new ReportExportDialog(exportTypes);
149 }
150 exportImage.setVisible(false);
151 hoverPopup1.add(new HTMLPanel("Export Summary to File"));
152 hoverPopup1.setStyleName("ks-help-popup");
153 exportImage.addMouseOverHandler(new MouseOverHandler(){
154 @Override
155 public void onMouseOver(MouseOverEvent event) {
156 hoverPopup1.setPopupPosition(exportImage.getAbsoluteLeft()-55,
157 exportImage.getAbsoluteTop()-exportImage.getOffsetWidth()-15);
158 hoverPopup1.show();
159 }
160 });
161 exportImage.addMouseOutHandler(new MouseOutHandler(){
162
163 @Override
164 public void onMouseOut(MouseOutEvent event) {
165 hoverPopup1.hide();
166 }
167 });
168
169 exportImage.addClickHandler(new ClickHandler() {
170
171 @Override
172 public void onClick(ClickEvent event) {
173 if (exportDialog != null) {
174
175
176 hoverPopup1.hide();
177 exportDialog.show();
178 }
179
180 }
181 });
182
183 exportDialog.addSelectCompleteCallback(new Callback<String>() {
184 @Override
185 public void exec(String format) {
186 Controller currController = ExportUtils.getController(KSDocumentHeader.this);
187 String title = null;
188 if (currController instanceof LayoutController) {
189 title = ((LayoutController) currController).getName();
190 }
191 ExportUtils.handleExportClickEvent(currController, format, title);
192 }
193 });
194 }
195
196 public void setTitle(String header) {
197 headerHTML.setHTML("<h2>" + header + "</h2>");
198 }
199
200 public void addWidget(Widget w) {
201 if (w != null) {
202 if (hasSeparator) {
203 if (widgetPanel.getElement().hasChildNodes()) {
204 HTML separatorWrapper = new HTML("<span style='float: left; margin-left: .7em; margin-right: .7em'>|</span>");
205 separatorWrapper.addStyleName("ks-documentHeader-widgetPanel");
206 widgetPanel.add(separatorWrapper);
207 }
208 }
209 w.addStyleName("ks-documentHeader-widgetPanel");
210 widgetPanel.add(w);
211 }
212 }
213
214 public HTML getInfoLabel() {
215 return infoLabel;
216 }
217
218 public void showPrint(boolean show) {
219 printImage.setVisible(true);
220 }
221
222
223
224
225
226
227 public void showExport(boolean show) {
228 exportImage.setVisible(show);
229
230 }
231
232 public Image getExportImage() {
233 return exportImage;
234 }
235 }