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
Java FX tentackle desktop application.
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 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 method must hide the view when the main application window is displayed after successful login.

      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 to spawn 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.
      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.
    • getUncaughtExceptionHandler

      public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
      Gets the exception handler.
      Returns:
      the handler
    • createDomainContext

      public DomainContext createDomainContext(Session session)
      Creates the domain context.
      Override this method if the application uses a subclass of DomainContext.

      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.
      It can be configured via command line or user preferences. If such configuration is missing, the mode is considered to be determined automatically according to the desktop settings.
      Returns:
      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.
      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 starts the modification tracker, unless the property "notracker" is given.
      The property "statistics" activates the statistics.
      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, pre-compile all validator scripts in the background, 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