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