org.tentackle.appworx
Class Application

java.lang.Object
  extended by org.tentackle.appworx.AbstractApplication
      extended by org.tentackle.appworx.Application

public abstract class Application
extends AbstractApplication

Abstract class to handle the application's lifecycle. Tentackle applications should extend this class and invoke start(java.lang.String[]). To shutdown gracefully, application should invokd stop(). At minimum, the method doCreateWindow() must be implemented.

The subclass just needs to provide a main-method, for example:

 public static void main(String args[]) {
   new MyApplication().start(args);
 }
 

Author:
harald

Constructor Summary
Application(String name, Icon logo)
          Creates an application.
 
Method Summary
 void changeLookAndFeel(String name)
          Changes the look and feel.
 JMenu createLookAndFeelMenu()
          Creates a menu to select the look and feel.
 ModificationThread createModificationThread()
          Creates the modification thread ready for being started.
protected  void doConfigureApplication()
          Do anything what's necessary after the connection has been established.
protected abstract  FormWindow doCreateWindow()
          Creates the top level window.
protected  void doFinishStartup()
          Finishes the startup.
Invoked after all has been displayed.
protected  ContextDb doLogin()
          Connects to the database backend (or application server).
protected  void doShowWindow()
          Shows the window.
protected  void doStop(int exitValue)
          Terminates the application gracefully.
 CommandLine getCommandLine()
          Gets the command line.
 Icon getLogo()
          Gets the logo.
 String getName()
          Gets the application name.
 FormWindow getWindow()
          Gets the application's window.
protected  void installLookAndFeels()
          Installs the available look and feels.
protected  void installPreferences()
          Installs the preferences backend.
The default implementation installs the DbPreferencesFactory unless "--nodbprefs" is given.
protected  void installSecurityManager()
          installs the tentackle security manager
 void setLookAndFeel(String name)
          Sets the look and feel.
 void showEditDialog(Class<? extends AppDbObject> clazz)
          Brings up a non-modal edit dialog for a given class.
 AppDbObject showEditDialog(Component comp, AppDbObject object, boolean modal)
          Brings up an edit dialog for a given object.
 AppDbObject showEditDialog(Component comp, Class<? extends AppDbObject> clazz, boolean modal)
          Brings up an edit dialog for a given class.
 void showLoginStatus(String msg)
          Displays a message during login.
 void showSearchDialog(Class<? extends AppDbObject> clazz)
          Brings up a search dialog for a given class.
 void showSearchDialog(FormWindow w, Class<? extends AppDbObject> clazz)
          Brings up a search dialog for a given class.
 void start(String[] args)
          Launches the application.
 void stop()
          Gracefully terminates the application.
 String toString()
          Gets the application's name.
 
Methods inherited from class org.tentackle.appworx.AbstractApplication
createContextDb, createDb, createUserInfo, detectEE, detectJNLP, doInitialize, getContextDb, getDb, getProperties, getProperty, getRunningApplication, getUser, getUser, getUserInfo, isDeployedByEE, isDeployedByJNLP, register, securityRulesChanged, setContextDb, setProperties, setUserInfo, unregister, updateUserId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Application

public Application(String name,
                   Icon logo)
Creates an application.

Parameters:
name - the application's name
logo - the application's logo icon
Method Detail

start

public void start(String[] args)
Launches the application.

Parameters:
args - the arguments (usually from commandline)

stop

public void stop()
Gracefully terminates the application. Usually invoked from an exit-Button or when window is closed.


toString

public String toString()
Gets the application's name.

Overrides:
toString in class Object
Returns:
the name

getCommandLine

public CommandLine getCommandLine()
Gets the command line.

Returns:
the command line

getName

public String getName()
Gets the application name.

Returns:
the application name

getLogo

public Icon getLogo()
Gets the logo.

Returns:
the logo

getWindow

public FormWindow getWindow()
Gets the application's window.

Returns:
the window, null if not yet defined.

setLookAndFeel

public void setLookAndFeel(String name)
Sets the look and feel.

Parameters:
name - the name of the look and feel

changeLookAndFeel

public void changeLookAndFeel(String name)
Changes the look and feel. This method should be invoked if the user changed the look and feel intentionally. The default implementation just invokes setLookAndFeel, but applications can override it to save the setting, e.g. in the preferences.

Parameters:
name - the name of the l&f

createLookAndFeelMenu

public JMenu createLookAndFeelMenu()
Creates a menu to select the look and feel. The current implementation returns only the tentackle look and feels.

Returns:
a JMenu with all available look and feels

