1 package autotest.tko.embedded_spreadsheet; 2 3 import autotest.common.spreadsheet.Spreadsheet; 4 5 import com.google.gwt.dom.client.Element; 6 import com.google.gwt.user.client.Command; 7 import com.google.gwt.user.client.ui.Composite; 8 import com.google.gwt.user.client.ui.Label; 9 import com.google.gwt.user.client.ui.Panel; 10 import com.google.gwt.user.client.ui.SimplePanel; 11 import com.google.gwt.user.client.ui.Widget; 12 13 public class EmbeddedSpreadsheetDisplay extends Composite 14 implements EmbeddedSpreadsheetPresenter.Display { 15 private static final String NO_RESULTS = "There are no results for this query (yet?)"; 16 17 private Panel panel = new SimplePanel(); 18 private Spreadsheet spreadsheet = new Spreadsheet(); 19 private Label noResults = new Label(NO_RESULTS); 20 EmbeddedSpreadsheetDisplay()21 public EmbeddedSpreadsheetDisplay() { 22 initWidget(panel); 23 } 24 notifyParent(Widget w)25 private void notifyParent(Widget w) { 26 Element elem = w.getElement(); 27 notifyParent(elem.getClientWidth(), elem.getClientHeight()); 28 } 29 notifyParent(int width, int height)30 private native void notifyParent(int width, int height) /*-{ 31 $wnd.parent.postMessage(width + 'px ' + height + 'px', '*'); 32 }-*/; 33 34 @Override getOnSpreadsheetRendered()35 public Command getOnSpreadsheetRendered() { 36 return new Command() { 37 @Override 38 public void execute() { 39 notifyParent(spreadsheet); 40 } 41 }; 42 } 43 44 @Override 45 public Spreadsheet getSpreadsheet() { 46 return spreadsheet; 47 } 48 49 @Override 50 public void showNoResults() { 51 panel.add(noResults); 52 notifyParent(noResults); 53 } 54 55 @Override 56 public void showSpreadsheet() { 57 panel.add(spreadsheet); 58 } 59 } 60