// Path: src/main/java/gov/wa/wsdot/apps/analytics/client/ClientFactory.java
// public interface ClientFactory {
//     EventBus getEventBus();
//     PlaceController getPlaceController();
//     AnalyticsView getAnalyticsView();
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/client/activities/events/DateSubmitEvent.java
// public class DateSubmitEvent extends GenericEvent {
// 
// 
//     private final String dateRange;
//     private final String account;
//     private final Date startDate;
//     private final Date endDate;
// 
//     public DateSubmitEvent(String dateRange, Date startDate, Date endDate, String account) {
//         this.dateRange = dateRange;
//         this.account = account;
//         this.startDate = startDate;
//         this.endDate = endDate;
//     }
// 
//     public String getDateRange() {
//         return this.dateRange;
//     }
// 
//     public String getAccount() {
//         return this.account;
//     }
// 
//     public Date getStartDate(){ return this.startDate;}
// 
//     public Date getEndDate(){ return this.endDate;}
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/client/activities/events/SentimentDisplayEvent.java
// public class SentimentDisplayEvent extends GenericEvent {
// 
//     String sentiment;
// 
//     public SentimentDisplayEvent(String sentiment){
//         this.sentiment = sentiment;
//     }
// 
//     public String getSentiment(){
//         return sentiment;
//     }
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/client/resources/Resources.java
// public interface Resources extends ClientBundle {
// 	public static final Resources INSTANCE = GWT.create(Resources.class);
// 	
//     @Source("GlobalStyles.css")
//     public Styles css();
// 
//     @Source("WSDOTacronymWhite.png")
//     ImageResource tacronymWhiteLogoPNG();
// 
//     public interface Styles extends CssResource {
//         // CSS classes
// 
//         String loader();
// 
//         String logo();
// 
//         // Graph
//         String graphBlock();
//         String overflowHidden();
//     }
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/shared/SentimentSummary.java
// public class SentimentSummary extends JavaScriptObject {
// 	protected SentimentSummary() {}
// 	
// 	public final native String getId() /*-{ return this._id }-*/;
// 	public final native int getValue() /*-{ return this.value }-*/;
// 	public final native JsArray<SentimentSummary> getSentimentSummary() /*-{ return this }-*/;
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/util/Consts.java
// public final class Consts {
// 
//     public static final String HOST_URL = "http://127.0.0.1:3001";
// 
//     public static final String DEFAULT_ACCOUNT = "wsdot";
// 
//     /**
//      * The caller references the constants using <tt>Consts.EMPTY_STRING</tt>,
//      * and so on. Thus, the caller should be prevented from constructing objects of
//      * this class, by declaring this private constructor.
//      */
//     private Consts() {
//         //this prevents even the native class from
//         //calling this ctor as well :
//         throw new AssertionError();
//     }
// 
// }


