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
114 int firstwidget = 0;
115 this.setPrintContent(ApplicationPanel.get().getWidget(firstwidget));
116 }
117 hoverPopup.add(new HTMLPanel("Print Page"));
118 hoverPopup.setStyleName("ks-help-popup");
119
120 printImage.addMouseOverHandler(new MouseOverHandler(){
121 @Override
122 public void onMouseOver(MouseOverEvent event) {
123 hoverPopup.setPopupPosition(printImage.getAbsoluteLeft()-10 ,
124 printImage.getAbsoluteTop()-exportImage.getOffsetWidth()-15);
125 hoverPopup.show();
126 }
127 });
128 printImage.addMouseOutHandler(new MouseOutHandler(){
129
130 @Override
131 public void onMouseOut(MouseOutEvent event) {
132 hoverPopup.hide();
133 }
134 });
135 printImage.setVisible(false);
136 printImage.addClickHandler(new ClickHandler() {
137
138 @Override
139 public void onClick(ClickEvent event) {
140 PrintUtils.print(getPrintContent());
141 }
142 });
143 }
144
145 protected void setupExportPrint() {
146 if(exportTypes==null||exportTypes.isEmpty()){
147 exportDialog = new ReportExportDialog();
148 }
149 else{
150 exportDialog = new ReportExportDialog(exportTypes);
151 }
152 exportImage.setVisible(false);
153 hoverPopup1.add(new HTMLPanel("Export Summary to File"));
154 hoverPopup1.setStyleName("ks-help-popup");
155 exportImage.addMouseOverHandler(new MouseOverHandler(){
156 @Override
157 public void onMouseOver(MouseOverEvent event) {
158 hoverPopup1.setPopupPosition(exportImage.getAbsoluteLeft()-55,
159 exportImage.getAbsoluteTop()-exportImage.getOffsetWidth()-15);
160 hoverPopup1.show();
161 }
162 });
163 exportImage.addMouseOutHandler(new MouseOutHandler(){
164
165 @Override
166 public void onMouseOut(MouseOutEvent event) {
167 hoverPopup1.hide();
168 }
169 });
170
171 exportImage.addClickHandler(new ClickHandler() {
172
173 @Override
174 public void onClick(ClickEvent event) {
175 if (exportDialog != null) {
176
177
178 hoverPopup1.hide();
179 exportDialog.show();
180 }
181
182 }
183 });
184
185 exportDialog.addSelectCompleteCallback(new Callback<String>() {
186 @Override
187 public void exec(String format) {
188 Controller currController = ExportUtils.getController(KSDocumentHeader.this);
189 String title = null;
190 if (currController instanceof LayoutController) {
191 title = ((LayoutController) currController).getName();
192 }
193 ExportUtils.handleExportClickEvent(currController, format, title);
194 }
195 });
196 }
197
198 public void setTitle(String header) {
199 headerHTML.setHTML("<h2>" + header + "</h2>");
200 }
201
202 public void addWidget(Widget w) {
203 if (w != null) {
204 if (hasSeparator) {
205 if (widgetPanel.getElement().hasChildNodes()) {
206 HTML separatorWrapper = new HTML("<span style='float: left; margin-left: .7em; margin-right: .7em'>|</span>");
207 separatorWrapper.addStyleName("ks-documentHeader-widgetPanel");
208 widgetPanel.add(separatorWrapper);
209 }
210 }
211 w.addStyleName("ks-documentHeader-widgetPanel");
212 widgetPanel.add(w);
213 }
214 }
215
216 public HTML getInfoLabel() {
217 return infoLabel;
218 }
219
220 public void showPrint(boolean show) {
221 printImage.setVisible(true);
222 }
223
224
225
226
227
228
229 public void showExport(boolean show) {
230 exportImage.setVisible(show);
231
232 }
233
234 public Image getExportImage() {
235 return exportImage;
236 }
237 }