Example usage for com.google.gwt.visualization.client VisualizationUtils loadVisualizationApi

List of usage examples for com.google.gwt.visualization.client VisualizationUtils loadVisualizationApi

Introduction

In this page you can find the example usage for com.google.gwt.visualization.client VisualizationUtils loadVisualizationApi.

Prototype

public static void loadVisualizationApi(Runnable onLoad, String... packages) 

Source Link

Usage

From source file:com.facebook.tsdb.tsdash.client.plot.InteractivePlot.java

License:Apache License

@Override
public void render(final Command onRendered) {
    if (!APILoaded) {
        GWT.log("Loading the API...");
        VisualizationUtils.loadVisualizationApi(new Runnable() {
            @Override//  w  w w. java  2s  . c  om
            public void run() {
                APILoaded = true;
                GWT.log("API loaded");
                render(onRendered);
            }
        }, AnnotatedTimeLine.PACKAGE);
        return;
    }
    if (timeSeriesJSON == null) {
        GWT.log("cannot render: null data");
        return;
    }
    DataTable dataTable = DataTable.create(timeSeriesJSON.getJavaScriptObject());
    Widget w = (Widget) container;
    final AnnotatedTimeLine newChart = new AnnotatedTimeLine(dataTable, getChartOptions(),
            (w.getOffsetWidth() - 10) + "px", (w.getOffsetHeight() - 10) + "px");
    newChart.addReadyHandler(new ReadyHandler() {
        @Override
        public void onReady(ReadyEvent event) {
            endRender(newChart);
            onRendered.execute();
        }
    });
    startRender(newChart);
}

From source file:com.google.gwt.sample.healthyeatingapp.client.Homepage.java

public Homepage() {
    initWidget(tp);/*from   w w w . j  a va  2 s  . co m*/
    // Add a home tab
    tp.add(new FoodLog(tp).onModuleLoad(), "Food Log");
    tp.add(new SocialMedia().SocialMediaWebPageLoad(), "Social Media");
    this.rpc = (DBConnectionServiceAsync) GWT.create(DBConnectionService.class);
    ServiceDefTarget target = (ServiceDefTarget) rpc;
    String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionServiceImpl";
    target.setServiceEntryPoint(moduleRelativeURL);

    Runnable onLoadCallBack = new Runnable() {
        @Override
        public void run() {
            String username = Cookies.getCookie("healthy_app_user");
            rpc.getUserCalories(username, new AsyncCallback<String>() {

                @Override
                public void onFailure(Throwable caught) {
                    // Show the RPC error message to the user
                    Window.alert("No log records for user:" + Cookies.getCookie("healthy_app_user"));
                }

                @Override
                public void onSuccess(String result) {
                    // TODO Auto-generated method stub
                    DataTable data = toDataTable(result);
                    tp.add(new Graph().returnGraph(data), "Graph");
                }
            });
        }
    };

    VisualizationUtils.loadVisualizationApi(onLoadCallBack, CoreChart.PACKAGE);
}

From source file:com.google.sampling.experiential.client.Main.java

License:Open Source License

private void createCallbackForGviz() {
    // Create a callback to be called when the visualization API
    // has been loaded.
    Runnable onLoadCallback = new Runnable() {
        public void run() {
        }/*www  . j a  va2  s. co  m*/
    };
    // Load the visualization api, passing the onLoadCallback to be called
    // when loading is done.
    VisualizationUtils.loadVisualizationApi(onLoadCallback, /*
                                                             * ColumnChart.PACKAGE
                                                             * , Table.PACKAGE,
                                                             */
            LineChart.PACKAGE/* , ScatterChart.PACKAGE */);
}

From source file:com.java33.vizpres.client.view.visualization.GoogleCharts.java

License:Open Source License

@UiConstructor
public GoogleCharts(final int width, final int height) {
    this.width = width;
    this.height = height;
    initWidget(root);/*from   w  w  w.  j av a 2s.  co  m*/
    VisualizationUtils.loadVisualizationApi(new Runnable() {
        @Override
        public void run() {
            GoogleCharts.this.chart = makeChart();
            root.add(chart);
        }
    }, CoreChart.PACKAGE);
}

From source file:com.rhizospherejs.gwt.showcase.client.gviz.GoogleVisualizationTab.java

License:Open Source License

