| 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 Widget printContent = null; |
| 46 | |
|
| 47 | 0 | private boolean hasSeparator = true; |
| 48 | |
|
| 49 | 0 | public KSDocumentHeader() { |
| 50 | 0 | initWidget(uiBinder.createAndBindUi(this)); |
| 51 | 0 | setupPrint(); |
| 52 | 0 | setupExportPrint(); |
| 53 | 0 | } |
| 54 | |
|
| 55 | 0 | public KSDocumentHeader(boolean hasContentWidgetSeparator) { |
| 56 | 0 | this.hasSeparator = hasContentWidgetSeparator; |
| 57 | 0 | initWidget(uiBinder.createAndBindUi(this)); |
| 58 | 0 | setupPrint(); |
| 59 | 0 | setupExportPrint(); |
| 60 | 0 | } |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
public Widget getPrintContent(){ |
| 68 | 0 | return this.printContent; |
| 69 | |
} |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
public void setPrintContent(Widget pContent){ |
| 79 | 0 | this.printContent = pContent; |
| 80 | 0 | } |
| 81 | |
|
| 82 | |
private void setupPrint() { |
| 83 | |
|
| 84 | |
|
| 85 | 0 | if(this.printContent == null){ |
| 86 | 0 | this.setPrintContent(ApplicationPanel.get().getWidget(0)); |
| 87 | |
} |
| 88 | |
|
| 89 | 0 | printImage.setVisible(false); |
| 90 | 0 | printImage.addClickHandler(new ClickHandler() { |
| 91 | |
|
| 92 | |
@Override |
| 93 | |
public void onClick(ClickEvent event) { |
| 94 | 0 | PrintUtils.print(getPrintContent()); |
| 95 | 0 | } |
| 96 | |
}); |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
private void setupExportPrint() { |
| 100 | 0 | exportDialog = new ReportExportDialog(); |
| 101 | 0 | exportImage.setVisible(false); |
| 102 | 0 | exportImage.addClickHandler(new ClickHandler() { |
| 103 | |
|
| 104 | |
@Override |
| 105 | |
public void onClick(ClickEvent event) { |
| 106 | 0 | if (exportDialog != null) { |
| 107 | 0 | exportDialog.show(); |
| 108 | |
} |
| 109 | |
|
| 110 | 0 | } |
| 111 | |
}); |
| 112 | |
|
| 113 | 0 | exportDialog.addSelectCompleteCallback(new Callback<String>() { |
| 114 | |
@Override |
| 115 | |
public void exec(String format) { |
| 116 | 0 | Controller currController = ExportUtils.getController(KSDocumentHeader.this); |
| 117 | 0 | String title = null; |
| 118 | 0 | if (currController instanceof LayoutController) { |
| 119 | 0 | title = ((LayoutController) currController).getName(); |
| 120 | |
} |
| 121 | 0 | ExportUtils.handleExportClickEvent(currController, format, title); |
| 122 | 0 | } |
| 123 | |
}); |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
public void setTitle(String header) { |
| 127 | 0 | headerHTML.setHTML("<h2>" + header + "</h2>"); |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
public void addWidget(Widget w) { |
| 131 | 0 | if (w != null) { |
| 132 | 0 | if (hasSeparator) { |
| 133 | 0 | if (widgetPanel.getElement().hasChildNodes()) { |
| 134 | 0 | widgetPanel.add(new HTML("<span style='float: left; margin-left: .7em; margin-right: .7em'>|</span>")); |
| 135 | |
} |
| 136 | |
} |
| 137 | 0 | widgetPanel.add(w); |
| 138 | |
} |
| 139 | 0 | w.getElement().setAttribute("style", "float: left"); |
| 140 | 0 | } |
| 141 | |
|
| 142 | |
public HTML getInfoLabel() { |
| 143 | 0 | return infoLabel; |
| 144 | |
} |
| 145 | |
|
| 146 | |
public void showPrint(boolean show) { |
| 147 | 0 | printImage.setVisible(true); |
| 148 | 0 | } |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public void showExport(boolean show) { |
| 156 | 0 | exportImage.setVisible(show); |
| 157 | 0 | } |
| 158 | |
|
| 159 | |
public Image getExportImage() { |
| 160 | 0 | return exportImage; |
| 161 | |
} |
| 162 | |
} |