Class DesktopApplication<C extends FxController>

Type Parameters:
C - the main controller type
All Implemented Interfaces:
Application, DomainContextProvider, ClassMappedListener, SessionProvider
Direct Known Subclasses:
UpdatableDesktopApplication

public abstract class DesktopApplication<C extends FxController> extends AbstractClientApplication implements ClassMappedListener
Tentackle JavaFX desktop application.
Launches the FxApplication (by default the LoginApplication), performs the login in a background service while showing the progress in the login view, and finally opens the main window with the main controller.

The modification tracker runs with its own session, a clone of the login session grouped with it.

Author:
harald
  • Constructor Details

    • DesktopApplication

      public DesktopApplication(String name, String version)
      Creates an FX desktop application.
      Parameters:
      name - the application name, null for default name
      version - the application version, null for the default version
  • Method Details

    • isInteractive

      public boolean isInteractive()
      Description copied from class: AbstractApplication
      Returns whether the running application is interactive.
      Specified by:
      isInteractive in interface Application
      Overrides:
      isInteractive in class AbstractApplication
      Returns:
      true if interaction with user, false if server, daemon or whatever
    • getMainControllerClass

      public abstract Class<? extends C> getMainControllerClass()
      Gets the main controller to be displayed initially.
      Maintains the main scene of the application.
      Returns:
      the main controller class
    • configureMainStage

      public void configureMainStage(javafx.stage.Stage mainStage)
      Configures and sets the main stage.

      If overridden, make sure to invoke super.configureMainStage!

      Parameters:
      mainStage - the main stage
    • getMainStage

      public javafx.stage.Stage getMainStage()
      Gets the main stage.
      Returns:
      the stage
    • setMainController

      public void setMainController(C mainController)
      Sets the main controller instance.
      Parameters:
      mainController - the main controller
    • getMainController

      public C getMainController()
      Gets the main controller.
      Returns:
      the main controller
    • isAutoLogin

      public boolean isAutoLogin()
      Returns the autologin flag.
      Returns:
      true if the user is logged in w/o being asked for username/password, default is false
      See Also:
    • createLoginFailedHandler

      public LoginFailedHandler createLoginFailedHandler(javafx.scene.Parent view, SessionInfo sessionInfo)
      Creates the login failed handler.
      Parameters:
      view - the view
      sessionInfo - the session info
      Returns:
      the handler
    • createSessionInfo

      public SessionInfo createSessionInfo(String username, char[] password, String sessionPropertiesBaseName)
      Description copied from class: AbstractApplication
      Creates the sessionInfo.
      Presets the attributes like locale, timezone, vm-, os- and host-info.
      Overrides:
      createSessionInfo in class AbstractApplication
      Parameters:
      username - is the name of the user
      password - is the password, null if none
      sessionPropertiesBaseName - the resource bundle basename of the property file, null if default
      Returns:
      the sessionInfo
    • login

      public void login(javafx.scene.Parent view, SessionInfo sessionInfo)
      Performs the login and final startup of the application.

      The login runs in a background service. After a successful login, the application is configured, the main controller is loaded, and the main window is displayed. The login view is hidden when the main window is shown. Failed logins are handled by the LoginFailedHandler.

      Notice that this method is invoked from within the FX thread.

      Parameters:
      view - the view to hide if login succeeded and the application window is visible
      sessionInfo - the session info
    • getFxApplication

      public FxApplication getFxApplication()
      Gets the FX application instance.
      This is the instance of the class provided by getApplicationClass().
      The FX application usually provides a login view and is responsible for spawning the main view after successful login.
      Returns:
      the FX application
    • setFxApplication

      public void setFxApplication(FxApplication fxApplication)
      Sets the FX application instance.
      Parameters:
      fxApplication - the FX application
    • getApplicationClass

      public Class<? extends FxApplication> getApplicationClass()
      Gets the FX application class.
      Override to launch an application other than the LoginApplication.
      Returns:
      the FX application class
    • showApplicationStatus

      public void showApplicationStatus(String msg, double progress, long minMillis)
      Displays a message during login.
      Parameters:
      msg - the status message
      progress - the progress, 0 to disable, negative if infinite, 1.0 if done
      minMillis - minimum milliseconds the previous message must have been visible
    • showApplicationStatus

      public void showApplicationStatus(String msg, double progress)
      Displays a message during login.
      Makes sure that the message is shown at least 100ms.
      Parameters:
      msg - the status message
      progress - the progress, 0 to disable, negative if infinite, 1.0 if done
    • registerUncaughtExceptionHandler

      public void registerUncaughtExceptionHandler()
      Registers a handler for uncaught exceptions.
      Applies to all threads and the FX thread.
    • getUncaughtExceptionHandler

      public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
      Gets the exception handler.
      The default handler logs the exception and shows it in an error dialog.
      Returns:
      the handler
    • createDomainContext

      public DomainContext createDomainContext(Session session)
      Creates the domain context.
      The context is created via Pdo.createDomainContext(Session, boolean) with an immutable session, i.e., by the DomainContextFactory, which is the recommended way to provide an application-specific context. For remote sessions, the user's ID, class ID, and name are taken from the server's view of the session.

      Overridden to create a DomainContext with a thread-local session.

      In desktop client apps there are 2 threads using their own session:

      1. the FX thread
      2. the ModificationTracker thread
      By using the thread-local session, PDOs can be used from both threads without having to worry about the correct session.
      Overrides:
      createDomainContext in class AbstractApplication
      Parameters:
      session - the session, null if thread-local
      Returns:
      the domain context
    • applyProperties

      public void applyProperties(Properties properties)
      Description copied from class: AbstractApplication
      Applies the given properties.
      If the given properties are different from the application properties, they will be copied to the application properties.

      The default implementation first parses the properties for system properties and replaces any system properties according to StringHelper.evaluate(String, Function).
      System properties start with SYSTEM_ or ^ followed by the property name.

      Other well-known properties that can be set:

      scripting=... sets the default scripting language

      nosecurity disables the tentackle security manager

      locale=... sets the default locale.

      Specified by:
      applyProperties in interface Application
      Overrides:
      applyProperties in class AbstractApplication
      Parameters:
      properties - the properties, null if none
    • getThemePreferences

      public ThemeUtilities.ThemePreferences getThemePreferences()
      Gets the configured dark mode and theme preferences.
      They can be configured via command line or user preferences. If the dark mode is not configured, it is determined automatically according to the desktop settings.
      Returns:
      the theme preferences, with darkMode() null if automatic, TRUE if fixed dark mode, FALSE if fixed light mode
    • startup

      protected void startup()
      Description copied from class: AbstractApplication
      Invokes all steps to start up the application.
      Invoked from AbstractApplication.start(java.lang.String[]).
      Specified by:
      startup in class AbstractApplication
    • configurePreferences

      protected void configurePreferences()
      Description copied from class: AbstractApplication
      Configures the preferences.

      If the property "readonlyprefs" is set, any write attempt to the preferences will be silently ignored.
      The property "noprefsync" turns off preferences auto sync between jvms.
      The property "systemprefs" restricts to system preferences. Default is user and system prefs.

      Overrides:
      configurePreferences in class AbstractApplication
    • configureSecurityManager

      protected void configureSecurityManager()
      Description copied from class: AbstractApplication
      Configures the security manager.
      The default implementation enables the security manager, unless the property "nosecurity" is given.
      Overrides:
      configureSecurityManager in class AbstractApplication
    • configureModificationTracker

      protected void configureModificationTracker()
      Description copied from class: AbstractApplication
      Configures the modification tracker singleton.
      Overrides:
      configureModificationTracker in class AbstractApplication
    • finishStartup

      protected void finishStartup()
      Description copied from class: AbstractApplication
      Finishes the startup.
      The default implementation:
      1. activates the statistics, if the property "statistics" is given,
      2. preloads the caches (see AbstractApplication.preloadCaches()) and starts the modification tracker, unless the property "notracker" is given, which disables all PDO caches instead,
      3. and, if this is a server, waits until the caches are preloaded.
      Overrides:
      finishStartup in class AbstractApplication
    • registerColorSchemeListener

      protected void registerColorSchemeListener()
      Registers a listener to update the dark mode of all windows if configuration is automatic.
    • initializeScripting

      protected void initializeScripting()
      Description copied from class: AbstractApplication
      Initializes the scripting.
      Overrides:
      initializeScripting in class AbstractApplication
    • classMapped

      public void classMapped(String name, Class<?> clazz)
      A class was mapped the first time.

      Whenever a PDO class is used the first time, all field validators are prepared in the background, which pre-compiles the validator scripts, if any. This usually improves UX snappiness.

      The default implementation adds a Task to the ModificationTracker.

      Specified by:
      classMapped in interface ClassMappedListener
      Parameters:
      name - the mapped name
      clazz - the class associated with that name
    • cleanup

      protected void cleanup()
      Description copied from class: AbstractApplication
      Cleans up resources.
      Invoked from AbstractApplication.stop(int, java.lang.Throwable)
      Overrides:
      cleanup in class AbstractApplication