123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674 |
- /*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
- package com.vaadin.client;
-
- import java.util.HashMap;
- import java.util.Map;
- import java.util.logging.Logger;
-
- import com.google.gwt.aria.client.LiveValue;
- import com.google.gwt.aria.client.RelevantValue;
- import com.google.gwt.aria.client.Roles;
- import com.google.gwt.core.client.Duration;
- import com.google.gwt.core.client.GWT;
- import com.google.gwt.core.client.JavaScriptObject;
- import com.google.gwt.core.client.JsArrayString;
- import com.google.gwt.core.client.Scheduler;
- import com.google.gwt.dom.client.Element;
- import com.google.gwt.event.shared.EventBus;
- import com.google.gwt.event.shared.EventHandler;
- import com.google.gwt.event.shared.GwtEvent;
- import com.google.gwt.event.shared.HandlerRegistration;
- import com.google.gwt.event.shared.HasHandlers;
- import com.google.gwt.event.shared.SimpleEventBus;
- import com.google.gwt.http.client.URL;
- import com.google.gwt.user.client.Command;
- import com.google.gwt.user.client.DOM;
- import com.google.gwt.user.client.Timer;
- import com.google.gwt.user.client.ui.HasWidgets;
- import com.google.gwt.user.client.ui.Widget;
- import com.vaadin.client.ApplicationConfiguration.ErrorMessage;
- import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent;
- import com.vaadin.client.ResourceLoader.ResourceLoadEvent;
- import com.vaadin.client.ResourceLoader.ResourceLoadListener;
- import com.vaadin.client.communication.CommunicationProblemHandler;
- import com.vaadin.client.communication.Heartbeat;
- import com.vaadin.client.communication.ReconnectingCommunicationProblemHandler;
- import com.vaadin.client.communication.RpcManager;
- import com.vaadin.client.communication.ServerCommunicationHandler;
- import com.vaadin.client.communication.ServerMessageHandler;
- import com.vaadin.client.communication.ServerRpcQueue;
- import com.vaadin.client.componentlocator.ComponentLocator;
- import com.vaadin.client.metadata.ConnectorBundleLoader;
- import com.vaadin.client.ui.AbstractComponentConnector;
- import com.vaadin.client.ui.FontIcon;
- import com.vaadin.client.ui.Icon;
- import com.vaadin.client.ui.ImageIcon;
- import com.vaadin.client.ui.VContextMenu;
- import com.vaadin.client.ui.VNotification;
- import com.vaadin.client.ui.VOverlay;
- import com.vaadin.client.ui.ui.UIConnector;
- import com.vaadin.shared.AbstractComponentState;
- import com.vaadin.shared.VaadinUriResolver;
- import com.vaadin.shared.Version;
- import com.vaadin.shared.communication.LegacyChangeVariablesInvocation;
- import com.vaadin.shared.util.SharedUtil;
-
- /**
- * This is the client side communication "engine", managing client-server
- * communication with its server side counterpart
- * com.vaadin.server.VaadinService.
- *
- * Client-side connectors receive updates from the corresponding server-side
- * connector (typically component) as state updates or RPC calls. The connector
- * has the possibility to communicate back with its server side counter part
- * through RPC calls.
- *
- * TODO document better
- *
- * Entry point classes (widgetsets) define <code>onModuleLoad()</code>.
- */
- public class ApplicationConnection implements HasHandlers {
-
- @Deprecated
- public static final String MODIFIED_CLASSNAME = StyleConstants.MODIFIED;
-
- @Deprecated
- public static final String DISABLED_CLASSNAME = StyleConstants.DISABLED;
-
- @Deprecated
- public static final String REQUIRED_CLASSNAME = StyleConstants.REQUIRED;
-
- @Deprecated
- public static final String REQUIRED_CLASSNAME_EXT = StyleConstants.REQUIRED_EXT;
-
- @Deprecated
- public static final String ERROR_CLASSNAME_EXT = StyleConstants.ERROR_EXT;
-
- /**
- * A string that, if found in a non-JSON response to a UIDL request, will
- * cause the browser to refresh the page. If followed by a colon, optional
- * whitespace, and a URI, causes the browser to synchronously load the URI.
- *
- * <p>
- * This allows, for instance, a servlet filter to redirect the application
- * to a custom login page when the session expires. For example:
- * </p>
- *
- * <pre>
- * if (sessionExpired) {
- * response.setHeader("Content-Type", "text/html");
- * response.getWriter().write(
- * myLoginPageHtml + "<!-- Vaadin-Refresh: "
- * + request.getContextPath() + " -->");
- * }
- * </pre>
- */
- public static final String UIDL_REFRESH_TOKEN = "Vaadin-Refresh";
-
- private final HashMap<String, String> resourcesMap = new HashMap<String, String>();
-
- private WidgetSet widgetSet;
-
- private VContextMenu contextMenu = null;
-
- private final UIConnector uIConnector;
-
- protected boolean cssLoaded = false;
-
- /** Parameters for this application connection loaded from the web-page */
- private ApplicationConfiguration configuration;
-
- private final LayoutManager layoutManager;
-
- private final RpcManager rpcManager;
-
- /** Event bus for communication events */
- private EventBus eventBus = GWT.create(SimpleEventBus.class);
-
- public enum State {
- INITIALIZING, RUNNING, TERMINATED;
- }
-
- private State state = State.INITIALIZING;
-
- /**
- * The communication handler methods are called at certain points during
- * communication with the server. This allows for making add-ons that keep
- * track of different aspects of the communication.
- */
- public interface CommunicationHandler extends EventHandler {
- void onRequestStarting(RequestStartingEvent e);
-
- void onResponseHandlingStarted(ResponseHandlingStartedEvent e);
-
- void onResponseHandlingEnded(ResponseHandlingEndedEvent e);
- }
-
- public static class RequestStartingEvent extends ApplicationConnectionEvent {
-
- public static Type<CommunicationHandler> TYPE = new Type<CommunicationHandler>();
-
- public RequestStartingEvent(ApplicationConnection connection) {
- super(connection);
- }
-
- @Override
- public Type<CommunicationHandler> getAssociatedType() {
- return TYPE;
- }
-
- @Override
- protected void dispatch(CommunicationHandler handler) {
- handler.onRequestStarting(this);
- }
- }
-
- public static class ResponseHandlingEndedEvent extends
- ApplicationConnectionEvent {
-
- public static Type<CommunicationHandler> TYPE = new Type<CommunicationHandler>();
-
- public ResponseHandlingEndedEvent(ApplicationConnection connection) {
- super(connection);
- }
-
- @Override
- public Type<CommunicationHandler> getAssociatedType() {
- return TYPE;
- }
-
- @Override
- protected void dispatch(CommunicationHandler handler) {
- handler.onResponseHandlingEnded(this);
- }
- }
-
- public static abstract class ApplicationConnectionEvent extends
- GwtEvent<CommunicationHandler> {
-
- private ApplicationConnection connection;
-
- protected ApplicationConnectionEvent(ApplicationConnection connection) {
- this.connection = connection;
- }
-
- public ApplicationConnection getConnection() {
- return connection;
- }
-
- }
-
- public static class ResponseHandlingStartedEvent extends
- ApplicationConnectionEvent {
-
- public ResponseHandlingStartedEvent(ApplicationConnection connection) {
- super(connection);
- }
-
- public static Type<CommunicationHandler> TYPE = new Type<CommunicationHandler>();
-
- @Override
- public Type<CommunicationHandler> getAssociatedType() {
- return TYPE;
- }
-
- @Override
- protected void dispatch(CommunicationHandler handler) {
- handler.onResponseHandlingStarted(this);
- }
- }
-
- /**
- * Event triggered when a application is stopped by calling
- * {@link ApplicationConnection#setApplicationRunning(false)}.
- *
- * To listen for the event add a {@link ApplicationStoppedHandler} by
- * invoking
- * {@link ApplicationConnection#addHandler(ApplicationConnection.ApplicationStoppedEvent.Type, ApplicationStoppedHandler)}
- * to the {@link ApplicationConnection}
- *
- * @since 7.1.8
- * @author Vaadin Ltd
- */
- public static class ApplicationStoppedEvent extends
- GwtEvent<ApplicationStoppedHandler> {
-
- public static Type<ApplicationStoppedHandler> TYPE = new Type<ApplicationStoppedHandler>();
-
- @Override
- public Type<ApplicationStoppedHandler> getAssociatedType() {
- return TYPE;
- }
-
- @Override
- protected void dispatch(ApplicationStoppedHandler listener) {
- listener.onApplicationStopped(this);
- }
- }
-
- /**
- * Allows custom handling of communication errors.
- */
- public interface CommunicationErrorHandler {
- /**
- * Called when a communication error has occurred. Returning
- * <code>true</code> from this method suppresses error handling.
- *
- * @param details
- * A string describing the error.
- * @param statusCode
- * The HTTP status code (e.g. 404, etc).
- * @return true if the error reporting should be suppressed, false to
- * perform normal error reporting.
- */
- public boolean onError(String details, int statusCode);
- }
-
- /**
- * A listener for listening to application stopped events. The listener can
- * be added to a {@link ApplicationConnection} by invoking
- * {@link ApplicationConnection#addHandler(ApplicationStoppedEvent.Type, ApplicationStoppedHandler)}
- *
- * @since 7.1.8
- * @author Vaadin Ltd
- */
- public interface ApplicationStoppedHandler extends EventHandler {
-
- /**
- * Triggered when the {@link ApplicationConnection} marks a previously
- * running application as stopped by invoking
- * {@link ApplicationConnection#setApplicationRunning(false)}
- *
- * @param event
- * the event triggered by the {@link ApplicationConnection}
- */
- void onApplicationStopped(ApplicationStoppedEvent event);
- }
-
- private CommunicationErrorHandler communicationErrorDelegate = null;
-
- private VLoadingIndicator loadingIndicator;
-
- private Heartbeat heartbeat = GWT.create(Heartbeat.class);
-
- private boolean tooltipInitialized = false;
-
- private final VaadinUriResolver uriResolver = new VaadinUriResolver() {
- @Override
- protected String getVaadinDirUrl() {
- return getConfiguration().getVaadinDirUrl();
- }
-
- @Override
- protected String getServiceUrlParameterName() {
- return getConfiguration().getServiceUrlParameterName();
- }
-
- @Override
- protected String getServiceUrl() {
- return getConfiguration().getServiceUrl();
- }
-
- @Override
- protected String getThemeUri() {
- return ApplicationConnection.this.getThemeUri();
- }
-
- @Override
- protected String encodeQueryStringParameterValue(String queryString) {
- return URL.encodeQueryString(queryString);
- }
- };
-
- public static class MultiStepDuration extends Duration {
- private int previousStep = elapsedMillis();
-
- public void logDuration(String message) {
- logDuration(message, 0);
- }
-
- public void logDuration(String message, int minDuration) {
- int currentTime = elapsedMillis();
- int stepDuration = currentTime - previousStep;
- if (stepDuration >= minDuration) {
- getLogger().info(message + ": " + stepDuration + " ms");
- }
- previousStep = currentTime;
- }
- }
-
- public ApplicationConnection() {
- // Assuming UI data is eagerly loaded
- ConnectorBundleLoader.get().loadBundle(
- ConnectorBundleLoader.EAGER_BUNDLE_NAME, null);
- uIConnector = GWT.create(UIConnector.class);
- rpcManager = GWT.create(RpcManager.class);
- layoutManager = GWT.create(LayoutManager.class);
- layoutManager.setConnection(this);
- tooltip = GWT.create(VTooltip.class);
- loadingIndicator = GWT.create(VLoadingIndicator.class);
- loadingIndicator.setConnection(this);
- serverRpcQueue = GWT.create(ServerRpcQueue.class);
- serverRpcQueue.setConnection(this);
- communicationProblemHandler = GWT
- .create(ReconnectingCommunicationProblemHandler.class);
- communicationProblemHandler.setConnection(this);
- serverMessageHandler = GWT.create(ServerMessageHandler.class);
- serverMessageHandler.setConnection(this);
- serverCommunicationHandler = GWT
- .create(ServerCommunicationHandler.class);
- serverCommunicationHandler.setConnection(this);
- }
-
- public void init(WidgetSet widgetSet, ApplicationConfiguration cnf) {
- getLogger().info("Starting application " + cnf.getRootPanelId());
- getLogger().info("Using theme: " + cnf.getThemeName());
-
- getLogger().info(
- "Vaadin application servlet version: "
- + cnf.getServletVersion());
-
- if (!cnf.getServletVersion().equals(Version.getFullVersion())) {
- getLogger()
- .severe("Warning: your widget set seems to be built with a different "
- + "version than the one used on server. Unexpected "
- + "behavior may occur.");
- }
-
- this.widgetSet = widgetSet;
- configuration = cnf;
-
- ComponentLocator componentLocator = new ComponentLocator(this);
-
- String appRootPanelName = cnf.getRootPanelId();
- // remove the end (window name) of autogenerated rootpanel id
- appRootPanelName = appRootPanelName.replaceFirst("-\\d+$", "");
-
- initializeTestbenchHooks(componentLocator, appRootPanelName);
-
- initializeClientHooks();
-
- uIConnector.init(cnf.getRootPanelId(), this);
-
- tooltip.setOwner(uIConnector.getWidget());
-
- getLoadingIndicator().show();
-
- heartbeat.init(this);
-
- // Ensure the overlay container is added to the dom and set as a live
- // area for assistive devices
- Element overlayContainer = VOverlay.getOverlayContainer(this);
- Roles.getAlertRole().setAriaLiveProperty(overlayContainer,
- LiveValue.ASSERTIVE);
- VOverlay.setOverlayContainerLabel(this,
- getUIConnector().getState().overlayContainerLabel);
- Roles.getAlertRole().setAriaRelevantProperty(overlayContainer,
- RelevantValue.ADDITIONS);
- }
-
- /**
- * Starts this application. Don't call this method directly - it's called by
- * {@link ApplicationConfiguration#startNextApplication()}, which should be
- * called once this application has started (first response received) or
- * failed to start. This ensures that the applications are started in order,
- * to avoid session-id problems.
- *
- */
- public void start() {
- String jsonText = configuration.getUIDL();
- if (jsonText == null) {
- // initial UIDL not in DOM, request from server
- getServerCommunicationHandler().resynchronize();
- } else {
- // initial UIDL provided in DOM, continue as if returned by request
-
- // Hack to avoid logging an error in endRequest()
- getServerCommunicationHandler().startRequest();
- getServerMessageHandler().handleMessage(
- ServerMessageHandler.parseJson(jsonText));
- }
-
- // Tooltip can't be created earlier because the
- // necessary fields are not setup to add it in the
- // correct place in the DOM
- if (!tooltipInitialized) {
- tooltipInitialized = true;
- ApplicationConfiguration.runWhenDependenciesLoaded(new Command() {
- @Override
- public void execute() {
- getVTooltip().initializeAssistiveTooltips();
- }
- });
- }
- }
-
- /**
- * Checks if there is some work to be done on the client side
- *
- * @return true if the client has some work to be done, false otherwise
- */
- private boolean isActive() {
- return !getServerMessageHandler().isInitialUidlHandled()
- || isWorkPending()
- || getServerCommunicationHandler().hasActiveRequest()
- || isExecutingDeferredCommands();
- }
-
- private native void initializeTestbenchHooks(
- ComponentLocator componentLocator, String TTAppId)
- /*-{
- var ap = this;
- var client = {};
- client.isActive = $entry(function() {
- return ap.@com.vaadin.client.ApplicationConnection::isActive()();
- });
- var vi = ap.@com.vaadin.client.ApplicationConnection::getVersionInfo()();
- if (vi) {
- client.getVersionInfo = function() {
- return vi;
- }
- }
-
- client.getProfilingData = $entry(function() {
- var smh = ap.@com.vaadin.client.ApplicationConnection::getServerMessageHandler();
- var pd = [
- smh.@com.vaadin.client.communication.ServerMessageHandler::lastProcessingTime,
- smh.@com.vaadin.client.communication.ServerMessageHandler::totalProcessingTime
- ];
- pd = pd.concat(smh.@com.vaadin.client.communication.ServerMessageHandler::serverTimingInfo);
- pd[pd.length] = smh.@com.vaadin.client.communication.ServerMessageHandler::bootstrapTime;
- return pd;
- });
-
- client.getElementByPath = $entry(function(id) {
- return componentLocator.@com.vaadin.client.componentlocator.ComponentLocator::getElementByPath(Ljava/lang/String;)(id);
- });
- client.getElementByPathStartingAt = $entry(function(id, element) {
- return componentLocator.@com.vaadin.client.componentlocator.ComponentLocator::getElementByPathStartingAt(Ljava/lang/String;Lcom/google/gwt/dom/client/Element;)(id, element);
- });
- client.getElementsByPath = $entry(function(id) {
- return componentLocator.@com.vaadin.client.componentlocator.ComponentLocator::getElementsByPath(Ljava/lang/String;)(id);
- });
- client.getElementsByPathStartingAt = $entry(function(id, element) {
- return componentLocator.@com.vaadin.client.componentlocator.ComponentLocator::getElementsByPathStartingAt(Ljava/lang/String;Lcom/google/gwt/dom/client/Element;)(id, element);
- });
- client.getPathForElement = $entry(function(element) {
- return componentLocator.@com.vaadin.client.componentlocator.ComponentLocator::getPathForElement(Lcom/google/gwt/dom/client/Element;)(element);
- });
- client.initializing = false;
-
- $wnd.vaadin.clients[TTAppId] = client;
- }-*/;
-
- /**
- * Helper for tt initialization
- */
- private JavaScriptObject getVersionInfo() {
- return configuration.getVersionInfoJSObject();
- }
-
- /**
- * Publishes a JavaScript API for mash-up applications.
- * <ul>
- * <li><code>vaadin.forceSync()</code> sends pending variable changes, in
- * effect synchronizing the server and client state. This is done for all
- * applications on host page.</li>
- * <li><code>vaadin.postRequestHooks</code> is a map of functions which gets
- * called after each XHR made by vaadin application. Note, that it is
- * attaching js functions responsibility to create the variable like this:
- *
- * <code><pre>
- * if(!vaadin.postRequestHooks) {vaadin.postRequestHooks = new Object();}
- * postRequestHooks.myHook = function(appId) {
- * if(appId == "MyAppOfInterest") {
- * // do the staff you need on xhr activity
- * }
- * }
- * </pre></code> First parameter passed to these functions is the identifier
- * of Vaadin application that made the request.
- * </ul>
- *
- * TODO make this multi-app aware
- */
- private native void initializeClientHooks()
- /*-{
- var app = this;
- var oldSync;
- if ($wnd.vaadin.forceSync) {
- oldSync = $wnd.vaadin.forceSync;
- }
- $wnd.vaadin.forceSync = $entry(function() {
- if (oldSync) {
- oldSync();
- }
- app.@com.vaadin.client.ApplicationConnection::sendPendingVariableChanges()();
- });
- var oldForceLayout;
- if ($wnd.vaadin.forceLayout) {
- oldForceLayout = $wnd.vaadin.forceLayout;
- }
- $wnd.vaadin.forceLayout = $entry(function() {
- if (oldForceLayout) {
- oldForceLayout();
- }
- app.@com.vaadin.client.ApplicationConnection::forceLayout()();
- });
- }-*/;
-
- /**
- * Runs possibly registered client side post request hooks. This is expected
- * to be run after each uidl request made by Vaadin application.
- *
- * @param appId
- */
- public static native void runPostRequestHooks(String appId)
- /*-{
- if ($wnd.vaadin.postRequestHooks) {
- for ( var hook in $wnd.vaadin.postRequestHooks) {
- if (typeof ($wnd.vaadin.postRequestHooks[hook]) == "function") {
- try {
- $wnd.vaadin.postRequestHooks[hook](appId);
- } catch (e) {
- }
- }
- }
- }
- }-*/;
-
- /**
- * If on Liferay and logged in, ask the client side session management
- * JavaScript to extend the session duration.
- *
- * Otherwise, Liferay client side JavaScript will explicitly expire the
- * session even though the server side considers the session to be active.
- * See ticket #8305 for more information.
- */
- public static native void extendLiferaySession()
- /*-{
- if ($wnd.Liferay && $wnd.Liferay.Session) {
- $wnd.Liferay.Session.extend();
- // if the extend banner is visible, hide it
- if ($wnd.Liferay.Session.banner) {
- $wnd.Liferay.Session.banner.remove();
- }
- }
- }-*/;
-
- /**
- * Requests an analyze of layouts, to find inconsistencies. Exclusively used
- * for debugging during development.
- *
- * @deprecated as of 7.1. Replaced by {@link UIConnector#analyzeLayouts()}
- */
- @Deprecated
- public void analyzeLayouts() {
- getUIConnector().analyzeLayouts();
- }
-
- /**
- * Sends a request to the server to print details to console that will help
- * the developer to locate the corresponding server-side connector in the
- * source code.
- *
- * @param serverConnector
- * @deprecated as of 7.1. Replaced by
- * {@link UIConnector#showServerDebugInfo(ServerConnector)}
- */
- @Deprecated
- void highlightConnector(ServerConnector serverConnector) {
- getUIConnector().showServerDebugInfo(serverConnector);
- }
-
- int cssWaits = 0;
-
- protected ServerRpcQueue serverRpcQueue;
- protected CommunicationProblemHandler communicationProblemHandler;
- protected ServerMessageHandler serverMessageHandler;
- protected ServerCommunicationHandler serverCommunicationHandler;
-
- static final int MAX_CSS_WAITS = 100;
-
- public void executeWhenCSSLoaded(final Command c) {
- if (!isCSSLoaded() && cssWaits < MAX_CSS_WAITS) {
- (new Timer() {
- @Override
- public void run() {
- executeWhenCSSLoaded(c);
- }
- }).schedule(50);
-
- // Show this message just once
- if (cssWaits++ == 0) {
- getLogger().warning(
- "Assuming CSS loading is not complete, "
- + "postponing render phase. "
- + "(.v-loading-indicator height == 0)");
- }
- } else {
- cssLoaded = true;
- if (cssWaits >= MAX_CSS_WAITS) {
- getLogger().severe("CSS files may have not loaded properly.");
- }
-
- c.execute();
- }
- }
-
- /**
- * Checks whether or not the CSS is loaded. By default checks the size of
- * the loading indicator element.
- *
- * @return
- */
- protected boolean isCSSLoaded() {
- return cssLoaded
- || getLoadingIndicator().getElement().getOffsetHeight() != 0;
- }
-
- /**
- * Shows the communication error notification.
- *
- * @param details
- * Optional details.
- * @param statusCode
- * The status code returned for the request
- *
- */
- public void showCommunicationError(String details, int statusCode) {
- getLogger().severe("Communication error: " + details);
- showError(details, configuration.getCommunicationError());
- }
-
- /**
- * Shows the authentication error notification.
- *
- * @param details
- * Optional details.
- */
- public void showAuthenticationError(String details) {
- getLogger().severe("Authentication error: " + details);
- showError(details, configuration.getAuthorizationError());
- }
-
- /**
- * Shows the session expiration notification.
- *
- * @param details
- * Optional details.
- */
- public void showSessionExpiredError(String details) {
- getLogger().severe("Session expired: " + details);
- showError(details, configuration.getSessionExpiredError());
- }
-
- /**
- * Shows an error notification.
- *
- * @param details
- * Optional details.
- * @param message
- * An ErrorMessage describing the error.
- */
- protected void showError(String details, ErrorMessage message) {
- VNotification.showError(this, message.getCaption(),
- message.getMessage(), details, message.getUrl());
- }
-
- /**
- * Checks if the client has running or scheduled commands
- */
- private boolean isWorkPending() {
- ConnectorMap connectorMap = getConnectorMap();
- JsArrayObject<ServerConnector> connectors = connectorMap
- .getConnectorsAsJsArray();
- int size = connectors.size();
- for (int i = 0; i < size; i++) {
- ServerConnector conn = connectors.get(i);
- if (isWorkPending(conn)) {
- return true;
- }
-
- if (conn instanceof ComponentConnector) {
- ComponentConnector compConn = (ComponentConnector) conn;
- if (isWorkPending(compConn.getWidget())) {
- return true;
- }
- }
- }
- return false;
- }
-
- private static boolean isWorkPending(Object object) {
- return object instanceof DeferredWorker
- && ((DeferredWorker) object).isWorkPending();
- }
-
- /**
- * Checks if deferred commands are (potentially) still being executed as a
- * result of an update from the server. Returns true if a deferred command
- * might still be executing, false otherwise. This will not work correctly
- * if a deferred command is added in another deferred command.
- * <p>
- * Used by the native "client.isActive" function.
- * </p>
- *
- * @return true if deferred commands are (potentially) being executed, false
- * otherwise
- */
- private boolean isExecutingDeferredCommands() {
- Scheduler s = Scheduler.get();
- if (s instanceof VSchedulerImpl) {
- return ((VSchedulerImpl) s).hasWorkQueued();
- } else {
- return false;
- }
- }
-
- /**
- * Returns the loading indicator used by this ApplicationConnection
- *
- * @return The loading indicator for this ApplicationConnection
- */
- public VLoadingIndicator getLoadingIndicator() {
- return loadingIndicator;
- }
-
- /**
- * Determines whether or not the loading indicator is showing.
- *
- * @return true if the loading indicator is visible
- * @deprecated As of 7.1. Use {@link #getLoadingIndicator()} and
- * {@link VLoadingIndicator#isVisible()}.isVisible() instead.
- */
- @Deprecated
- public boolean isLoadingIndicatorVisible() {
- return getLoadingIndicator().isVisible();
- }
-
- public void loadStyleDependencies(JsArrayString dependencies) {
- // Assuming no reason to interpret in a defined order
- ResourceLoadListener resourceLoadListener = new ResourceLoadListener() {
- @Override
- public void onLoad(ResourceLoadEvent event) {
- ApplicationConfiguration.endDependencyLoading();
- }
-
- @Override
- public void onError(ResourceLoadEvent event) {
- getLogger()
- .severe(event.getResourceUrl()
- + " could not be loaded, or the load detection failed because the stylesheet is empty.");
- // The show must go on
- onLoad(event);
- }
- };
- ResourceLoader loader = ResourceLoader.get();
- for (int i = 0; i < dependencies.length(); i++) {
- String url = translateVaadinUri(dependencies.get(i));
- ApplicationConfiguration.startDependencyLoading();
- loader.loadStylesheet(url, resourceLoadListener);
- }
- }
-
- public void loadScriptDependencies(final JsArrayString dependencies) {
- if (dependencies.length() == 0) {
- return;
- }
-
- // Listener that loads the next when one is completed
- ResourceLoadListener resourceLoadListener = new ResourceLoadListener() {
- @Override
- public void onLoad(ResourceLoadEvent event) {
- if (dependencies.length() != 0) {
- String url = translateVaadinUri(dependencies.shift());
- ApplicationConfiguration.startDependencyLoading();
- // Load next in chain (hopefully already preloaded)
- event.getResourceLoader().loadScript(url, this);
- }
- // Call start for next before calling end for current
- ApplicationConfiguration.endDependencyLoading();
- }
-
- @Override
- public void onError(ResourceLoadEvent event) {
- getLogger().severe(
- event.getResourceUrl() + " could not be loaded.");
- // The show must go on
- onLoad(event);
- }
- };
-
- ResourceLoader loader = ResourceLoader.get();
-
- // Start chain by loading first
- String url = translateVaadinUri(dependencies.shift());
- ApplicationConfiguration.startDependencyLoading();
- loader.loadScript(url, resourceLoadListener);
-
- if (ResourceLoader.supportsInOrderScriptExecution()) {
- for (int i = 0; i < dependencies.length(); i++) {
- String preloadUrl = translateVaadinUri(dependencies.get(i));
- loader.loadScript(preloadUrl, null);
- }
- } else {
- // Preload all remaining
- for (int i = 0; i < dependencies.length(); i++) {
- String preloadUrl = translateVaadinUri(dependencies.get(i));
- loader.preloadResource(preloadUrl, null);
- }
- }
- }
-
- private void addVariableToQueue(String connectorId, String variableName,
- Object value, boolean immediate) {
- boolean lastOnly = !immediate;
- // note that type is now deduced from value
- serverRpcQueue.add(new LegacyChangeVariablesInvocation(connectorId,
- variableName, value), lastOnly);
- if (immediate) {
- serverRpcQueue.flush();
- }
- }
-
- /**
- * @deprecated as of 7.6, use {@link ServerRpcQueue#flush()}
- */
- @Deprecated
- public void sendPendingVariableChanges() {
- serverRpcQueue.flush();
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * </p>
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param newValue
- * the new value to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
- public void updateVariable(String paintableId, String variableName,
- ServerConnector newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, newValue, immediate);
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * </p>
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param newValue
- * the new value to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
-
- public void updateVariable(String paintableId, String variableName,
- String newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, newValue, immediate);
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * </p>
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param newValue
- * the new value to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
-
- public void updateVariable(String paintableId, String variableName,
- int newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, newValue, immediate);
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * </p>
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param newValue
- * the new value to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
-
- public void updateVariable(String paintableId, String variableName,
- long newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, newValue, immediate);
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * </p>
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param newValue
- * the new value to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
-
- public void updateVariable(String paintableId, String variableName,
- float newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, newValue, immediate);
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * </p>
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param newValue
- * the new value to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
-
- public void updateVariable(String paintableId, String variableName,
- double newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, newValue, immediate);
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * </p>
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param newValue
- * the new value to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
-
- public void updateVariable(String paintableId, String variableName,
- boolean newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, newValue, immediate);
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * </p>
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param map
- * the new values to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
- public void updateVariable(String paintableId, String variableName,
- Map<String, Object> map, boolean immediate) {
- addVariableToQueue(paintableId, variableName, map, immediate);
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * <p>
- * A null array is sent as an empty array.
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param values
- * the new value to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
- public void updateVariable(String paintableId, String variableName,
- String[] values, boolean immediate) {
- addVariableToQueue(paintableId, variableName, values, immediate);
- }
-
- /**
- * Sends a new value for the given paintables given variable to the server.
- * <p>
- * The update is actually queued to be sent at a suitable time. If immediate
- * is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * <p>
- * A null array is sent as an empty array.
- *
- * @param paintableId
- * the id of the paintable that owns the variable
- * @param variableName
- * the name of the variable
- * @param values
- * the new value to be sent
- * @param immediate
- * true if the update is to be sent as soon as possible
- */
- public void updateVariable(String paintableId, String variableName,
- Object[] values, boolean immediate) {
- addVariableToQueue(paintableId, variableName, values, immediate);
- }
-
- /**
- * Does absolutely nothing. Replaced by {@link LayoutManager}.
- *
- * @param container
- * @deprecated As of 7.0, serves no purpose
- */
- @Deprecated
- public void runDescendentsLayout(HasWidgets container) {
- }
-
- /**
- * This will cause re-layouting of all components. Mainly used for
- * development. Published to JavaScript.
- */
- public void forceLayout() {
- Duration duration = new Duration();
-
- layoutManager.forceLayout();
-
- getLogger().info("forceLayout in " + duration.elapsedMillis() + " ms");
- }
-
- /**
- * Returns false
- *
- * @param paintable
- * @return false, always
- * @deprecated As of 7.0, serves no purpose
- */
- @Deprecated
- private boolean handleComponentRelativeSize(ComponentConnector paintable) {
- return false;
- }
-
- /**
- * Returns false
- *
- * @param paintable
- * @return false, always
- * @deprecated As of 7.0, serves no purpose
- */
- @Deprecated
- public boolean handleComponentRelativeSize(Widget widget) {
- return handleComponentRelativeSize(connectorMap.getConnector(widget));
-
- }
-
- @Deprecated
- public ComponentConnector getPaintable(UIDL uidl) {
- // Non-component connectors shouldn't be painted from legacy connectors
- return (ComponentConnector) getConnector(uidl.getId(),
- Integer.parseInt(uidl.getTag()));
- }
-
- /**
- * Get either an existing ComponentConnector or create a new
- * ComponentConnector with the given type and id.
- *
- * If a ComponentConnector with the given id already exists, returns it.
- * Otherwise creates and registers a new ComponentConnector of the given
- * type.
- *
- * @param connectorId
- * Id of the paintable
- * @param connectorType
- * Type of the connector, as passed from the server side
- *
- * @return Either an existing ComponentConnector or a new ComponentConnector
- * of the given type
- */
- public ServerConnector getConnector(String connectorId, int connectorType) {
- if (!connectorMap.hasConnector(connectorId)) {
- return createAndRegisterConnector(connectorId, connectorType);
- }
- return connectorMap.getConnector(connectorId);
- }
-
- /**
- * Creates a new ServerConnector with the given type and id.
- *
- * Creates and registers a new ServerConnector of the given type. Should
- * never be called with the connector id of an existing connector.
- *
- * @param connectorId
- * Id of the new connector
- * @param connectorType
- * Type of the connector, as passed from the server side
- *
- * @return A new ServerConnector of the given type
- */
- private ServerConnector createAndRegisterConnector(String connectorId,
- int connectorType) {
- Profiler.enter("ApplicationConnection.createAndRegisterConnector");
-
- // Create and register a new connector with the given type
- ServerConnector p = widgetSet.createConnector(connectorType,
- configuration);
- connectorMap.registerConnector(connectorId, p);
- p.doInit(connectorId, this);
-
- Profiler.leave("ApplicationConnection.createAndRegisterConnector");
- return p;
- }
-
- /**
- * Gets a resource that has been pre-loaded via UIDL, such as custom
- * layouts.
- *
- * @param name
- * identifier of the resource to get
- * @return the resource
- */
- public String getResource(String name) {
- return resourcesMap.get(name);
- }
-
- /**
- * Sets a resource that has been pre-loaded via UIDL, such as custom
- * layouts.
- *
- * @param name
- * identifier of the resource to Set
- * @param resource
- * the resource
- */
- public void setResource(String name, String resource) {
- resourcesMap.put(name, resource);
- }
-
- /**
- * Singleton method to get instance of app's context menu.
- *
- * @return VContextMenu object
- */
- public VContextMenu getContextMenu() {
- if (contextMenu == null) {
- contextMenu = new VContextMenu();
- contextMenu.setOwner(uIConnector.getWidget());
- DOM.setElementProperty(contextMenu.getElement(), "id",
- "PID_VAADIN_CM");
- }
- return contextMenu;
- }
-
- /**
- * Gets an {@link Icon} instance corresponding to a URI.
- *
- * @since 7.2
- * @param uri
- * @return Icon object
- */
- public Icon getIcon(String uri) {
- Icon icon;
- if (uri == null) {
- return null;
- } else if (FontIcon.isFontIconUri(uri)) {
- icon = GWT.create(FontIcon.class);
- } else {
- icon = GWT.create(ImageIcon.class);
- }
- icon.setUri(translateVaadinUri(uri));
- return icon;
- }
-
- /**
- * Translates custom protocols in UIDL URI's to be recognizable by browser.
- * All uri's from UIDL should be routed via this method before giving them
- * to browser due URI's in UIDL may contain custom protocols like theme://.
- *
- * @param uidlUri
- * Vaadin URI from uidl
- * @return translated URI ready for browser
- */
- public String translateVaadinUri(String uidlUri) {
- return uriResolver.resolveVaadinUri(uidlUri);
- }
-
- /**
- * Gets the URI for the current theme. Can be used to reference theme
- * resources.
- *
- * @return URI to the current theme
- */
- public String getThemeUri() {
- return configuration.getVaadinDirUrl() + "themes/"
- + getUIConnector().getActiveTheme();
- }
-
- /* Extended title handling */
-
- private final VTooltip tooltip;
-
- private ConnectorMap connectorMap = GWT.create(ConnectorMap.class);
-
- /**
- * Use to notify that the given component's caption has changed; layouts may
- * have to be recalculated.
- *
- * @param component
- * the Paintable whose caption has changed
- * @deprecated As of 7.0.2, has not had any effect for a long time
- */
- @Deprecated
- public void captionSizeUpdated(Widget widget) {
- // This doesn't do anything, it's just kept here for compatibility
- }
-
- /**
- * Gets the main view
- *
- * @return the main view
- */
- public UIConnector getUIConnector() {
- return uIConnector;
- }
-
- /**
- * Gets the {@link ApplicationConfiguration} for the current application.
- *
- * @see ApplicationConfiguration
- * @return the configuration for this application
- */
- public ApplicationConfiguration getConfiguration() {
- return configuration;
- }
-
- /**
- * Checks if there is a registered server side listener for the event. The
- * list of events which has server side listeners is updated automatically
- * before the component is updated so the value is correct if called from
- * updatedFromUIDL.
- *
- * @param paintable
- * The connector to register event listeners for
- * @param eventIdentifier
- * The identifier for the event
- * @return true if at least one listener has been registered on server side
- * for the event identified by eventIdentifier.
- * @deprecated As of 7.0. Use
- * {@link AbstractComponentState#hasEventListener(String)}
- * instead
- */
- @Deprecated
- public boolean hasEventListeners(ComponentConnector paintable,
- String eventIdentifier) {
- return paintable.hasEventListener(eventIdentifier);
- }
-
- /**
- * Adds the get parameters to the uri and returns the new uri that contains
- * the parameters.
- *
- * @param uri
- * The uri to which the parameters should be added.
- * @param extraParams
- * One or more parameters in the format "a=b" or "c=d&e=f". An
- * empty string is allowed but will not modify the url.
- * @return The modified URI with the get parameters in extraParams added.
- * @deprecated Use {@link SharedUtil#addGetParameters(String,String)}
- * instead
- */
- @Deprecated
- public static String addGetParameters(String uri, String extraParams) {
- return SharedUtil.addGetParameters(uri, extraParams);
- }
-
- ConnectorMap getConnectorMap() {
- return connectorMap;
- }
-
- /**
- * @deprecated As of 7.0. No longer serves any purpose.
- */
- @Deprecated
- public void unregisterPaintable(ServerConnector p) {
- getLogger().info(
- "unregisterPaintable (unnecessarily) called for "
- + Util.getConnectorString(p));
- }
-
- /**
- * Get VTooltip instance related to application connection
- *
- * @return VTooltip instance
- */
- public VTooltip getVTooltip() {
- return tooltip;
- }
-
- /**
- * Method provided for backwards compatibility. Duties previously done by
- * this method is now handled by the state change event handler in
- * AbstractComponentConnector. The only function this method has is to
- * return true if the UIDL is a "cached" update.
- *
- * @param component
- * @param uidl
- * @param manageCaption
- * @deprecated As of 7.0, no longer serves any purpose
- * @return
- */
- @Deprecated
- public boolean updateComponent(Widget component, UIDL uidl,
- boolean manageCaption) {
- ComponentConnector connector = getConnectorMap()
- .getConnector(component);
- if (!AbstractComponentConnector.isRealUpdate(uidl)) {
- return true;
- }
-
- if (!manageCaption) {
- getLogger()
- .warning(
- Util.getConnectorString(connector)
- + " called updateComponent with manageCaption=false. The parameter was ignored - override delegateCaption() to return false instead. It is however not recommended to use caption this way at all.");
- }
- return false;
- }
-
- /**
- * @deprecated As of 7.0. Use
- * {@link AbstractComponentConnector#hasEventListener(String)}
- * instead
- */
- @Deprecated
- public boolean hasEventListeners(Widget widget, String eventIdentifier) {
- ComponentConnector connector = getConnectorMap().getConnector(widget);
- if (connector == null) {
- /*
- * No connector will exist in cases where Vaadin widgets have been
- * re-used without implementing server<->client communication.
- */
- return false;
- }
-
- return hasEventListeners(getConnectorMap().getConnector(widget),
- eventIdentifier);
- }
-
- LayoutManager getLayoutManager() {
- return layoutManager;
- }
-
- /**
- * Schedules a heartbeat request to occur after the configured heartbeat
- * interval elapses if the interval is a positive number. Otherwise, does
- * nothing.
- *
- * @deprecated as of 7.2, use {@link Heartbeat#schedule()} instead
- */
- @Deprecated
- protected void scheduleHeartbeat() {
- heartbeat.schedule();
- }
-
- /**
- * Sends a heartbeat request to the server.
- * <p>
- * Heartbeat requests are used to inform the server that the client-side is
- * still alive. If the client page is closed or the connection lost, the
- * server will eventually close the inactive UI.
- *
- * @deprecated as of 7.2, use {@link Heartbeat#send()} instead
- */
- @Deprecated
- protected void sendHeartbeat() {
- heartbeat.send();
- }
-
- public void handleCommunicationError(String details, int statusCode) {
- boolean handled = false;
- if (communicationErrorDelegate != null) {
- handled = communicationErrorDelegate.onError(details, statusCode);
-
- }
-
- if (!handled) {
- showCommunicationError(details, statusCode);
- }
-
- }
-
- /**
- * Sets the delegate that is called whenever a communication error occurrs.
- *
- * @param delegate
- * the delegate.
- */
- public void setCommunicationErrorDelegate(CommunicationErrorHandler delegate) {
- communicationErrorDelegate = delegate;
- }
-
- public void setApplicationRunning(boolean applicationRunning) {
- if (getState() == State.TERMINATED) {
- if (applicationRunning) {
- getLogger()
- .severe("Tried to restart a terminated application. This is not supported");
- } else {
- getLogger()
- .warning(
- "Tried to stop a terminated application. This should not be done");
- }
- return;
- } else if (getState() == State.INITIALIZING) {
- if (applicationRunning) {
- state = State.RUNNING;
- } else {
- getLogger()
- .warning(
- "Tried to stop the application before it has started. This should not be done");
- }
- } else if (getState() == State.RUNNING) {
- if (!applicationRunning) {
- state = State.TERMINATED;
- eventBus.fireEvent(new ApplicationStoppedEvent());
- } else {
- getLogger()
- .warning(
- "Tried to start an already running application. This should not be done");
- }
- }
- }
-
- /**
- * Checks if the application is in the {@link State#RUNNING} state.
- *
- * @since
- * @return true if the application is in the running state, false otherwise
- */
- public boolean isApplicationRunning() {
- return state == State.RUNNING;
- }
-
- public <H extends EventHandler> HandlerRegistration addHandler(
- GwtEvent.Type<H> type, H handler) {
- return eventBus.addHandler(type, handler);
- }
-
- @Override
- public void fireEvent(GwtEvent<?> event) {
- eventBus.fireEvent(event);
- }
-
- /**
- * Calls {@link ComponentConnector#flush()} on the active connector. Does
- * nothing if there is no active (focused) connector.
- */
- public void flushActiveConnector() {
- ComponentConnector activeConnector = getActiveConnector();
- if (activeConnector == null) {
- return;
- }
- activeConnector.flush();
- }
-
- /**
- * Gets the active connector for focused element in browser.
- *
- * @return Connector for focused element or null.
- */
- private ComponentConnector getActiveConnector() {
- Element focusedElement = WidgetUtil.getFocusedElement();
- if (focusedElement == null) {
- return null;
- }
- return Util.getConnectorForElement(this, getUIConnector().getWidget(),
- focusedElement);
- }
-
- private static Logger getLogger() {
- return Logger.getLogger(ApplicationConnection.class.getName());
- }
-
- /**
- * Returns the hearbeat instance.
- */
- public Heartbeat getHeartbeat() {
- return heartbeat;
- }
-
- /**
- * Returns the state of this application. An application state goes from
- * "initializing" to "running" to "stopped". There is no way for an
- * application to go back to a previous state, i.e. a stopped application
- * can never be re-started
- *
- * @since
- * @return the current state of this application
- */
- public State getState() {
- return state;
- }
-
- /**
- * Gets the server RPC queue for this application
- *
- * @return the server RPC queue
- */
- public ServerRpcQueue getServerRpcQueue() {
- return serverRpcQueue;
- }
-
- /**
- * Gets the communication error handler for this application
- *
- * @return the server RPC queue
- */
- public CommunicationProblemHandler getCommunicationProblemHandler() {
- return communicationProblemHandler;
- }
-
- /**
- * Gets the server message handler for this application
- *
- * @return the server message handler
- */
- public ServerMessageHandler getServerMessageHandler() {
- return serverMessageHandler;
- }
-
- /**
- * Gets the server rpc manager for this application
- *
- * @return the server rpc manager
- */
- public RpcManager getRpcManager() {
- return rpcManager;
- }
-
- /**
- * Gets the server communication handler for this application
- *
- * @return the server communication handler
- */
- public ServerCommunicationHandler getServerCommunicationHandler() {
- return serverCommunicationHandler;
- }
-
- /**
- * @return the widget set
- */
- public WidgetSet getWidgetSet() {
- return widgetSet;
- }
-
- public int getLastSeenServerSyncId() {
- return getServerMessageHandler().getLastSeenServerSyncId();
- }
-
- }
|