package org.dartlang.gwtapplication.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class GwtApplication implements EntryPoint {

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {
    VerticalPanel mainPanel = new VerticalPanel();
    RootPanel.get("gwtDiv").add(mainPanel);
    
    Label gwtLoadedLabel = new Label();
    gwtLoadedLabel.setText("GWT application loaded");
    mainPanel.add(gwtLoadedLabel);
  }
}

@@ -84,16 +84,165 @@
 yPoint;%0A
+import com.google.gwt.event.dom.client.ClickEvent;%0Aimport com.google.gwt.event.dom.client.ClickHandler;%0Aimport com.google.gwt.user.client.ui.Button;%0A
 import c
@@ -498,16 +498,74 @@
 oint %7B%0A%0A
+  private VerticalPanel mainPanel = new VerticalPanel();%0A%0A
   /**%0A  
@@ -644,123 +644,1048 @@
     
-VerticalPanel mainPanel = new VerticalPanel();%0A    RootPanel.get(%22gwtDiv%22).add(mainPanel);%0A    %0A    Label gwtLoaded
+RootPanel.get(%22gwtDiv%22).add(mainPanel);%0A    %0A    // Say that the application has been loaded.%0A    Label gwtLoadedLabel = new Label();%0A    gwtLoadedLabel.setText(%22GWT application loaded%22);%0A    mainPanel.add(gwtLoadedLabel);%0A    %0A    // Add a button to call postMessage.%0A    Button postMessageButton = new Button(%22Post message from GWT%22);%0A    mainPanel.add(postMessageButton);%0A    postMessageButton.addClickHandler(new ClickHandler() %7B%0A      public void onClick(ClickEvent event) %7B%0A        postMessage(%22Hello from GWT!%22);%0A      %7D%0A    %7D);%0A    %0A    listenForPostMessage();%0A  %7D%0A  %0A  protected native void postMessage(String msg) /*-%7B%0A    $wnd.postMessage(msg, %22*%22);%0A  %7D-*/;%0A%0A  private final native void listenForPostMessage() /*-%7B%0A    var that = this;%0A    $wnd.addEventListener(%22message%22, function(msg) %7B%0A      that.@org.dartlang.gwtapplication.client.GwtApplication::onPostMessage(Ljava/lang/String;Ljava/lang/String;)(%0A          msg.data, msg.origin);%0A    %7D);%0A  %7D-*/;%0A  %0A  private void onPostMessage(String data, String origin) %7B%0A    Label msg
 Labe
@@ -1701,33 +1701,27 @@
 abel();%0A    
-gwtLoaded
+msg
 Label.setTex
@@ -1727,35 +1727,85 @@
 xt(%22GWT 
-application loaded%22
+received a postMessage: Data: %22 +%0A        data + %22 Origin: %22 + origin
 );%0A    m
@@ -1813,33 +1813,27 @@
 inPanel.add(
-gwtLoaded
+msg
 Label);%0A  %7D%0A

Handle postMessage in GWT