View Javadoc

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;  // Widget to be printed. 
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       * returns the widget that will be printed
91       * 
92       * @return
93       */
94      public Widget getPrintContent(){
95      	return this.printContent;
96      }
97      
98      
99      /**
100      * Takes a widget to be printed. This is useful when you want to 
101      * print only a certain section of a page
102      * 
103      * @param pContent
104      */
105     public void setPrintContent(Widget pContent){
106     	this.printContent = pContent;
107     }
108 
109     protected void setupPrint() {
110     	
111     	// Default to the old way of printing the entire page
112     	if(this.printContent == null){
113             //Code Changed for JIRA-9075 - SONAR Critical issues - Use get(0) with caution - 5
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                 	//for firefox the roll over message was not being hidden when
177                 	//export was clicked
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      * This method set the visibility of the export button to the value of the parameter
226      * 
227      * @param show
228      */
229     public void showExport(boolean show) {
230     	exportImage.setVisible(show);
231 		
232 	}
233 
234     public Image getExportImage() {
235         return exportImage;
236     }
237 }