eu.livotov.tpt
Class TPTApplication

java.lang.Object
  extended by com.vaadin.Application
      extended by eu.livotov.tpt.TPTApplication
All Implemented Interfaces:
com.vaadin.service.ApplicationContext.TransactionListener, com.vaadin.terminal.Terminal.ErrorListener, com.vaadin.terminal.URIHandler, java.io.Serializable

public abstract class TPTApplication
extends com.vaadin.Application
implements com.vaadin.service.ApplicationContext.TransactionListener

This is the abstract class to be used instead of regular Vaadin Application in order to get some extended features, that TPT provides. Use this class absolutely the same way as you use plain Application class, the only difference is that instead of init() method you need to use applicationInit(). However, you may still init(), just do not forget to put super.init() at the beginning (as the first line of your overridden method body).

See Also:
Serialized Form

Nested Class Summary
private  class TPTApplication.TPTRunnable
           
 
Nested classes/interfaces inherited from class com.vaadin.Application
com.vaadin.Application.ApplicationError, com.vaadin.Application.CustomizedSystemMessages, com.vaadin.Application.SystemMessages, com.vaadin.Application.UserChangeEvent, com.vaadin.Application.UserChangeListener, com.vaadin.Application.WindowAttachEvent, com.vaadin.Application.WindowAttachListener, com.vaadin.Application.WindowDetachEvent, com.vaadin.Application.WindowDetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.URIHandler
com.vaadin.terminal.URIHandler.ErrorEvent
 
Field Summary
(package private) static java.lang.ThreadLocal<TPTApplication> currentApplication
           
private static java.util.concurrent.atomic.AtomicBoolean firstInstanceCreated
           
private  Dictionary internationalizationDictionary
           
 
Constructor Summary
TPTApplication()
          Default application constructor.
 
Method Summary
abstract  void applicationInit()
          This method must be implemented by a final application, exactly the same way as init() method had to be implemented in a regular Vaadin Application.
private  void cleanupPreviousResources()
          This method cleanups resources from previous app instance.
 void close()
          Overrides ITMill Toolkit close() method to add some resources cleanup (in the future), related to TPT.
abstract  void firstApplicationStartup()
          Another application initialization callback.
static TPTApplication getCurrentApplication()
          Provides an instance to the current application.
 void init()
          Standard ITMill Toolkit abstract init() method is implemented here for automatic registration of our application as a TransactionListener.
private  void initializeInternationalizationFramework()
          Performs initialization of i18n part of TPT.
 java.lang.Thread invokeLater(java.lang.Runnable task)
          Creates and starts a new thread.
private  void loadInternationalizationFiles()
          Loads property files with translations from the theme-name/i18n folder (if exists)
 void setTheme(java.lang.String themeName)
          This method is overridden as we want to reload theme-specific internationalization translation files from the theme's i18n folder once theme is changed.
 void transactionEnd(com.vaadin.Application application, java.lang.Object o)
          Once thread finishes, removes the application instance reference from it.
 void transactionStart(com.vaadin.Application application, java.lang.Object o)
          Adds a reference to the application instance into the current thread.
 
Methods inherited from class com.vaadin.Application
addListener, addListener, addListener, addResource, addWindow, getContext, getErrorHandler, getLocale, getLogoutURL, getMainWindow, getProperty, getPropertyNames, getRelativeLocation, getSystemMessages, getTheme, getURL, getUser, getVersion, getWindow, getWindows, handleURI, isRunning, removeListener, removeListener, removeListener, removeResource, removeWindow, setErrorHandler, setLocale, setLogoutURL, setMainWindow, setUser, start, terminalError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentApplication

static java.lang.ThreadLocal<TPTApplication> currentApplication

internationalizationDictionary

private Dictionary internationalizationDictionary

firstInstanceCreated

private static java.util.concurrent.atomic.AtomicBoolean firstInstanceCreated
Constructor Detail

TPTApplication

public TPTApplication()
Default application constructor. Here we additionaly put the current instance into the ThreadLocal registry in case somebody will want to ask for the application istance before ITMill Toolkit will call init() method.

Method Detail

init

public void init()
Standard ITMill Toolkit abstract init() method is implemented here for automatic registration of our application as a TransactionListener. End-users have to use applicationInit() instead of init() in their applications. But nothing stops you from overriding init() in your application, just do not forget to call super.init() as the first statement in your override.

Specified by:
init in class com.vaadin.Application

initializeInternationalizationFramework

private void initializeInternationalizationFramework()
Performs initialization of i18n part of TPT. It creates a dictionary, scans and loads all property files from theme-name/i18n folder.


loadInternationalizationFiles

private void loadInternationalizationFiles()
Loads property files with translations from the theme-name/i18n folder (if exists)


setTheme

public void setTheme(java.lang.String themeName)
This method is overridden as we want to reload theme-specific internationalization translation files from the theme's i18n folder once theme is changed.

Overrides:
setTheme in class com.vaadin.Application
Parameters:
themeName - new theme name

applicationInit

public abstract void applicationInit()
This method must be implemented by a final application, exactly the same way as init() method had to be implemented in a regular Vaadin Application. As init() method is used for TPT specific initialization, please use applicationInit() instead. In case you want to use exactly init() one, please override it but do not forget to add super.init() as the first line of the overridden method.


firstApplicationStartup

public abstract void firstApplicationStartup()

Another application initialization callback. It is called after init() / applicationInit() but only once per application class - e.g. this method is called when the first application instance is started. All subsequent instances of the same application (until the web contaner restart) will not cause this method to be called. You can place any shared or static resources initialization here, that are common to all application sessions and should be initialized only once.

Please note, that if you're running your application on a cluster, this method will be called in every cluster instance, so you have to care on this yourself.


close

public void close()
Overrides ITMill Toolkit close() method to add some resources cleanup (in the future), related to TPT. Please feel free to override this method in your application as well, however, do not forget to call super.close() in your override.

Overrides:
close in class com.vaadin.Application

transactionStart

public void transactionStart(com.vaadin.Application application,
                             java.lang.Object o)
Adds a reference to the application instance into the current thread. This allows us to get an application instance by calling ToolkitPlusApplication.getCurrentApplication() in any place of your application code.

Specified by:
transactionStart in interface com.vaadin.service.ApplicationContext.TransactionListener
Parameters:
application -
o -

transactionEnd

public void transactionEnd(com.vaadin.Application application,
                           java.lang.Object o)
Once thread finishes, removes the application instance reference from it.

Specified by:
transactionEnd in interface com.vaadin.service.ApplicationContext.TransactionListener
Parameters:
application -
o -

invokeLater

public java.lang.Thread invokeLater(java.lang.Runnable task)
Creates and starts a new thread. This method must be used instead of new Thread(...) construction when starting server threads if you wish to access toolkit UI data, i18n and be able to get the current application instance.

Parameters:
task - Runnable task to execute in a separate thread
Returns:
instance of the created and started thread.

getCurrentApplication

public static TPTApplication getCurrentApplication()
Provides an instance to the current application. You may use this method to get an application instance from any toolkit piece of your code. However, note, that if you'll spawn your own background server thread from your application and this thread will call getCurrentApplication() method, it will return NULL, because thread context knows nothing about toolkit. For such cases, consider explicitly passing application reference to your thread object as a parameter or start threads by calling an utility "invokeLater" method of the TPTApplication instance.

Returns:
Instance of currrent application

cleanupPreviousResources

private void cleanupPreviousResources()
This method cleanups resources from previous app instance. When Vaadin app is created using CDI injection, http session does not die after app.close() which results the same application instance to be used for the next application.