/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.essar.automation.dhaval.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

/**
 * Main entry point.
 *
 * @author dhaval
 */
public class HelloGWTEntryPoint implements EntryPoint {
    /** 
     * Creates a new instance of HelloGWTEntryPoint
     */
    public HelloGWTEntryPoint() {
    }

    /** 
     * The entry point method, called automatically by loading a module
     * that declares an implementing class as an entry-point
     */
    public void onModuleLoad() {
        final Label quoteLabel = new Label();

        final RandomQuoteServiceAsync quoteService = GWT.create(RandomQuoteService.class);
        ServiceDefTarget endPoint = (ServiceDefTarget) quoteService;
        endPoint.setServiceEntryPoint("/quoteService");

        Timer timer = new Timer() {

            @Override
            public void run() {
                AsyncCallback callBack = new AsyncCallback() {

                    public void onFailure(Throwable caught) {
                        quoteLabel.setText("Error Occurred");
                    }

                    public void onSuccess(Object result) {
                        quoteLabel.setText((String) result);
                    }
                };

                quoteService.getQuote(callBack);
            }
        };
        timer.scheduleRepeating(1000);
         
        RootPanel.get().add(quoteLabel);
    }
}