private GoogleVisualizationTab() {
    initWidget(ui.createAndBindUi(this));
    dobInput.setValue(new Date());
    dobInput.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT)));

    // Ensures that both the Google Visualization APIs and Rhizosphere libraries
    // are loaded.
    VisualizationUtils.loadVisualizationApi(new Runnable() {
        @Override/*w  w w . ja  va2  s.  com*/
        public void run() {
            RhizosphereLoader.getInstance().ensureInjected(new Runnable() {
                @Override
                public void run() {
                    // Populate the DataTable with some sample data.
                    initDataTable();

                    // Setup configuration options for both Rhizosphere and the
                    // scatterplot.
                    initOptions();

                    DataView view = DataView.create(dataTable);
                    view.setColumns(new int[] { 1, 2 });
                    scatterChart = new ScatterChart(view, scatterChartOptions);
                    chartContainer.clear();
                    chartContainer.add(scatterChart);

                    rhizosphere = new GVizRhizosphere(dataTable, rhizosphereOptions);
                    rhizosphere.setWidth("400px");
                    rhizosphere.setHeight("400px");
                    rhizosphereContainer.clear();
                    rhizosphereContainer.add(rhizosphere);
                }
            });
        }
    }, "corechart");
}

From source file:com.scalagent.appli.client.Application.java

License:Open Source License

/**
 * This is the entry point method./*from www.j  av a  2s.  co  m*/
 */
public void onModuleLoad2() {

    Runnable onLoadCallback = new Runnable() {
        public void run() {

            serviceAsync = GWT.create(BaseRPCService.class);

            eventBus = new SimpleEventBus();
            serviceCache = new RPCServiceCacheClient(serviceAsync, eventBus, -1);

            ServerPresenter serverPresenter = new ServerPresenter(serviceAsync, eventBus, serviceCache);
            LoginPresenter loginPresenter = new LoginPresenter(serviceAsync, eventBus, serviceCache);
            TopicListPresenter topicPresenter = new TopicListPresenter(serviceAsync, eventBus, serviceCache);
            QueueListPresenter queuePresenter = new QueueListPresenter(serviceAsync, eventBus, serviceCache);
            UserListPresenter userPresenter = new UserListPresenter(serviceAsync, eventBus, serviceCache);
            SubscriptionListPresenter subscriptionPresenter = new SubscriptionListPresenter(serviceAsync,
                    eventBus, serviceCache);

            MainPresenter mainPresenter = new MainPresenter(serviceAsync, serviceCache, eventBus,
                    loginPresenter, serverPresenter, topicPresenter, queuePresenter, userPresenter,
                    subscriptionPresenter);

            eventBus.addHandler(SystemErrorEvent.TYPE, mainPresenter);
            eventBus.addHandler(QueueDetailClickEvent.TYPE, mainPresenter);
            eventBus.addHandler(UserDetailClickEvent.TYPE, mainPresenter);
            eventBus.addHandler(SubscriptionDetailClickEvent.TYPE, mainPresenter);
            eventBus.addHandler(LoginValidEvent.TYPE, mainPresenter);

            eventBus.addHandler(UpdateCompleteEvent.TYPE, serverPresenter);

            eventBus.addHandler(NewTopicEvent.TYPE, topicPresenter);
            eventBus.addHandler(DeletedTopicEvent.TYPE, topicPresenter);
            eventBus.addHandler(UpdatedTopicEvent.TYPE, topicPresenter);
            eventBus.addHandler(UpdateCompleteEvent.TYPE, topicPresenter);

            eventBus.addHandler(NewQueueEvent.TYPE, queuePresenter);
            eventBus.addHandler(DeletedQueueEvent.TYPE, queuePresenter);
            eventBus.addHandler(UpdatedQueueEvent.TYPE, queuePresenter);
            eventBus.addHandler(UpdateCompleteEvent.TYPE, queuePresenter);

            eventBus.addHandler(NewUserEvent.TYPE, userPresenter);
            eventBus.addHandler(DeletedUserEvent.TYPE, userPresenter);
            eventBus.addHandler(UpdatedUserEvent.TYPE, userPresenter);
            eventBus.addHandler(UpdateCompleteEvent.TYPE, userPresenter);

            eventBus.addHandler(NewSubscriptionEvent.TYPE, subscriptionPresenter);
            eventBus.addHandler(DeletedSubscriptionEvent.TYPE, subscriptionPresenter);
            eventBus.addHandler(UpdatedSubscriptionEvent.TYPE, subscriptionPresenter);
            eventBus.addHandler(UpdateCompleteEvent.TYPE, subscriptionPresenter);

            MainWidget mWidget = mainPresenter.getWidget();
            Canvas mainCanvas = (Canvas) mWidget.asWidget();

            mainCanvas.draw();
        }
    };
    VisualizationUtils.loadVisualizationApi(onLoadCallback, AnnotatedTimeLine.PACKAGE);
}