showLoginStatus

public void showLoginStatus(String msg)
Displays a message during login. If the login dialog is visible, the message will be shown there. Otherwise it will simply print printed to the console.

Parameters:
msg - the status message

showEditDialog

public AppDbObject showEditDialog(Component comp,
                                  AppDbObject object,
                                  boolean modal)
                           throws ApplicationException
Brings up an edit dialog for a given object.

Parameters:
comp - some component of the owner window, null if none
object - the object to create the dialog for
modal - true if modal, else non-modal
Returns:
the edited object if modal, else null
Throws:
ApplicationException

showEditDialog

public AppDbObject showEditDialog(Component comp,
                                  Class<? extends AppDbObject> clazz,
                                  boolean modal)
                           throws ApplicationException
Brings up an edit dialog for a given class.

Parameters:
comp - some component of the owner window, null if none
clazz - is the object's class
modal - true if modal, else non-modal
Returns:
the edited object if modal, else null
Throws:
ApplicationException

showEditDialog

public void showEditDialog(Class<? extends AppDbObject> clazz)
Brings up a non-modal edit dialog for a given class. The owner window is the application's frame. This is the preferred method to be used in edit menus of application frames.

Parameters:
clazz - is the object's class

showSearchDialog

public void showSearchDialog(FormWindow w,
                             Class<? extends AppDbObject> clazz)
Brings up a search dialog for a given class. Searchdialogs have no owner but use the owner as the related window.

Parameters:
w - is the related window, null if none
clazz - is the object's class

showSearchDialog

public void showSearchDialog(Class<? extends AppDbObject> clazz)
Brings up a search dialog for a given class. The owner is the application frame. This is the preferred method to be used in search menus of application frames.

Parameters:
clazz - is the object's class

createModificationThread

public ModificationThread createModificationThread()
Creates the modification thread ready for being started. The default implementation creates the modthread with a polling interval of 2 seconds and which runs on a cloned db-connection.

Overrides:
createModificationThread in class AbstractApplication
Returns:
the created modification thread

installPreferences

protected void installPreferences()
Installs the preferences backend.
The default implementation installs the DbPreferencesFactory unless "--nodbprefs" is given. The option "--sysprefs" forces usage of system preferences only. "--roprefs" sets the preferences to readonly.

Overrides:
installPreferences in class AbstractApplication

installLookAndFeels

protected void installLookAndFeels()
Installs the available look and feels. The default implementation installs all Tentackle Plafs.


installSecurityManager

protected void installSecurityManager()
installs the tentackle security manager

Overrides:
installSecurityManager in class AbstractApplication

doLogin

protected ContextDb doLogin()
                     throws ApplicationException
Connects to the database backend (or application server).

Notice: if the application is started via JNLP (Java WebStart) and the commandline option "--db=" is given, it is interpreted as a URL to the db-properties file relative to the JNLP codebase. If it starts with "&lt;protocol&gt;://" it is taken as an absolute URL.
Example:

 --db=http://www.tentackle.org/Invoicer/Db.properties
 
 is the same as:
 
 --db=Db.properties
 
 if the codebase is http://www.tentackle.org/Invoicer.
 

Returns:
the connected context db, null if login aborted or authentication failed
Throws:
ApplicationException

doConfigureApplication

protected void doConfigureApplication()
                               throws ApplicationException
Do anything what's necessary after the connection has been established. Setup preferences, etc... The default creates the modification thread (but does not start it), installs the Preferences, tentackle's SecurityManager and the look and feels.

Overrides:
doConfigureApplication in class AbstractApplication
Throws:
ApplicationException

doCreateWindow

protected abstract FormWindow doCreateWindow()
                                      throws ApplicationException
Creates the top level window. The method must not setVisible(true)!

Returns:
the toplevel window, ready for showing
Throws:
ApplicationException

doShowWindow

protected void doShowWindow()
                     throws ApplicationException
Shows the window. The default implementation invokes setVisible(true). If the window is a FormContainer, setFormValue() and saveValues() will be invoked as well.

Throws:
ApplicationException

doFinishStartup

protected void doFinishStartup()
                        throws ApplicationException
Finishes the startup.
Invoked after all has been displayed. The default implementation starts the modification thread, unless "--nomodthread" given.

Overrides:
doFinishStartup in class AbstractApplication
Throws:
ApplicationException

doStop

protected void doStop(int exitValue)
Terminates the application gracefully. (this is the only do.. method that does not throw ApplicationException)

Parameters:
exitValue - the doStop value for System.exit()


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de