import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.jsonp.client.JsonpRequestBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.web.bindery.event.shared.binder.EventBinder;
import com.google.web.bindery.event.shared.binder.EventHandler;
import com.googlecode.gwt.charts.client.*;
import com.googlecode.gwt.charts.client.corechart.PieChart;
import com.googlecode.gwt.charts.client.corechart.PieChartOptions;
import com.googlecode.gwt.charts.client.event.SelectEvent;
import com.googlecode.gwt.charts.client.event.SelectHandler;
import com.googlecode.gwt.charts.client.options.ChartArea;
import com.googlecode.gwt.charts.client.options.Legend;
import com.googlecode.gwt.charts.client.options.LegendPosition;
import gov.wa.wsdot.apps.analytics.client.ClientFactory;
import gov.wa.wsdot.apps.analytics.client.activities.events.DateSubmitEvent;
import gov.wa.wsdot.apps.analytics.client.activities.events.SentimentDisplayEvent;
import gov.wa.wsdot.apps.analytics.client.resources.Resources;
import gov.wa.wsdot.apps.analytics.shared.SentimentSummary;
import gov.wa.wsdot.apps.analytics.util.Consts;
import gwt.material.design.client.ui.MaterialCardContent;
import gwt.material.design.client.ui.MaterialPreLoader;
        this.clientFactory = clientFactory;
        eventBinder.bindEventHandlers(this, clientFactory.getEventBus());
        initWidget(uiBinder.createAndBindUi(this));

    }


    @EventHandler
    void onDateSubmit(DateSubmitEvent event){
        updateChart(event.getDateRange(), event.getAccount());
    }

    /**
     * Requests data from the server
     * @param dateRange
     * @param account
     */
    public static void updateChart(final String dateRange, final String account) {
        cardContent.clear();

        String url = "";
        String screenName = account;

        sentimentLoader.setVisible(true);

        url = JSON_URL + "/sentiment/" + screenName + dateRange;

        JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
        // Set timeout for 30 seconds (30000 milliseconds)
        jsonp.setTimeout(30000);
// Path: src/main/java/gov/wa/wsdot/apps/analytics/client/ClientFactory.java
// public interface ClientFactory {
//     EventBus getEventBus();
//     PlaceController getPlaceController();
//     AnalyticsView getAnalyticsView();
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/client/activities/events/DateSubmitEvent.java
// public class DateSubmitEvent extends GenericEvent {
// 
// 
//     private final String dateRange;
//     private final String account;
//     private final Date startDate;
//     private final Date endDate;
// 
//     public DateSubmitEvent(String dateRange, Date startDate, Date endDate, String account) {
//         this.dateRange = dateRange;
//         this.account = account;
//         this.startDate = startDate;
//         this.endDate = endDate;
//     }
// 
//     public String getDateRange() {
//         return this.dateRange;
//     }
// 
//     public String getAccount() {
//         return this.account;
//     }
// 
//     public Date getStartDate(){ return this.startDate;}
// 
//     public Date getEndDate(){ return this.endDate;}
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/client/activities/events/SentimentDisplayEvent.java
// public class SentimentDisplayEvent extends GenericEvent {
// 
//     String sentiment;
// 
//     public SentimentDisplayEvent(String sentiment){
//         this.sentiment = sentiment;
//     }
// 
//     public String getSentiment(){
//         return sentiment;
//     }
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/client/resources/Resources.java
// public interface Resources extends ClientBundle {
// 	public static final Resources INSTANCE = GWT.create(Resources.class);
// 	
//     @Source("GlobalStyles.css")
//     public Styles css();
// 
//     @Source("WSDOTacronymWhite.png")
//     ImageResource tacronymWhiteLogoPNG();
// 
//     public interface Styles extends CssResource {
//         // CSS classes
// 
//         String loader();
// 
//         String logo();
// 
//         // Graph
//         String graphBlock();
//         String overflowHidden();
//     }
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/shared/SentimentSummary.java
// public class SentimentSummary extends JavaScriptObject {
// 	protected SentimentSummary() {}
// 	
// 	public final native String getId() /*-{ return this._id }-*/;
// 	public final native int getValue() /*-{ return this.value }-*/;
// 	public final native JsArray<SentimentSummary> getSentimentSummary() /*-{ return this }-*/;
// }
// 
// Path: src/main/java/gov/wa/wsdot/apps/analytics/util/Consts.java
// public final class Consts {
// 
//     public static final String HOST_URL = "http://127.0.0.1:3001";
// 
//     public static final String DEFAULT_ACCOUNT = "wsdot";
// 
//     /**
//      * The caller references the constants using <tt>Consts.EMPTY_STRING</tt>,
//      * and so on. Thus, the caller should be prevented from constructing objects of
//      * this class, by declaring this private constructor.
//      */
//     private Consts() {
//         //this prevents even the native class from
//         //calling this ctor as well :
//         throw new AssertionError();
//     }
// 
// }


// Path: src/main/java/gov/wa/wsdot/apps/analytics/client/activities/twitter/view/sentiment/SentimentPieChart.java
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.jsonp.client.JsonpRequestBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.web.bindery.event.shared.binder.EventBinder;
import com.google.web.bindery.event.shared.binder.EventHandler;
import com.googlecode.gwt.charts.client.*;
import com.googlecode.gwt.charts.client.corechart.PieChart;
import com.googlecode.gwt.charts.client.corechart.PieChartOptions;
import com.googlecode.gwt.charts.client.event.SelectEvent;
import com.googlecode.gwt.charts.client.event.SelectHandler;
import com.googlecode.gwt.charts.client.options.ChartArea;
import com.googlecode.gwt.charts.client.options.Legend;
import com.googlecode.gwt.charts.client.options.LegendPosition;
import gov.wa.wsdot.apps.analytics.client.ClientFactory;
import gov.wa.wsdot.apps.analytics.client.activities.events.DateSubmitEvent;
import gov.wa.wsdot.apps.analytics.client.activities.events.SentimentDisplayEvent;
import gov.wa.wsdot.apps.analytics.client.resources.Resources;
import gov.wa.wsdot.apps.analytics.shared.SentimentSummary;
import gov.wa.wsdot.apps.analytics.util.Consts;
import gwt.material.design.client.ui.MaterialCardContent;
import gwt.material.design.client.ui.MaterialPreLoader;

        this.clientFactory = clientFactory;
        eventBinder.bindEventHandlers(this, clientFactory.getEventBus());
        initWidget(uiBinder.createAndBindUi(this));

    }


    @EventHandler
    void onDateSubmit(DateSubmitEvent event){
        updateChart(event.getDateRange(), event.getAccount());
    }

    /**
     * Requests data from the server
     * @param dateRange
     * @param account
     */
    public static void updateChart(final String dateRange, final String account) {
        cardContent.clear();

        String url = "";
        String screenName = account;

        sentimentLoader.setVisible(true);

        url = JSON_URL + "/sentiment/" + screenName + dateRange;

        JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
        // Set timeout for 30 seconds (30000 milliseconds)
        jsonp.setTimeout(30000);
        jsonp.requestObject(url, new AsyncCallback<SentimentSummary>() {