From source file:com.square.client.gwt.client.presenter.personne.PersonneRelationsModePresenter.java

License:Open Source License

@Override
public void onBind() {
    view.getBtAjouterRelationGenerale().addClickHandler(new ClickHandler() {
        @Override/*from w  w  w .j av a  2 s .c  om*/
        public void onClick(ClickEvent event) {
            if (idNaturePersonne != null && (constantes.getIdNaturePersonneVivier().equals(idNaturePersonne)
                    || constantes.getIdNaturePersonneBeneficiaireVivier().equals(idNaturePersonne))) {
                view.afficherPopupErreur(
                        new ErrorPopupConfiguration(presenterConstants.ajoutRelationVivierImpossible()));
            } else {
                if (filtreGroupements != null) {
                    if (personneRelationsFamillePopupPresenter == null) {
                        personneRelationsFamillePopupPresenter = addChildPresenter(
                                new PersonneRelationsPopupPresenter(eventBus, personneRpcService,
                                        personnePhysiqueRpcService, personneMoraleRpcService,
                                        dimensionRpcService,
                                        new PersonneRelationPopupViewImpl(constantes.isHasRoleAdmin()),
                                        constantes, idPersonne, nomPersonne, filtreGroupements,
                                        filtrePasDansGroupements, typePersonneSource, deskBar, aideService));

                        personneRelationsFamillePopupPresenter.addEventHandlerToLocalBus(
                                SimpleValueChangeEvent.TYPE, new SimpleValueChangeEventHandler<String>() {
                                    @Override
                                    public void onValueChange(SimpleValueChangeEvent<String> event) {
                                        switchModeEdition(modeCourant);
                                    }
                                });
                        personneRelationsFamillePopupPresenter.showPresenter(null);
                    } else {
                        personneRelationsFamillePopupPresenter.afficherPopupAjoutRelation();
                    }
                }
                if (filtrePasDansGroupements != null) {
                    if (personneRelationsPopupPresenter == null) {
                        personneRelationsPopupPresenter = addChildPresenter(new PersonneRelationsPopupPresenter(
                                eventBus, personneRpcService, personnePhysiqueRpcService,
                                personneMoraleRpcService, dimensionRpcService,
                                new PersonneRelationPopupViewImpl(constantes.isHasRoleAdmin()), constantes,
                                idPersonne, nomPersonne, filtreGroupements, filtrePasDansGroupements,
                                typePersonneSource, deskBar, aideService));
                        personneRelationsPopupPresenter.addEventHandlerToLocalBus(SimpleValueChangeEvent.TYPE,
                                new SimpleValueChangeEventHandler<String>() {
                                    @Override
                                    public void onValueChange(SimpleValueChangeEvent<String> event) {
                                        switchModeEdition(modeCourant);
                                    }
                                });
                        personneRelationsPopupPresenter.showPresenter(null);
                    } else {
                        personneRelationsPopupPresenter.afficherPopupAjoutRelation();
                    }
                }
            }
        }
    });
    view.getBtEnregistrerRelationGenerale().addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (personneRelationsPresenter.isDatesValides()) {
                personneRelationsPresenter.modifierRelations();
            }
        }
    });
    view.btChangementDeMode().addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (modeCourant == AppControllerConstants.MODE_RELATION_EDITION) {
                switchModeEdition(AppControllerConstants.MODE_RELATION_GRAPHIQUE);
            } else {
                switchModeEdition(AppControllerConstants.MODE_RELATION_EDITION);
            }
        }
    });
    // Tentative de connexion a internet pour dterminer si la visualisation est disponible.
    view.afficherChangementMode(false);
    final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "http://www.google.fr");
    rb.setHeader("Access-Control-Allow-Origin", "http://www.google.fr");
    final int timeout = 15000;
    rb.setTimeoutMillis(timeout);
    rb.setCallback(new RequestCallback() {

        @Override
        public void onResponseReceived(Request request, Response response) {
            if (response != null) {
                final Runnable onLoadCallback = new Runnable() {
                    public void run() {
                        view.afficherChangementMode(true);
                    }
                };
                VisualizationUtils.loadVisualizationApi(onLoadCallback, OrgChart.PACKAGE);
            }
        }

        @Override
        public void onError(Request request, Throwable exception) {
        }
    });
    try {
        rb.send();
    } catch (RequestException e) {
        GWT.log("", e);
    }
}

From source file:com.square.composant.contrat.personne.morale.square.client.presenter.ContratsPersonneMoralePresenter.java

License:Open Source License

