com.maryanovsky.gwtutils.client
Class Application

java.lang.Object
  extended by com.maryanovsky.gwtutils.client.Application
All Implemented Interfaces:
EntryPoint

public abstract class Application
extends Object
implements EntryPoint

A class which handles much of the heavy lifting of starting up an application. The class handles the following:

Author:
Maryanovsky Alexander

Nested Class Summary
static class Application.RequestMakerResponseHandlerPair
           
 
Field Summary
protected static String SETTINGS_URL
          The URL of the settings file.
protected  ResultCallback<String> settingsResponseCallback
          The ResultCallback for the settings request.
protected static Map<String,String> URL_ARGS
          The arguments passed to us via the URL.
 
Constructor Summary
Application()
           
 
Method Summary
protected  RequestMaker<String> createSettingsRequestMaker()
          Creates the request maker for the settings file.
protected  List<Application.RequestMakerResponseHandlerPair> getApplicationStartRequests()
          Returns the list of requests that need to be made for the application to start and their handlers.
protected  GWT.UncaughtExceptionHandler getUncaughtExceptionHandler()
          Returns the uncaught exception handler for the application.
protected  boolean isWindowScrollingEnabled()
          Returns whether window scrolling should be enabled for the application.
protected  void onErrorMakingRequest(String url, String errorMessage)
          Invoked when making one of the requests required to start the application fails (that is, RequestBuilder.sendRequest(String, RequestCallback) threw a RequestException).
protected  void onErrorRetrievingSettings(String settingsUrl, String errorMessage)
          This method is called when an error occurs while retrieving the application settings.
protected  void onInvalidSettings(String errorMessage)
          Invoked when the settings are invalid.
 void onModuleLoad()
          The entry point method.
protected abstract  void onSettingsReceived(String settingsText)
          Invoked when the settings are received.
protected abstract  void startApplication()
          Starts the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_ARGS

protected static final Map<String,String> URL_ARGS
The arguments passed to us via the URL.


SETTINGS_URL

protected static final String SETTINGS_URL
The URL of the settings file.


settingsResponseCallback

protected final ResultCallback<String> settingsResponseCallback
The ResultCallback for the settings request.

Constructor Detail

Application

public Application()
Method Detail

onModuleLoad

public void onModuleLoad()
The entry point method.

Specified by:
onModuleLoad in interface EntryPoint

getApplicationStartRequests

protected List<Application.RequestMakerResponseHandlerPair> getApplicationStartRequests()
Returns the list of requests that need to be made for the application to start and their handlers. The default implementation returns a list with a single item - the pair (createSettingsRequestMaker(), settingsResponseCallback). If your application needs to retrieve more information in order to start, you should override this method and return additional request builders (and corresponding callbacks).


createSettingsRequestMaker

protected RequestMaker<String> createSettingsRequestMaker()
Creates the request maker for the settings file.


isWindowScrollingEnabled

protected boolean isWindowScrollingEnabled()
Returns whether window scrolling should be enabled for the application. Note that this method is called from onModuleLoad(). The default implementation returns false.


getUncaughtExceptionHandler

protected GWT.UncaughtExceptionHandler getUncaughtExceptionHandler()
Returns the uncaught exception handler for the application. Note that this method is called from onModuleLoad(). The default implementation returns an exception handler which shows an (unlocalized) alert describing the exception that occurred.


onErrorMakingRequest

protected void onErrorMakingRequest(String url,
                                    String errorMessage)
Invoked when making one of the requests required to start the application fails (that is, RequestBuilder.sendRequest(String, RequestCallback) threw a RequestException). The default implementation displays an (unlocalized) alert describing the error that occurred.


onErrorRetrievingSettings

protected void onErrorRetrievingSettings(String settingsUrl,
                                         String errorMessage)
This method is called when an error occurs while retrieving the application settings. The default implementation shows an (unlocalized) alert describing the error.


onSettingsReceived

protected abstract void onSettingsReceived(String settingsText)
                                    throws ParseException
Invoked when the settings are received. The method is meant to parse the settings, and store them in a field until startApplication() is invoked (where they will be used).

Throws:
ParseException

onInvalidSettings

protected void onInvalidSettings(String errorMessage)
Invoked when the settings are invalid. The default implementation shows an (unlocalized) alert describing the error.


startApplication

protected abstract void startApplication()
Starts the application. This method is invoked when all the requests required to start the application have finished. Note that this happens even if some of them failed - it is up to you, when overriding this method, to check whether you have all the information you need.