/** Charge les infos des contrats. */
private void chargerInfosContrat() {
    // Chargement des contrats de la personne
    view.afficherLoadingPopup(new LoadingPopupConfiguration(presenterConstants.chargementListeContrats()));
    // Cration du callback
    final AsyncCallback<InfosContratsPersonneMoraleModel> asyncCallback = new AsyncCallback<InfosContratsPersonneMoraleModel>() {
        @Override/* ww w. j a  v  a2  s.c  o  m*/
        public void onSuccess(final InfosContratsPersonneMoraleModel result) {
            view.onRpcServiceSuccess();
            // Tentative de connexion a internet pour dterminer si la visualisation est disponible.
            final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "http://www.google.fr");
            rb.setHeader("Access-Control-Allow-Origin", "http://www.google.fr");
            final int timeout = 15000;
            rb.setTimeoutMillis(timeout);
            rb.setCallback(new RequestCallback() {
                @Override
                public void onResponseReceived(Request request, Response response) {
                    GWT.log("response : " + response);
                    if (response != null) {
                        final Runnable onLoadCallback = new Runnable() {
                            public void run() {
                                // Construction du camembert reprsentant les populations
                                construireDonneesPopulation(result.getSyntheseContrat().getPopulation());
                            }
                        };
                        VisualizationUtils.loadVisualizationApi(onLoadCallback, "corechart");
                    }
                }

                @Override
                public void onError(Request request, Throwable exception) {
                }
            });
            try {
                rb.send();
            } catch (RequestException e) {
                GWT.log("", e);
            }

            // Chargement des infos
            initInfosContrats(result);

            final int nbContratsCharges = result.getListeContrats().size();
            fireEventLocalBus(new ContratsPersonneMoraleChargesEvent(nbContratsCharges));
        }

        @Override
        public void onFailure(Throwable caught) {
            view.onRpcServiceFailure(new ErrorPopupConfiguration(caught));
        }
    };
    contratServiceRpc.getInfosContratPersonneMorale(idPersonneMorale, asyncCallback);
}

From source file:com.square.composant.contrat.personne.morale.square.client.view.ContratsPersonneMoraleViewImpl.java

License:Open Source License

@Override
public void afficherCamembertPopulation(final DataTable donneesPopulation) {
    final Runnable onLoadCallback = new Runnable() {
        public void run() {
            final Options options = Options.create();
            options.setSize(ContratsPersonneMoraleViewImplConstants.LARGEUR_CHART,
                    ContratsPersonneMoraleViewImplConstants.HAUTEUR_CHART);
            options.setLegend(LegendPosition.NONE);
            options.setBackgroundColor(ContratsPersonneMoraleViewImplConstants.COULEUR_FOND_STATISTIQUE);
            options.setTitle(viewConstants.titrePopulation());
            options.setTitleFontSize(12);
            final PieChart pieChartPopulation = new PieChart(donneesPopulation, options);
            panelPieChartPopulation.add(pieChartPopulation);
            panelPieChartPopulation.setCellVerticalAlignment(pieChartPopulation, HasAlignment.ALIGN_TOP);
            panelPieChartPopulation.setVisible(true);
        }//from  ww w .  j  a  v a  2s .  com
    };
    VisualizationUtils.loadVisualizationApi(onLoadCallback, "corechart");
    panelPieChartPopulation.setVisible(true);
}

From source file:com.square.composant.contrat.square.client.presenter.ContratsPresenter.java

License:Open Source License

/**
 * Charge l'API graphique puis les graphiques si la connexion  Internet existe.
 * @param infosContrats les infos de contrat
 *///from   w  w w.ja  va 2  s  . com
private void chargerApiVisualisation(final InfosContratsModel infosContrats) {
    currentInfosContrats = infosContrats;
    // Tentative de connexion a internet pour dterminer si la visualisation est disponible.
    final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "http://www.google.fr");
    rb.setHeader("Access-Control-Allow-Origin", "http://www.google.fr");
    final int timeout = 15000;
    rb.setTimeoutMillis(timeout);
    rb.setCallback(new RequestCallback() {
        @Override
        public void onResponseReceived(Request request, Response response) {
            if (response != null) {
                final Runnable onLoadCallback = new Runnable() {
                    public void run() {
                        // Chargement des graphiques
                        chargerGraphiques();
                    }
                };
                VisualizationUtils.loadVisualizationApi(onLoadCallback, OrgChart.PACKAGE);
            }
        }

        @Override
        public void onError(Request request, Throwable exception) {
        }
    });
    try {
        rb.send();
    } catch (RequestException e) {
        GWT.log("", e);
    }
}