Class EntityApplication<M extends SwingEntityApplicationModel,P extends EntityApplicationPanel<M>>
- Type Parameters:
M- the application model typeP- the application panel type
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classEntityApplication.DomainStep<M extends SwingEntityApplicationModel,P extends EntityApplicationPanel<M>> Specifies the application domain model type. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PropertyValue<Boolean> Specifies whether the connection information displayed in the frame title is automatically converted to upper case.static final PropertyValue<Boolean> Specifies whether the client saves the last successful login username, which is then displayed as the default username the next time the application is started Value type: Boolean Default value: truestatic final PropertyValue<Boolean> Specifies whether a startup dialog should be shown Value type: Boolean Default value: truestatic final PropertyValue<String> Specifies the user for logging into the application on the formuser:password. -
Method Summary
Modifier and TypeMethodDescriptionstatic <M extends SwingEntityApplicationModel,P extends EntityApplicationPanel<M>>
EntityApplication.DomainStep<M, P> clientType(String clientType) Sets the client type of the connection the application creates, identifying the application to a server, which may choose its authenticator, session contexts and idle connection timeout by it.connection(EntityConnection connection) Overridesconnection(Function).connection(Function<User, EntityConnection> connection) Note that the login dialog relies on the given function connecting eagerly, failing when given invalid credentials or an unreachable server.connectionInfoUpperCase(boolean connectionInfoUpperCase) defaultFrameSize(@Nullable Dimension defaultFrameSize) defaultLookAndFeel(Class<? extends LookAndFeel> defaultLookAndFeelClass) Sets the default look and feel class, used in case no look and feel settings are found in user preferences.defaultLookAndFeel(String defaultLookAndFeelClassName) Sets the default look and feel classname, used in case no look and feel settings are found in user preferences.defaultUser(@Nullable User defaultUser) displayFrame(boolean displayFrame) frameTitle(Observable<String> frameTitle) For a dynamic frame title.frameTitle(String frameTitle) loginPanelSouthComponent(Supplier<JComponent> loginPanelSouthComponentSupplier) Note that this does not apply when a customuser(Supplier)has been specified.lookAndFeel(Class<? extends LookAndFeel> lookAndFeelClass) Sets the look and feel class, overrides any look and feel settings found in user preferences.lookAndFeel(String lookAndFeelClassName) Sets the look and feel classname, overrides any look and feel settings found in user preferences.mainMenu(boolean mainMenu) maximizeFrame(boolean maximizeFrame) model(BiFunction<EntityConnection, User, M> model) The application model factory, receiving the connection and the application user, the one logged in, for the model to hold, seeEntityApplicationModel.user().model(Function<EntityConnection, M> model) Sets the application name, shown to the user: in the titles of the login dialog and the startup dialog, and in the frame's default title, whichframeTitle(String)replaces.onStarting(@Nullable Runnable onStarting) Runs as the application is starting, but after Look and Feel initialization.preferences(Preferences preferences) ThePreferencesinstance the application-level preferences (frame size, look and feel, default user, scaling) are read from atstart()and, on exit, written to — in place of the default file-based user preferences.saveDefaultUsername(boolean saveDefaultUsername) voidstart()Starts the application on the Event Dispatch Thread.voidstart(boolean onEventDispatchThread) Starts the application.startupDialog(boolean startupDialog) uncaughtExceptionHandler(boolean uncaughtExceptionHandler) Specifies whether to set the default uncaught exception handler when starting the application, true by default.The application user, the one logging in, propagated toconnection(Function)and themodelfactory.Supplies the application user, the one logging in, propagated toconnection(Function)and themodelfactory.Supplies the application user, the one logging in, propagated toconnection(Function)and themodelfactory.Sets the application version, shown in the frame title and the About panel.
-
Field Details
-
USER
Specifies the user for logging into the application on the formuser:password. If one is specified no login dialog is presented.Initialized with the value of the CODION_CLIENT_USER environment variable.
Warning: System properties are visible in process listings. Use only for development/testing. In production, use secure credential management.
- Value type: String
- Default value: System.getenv("CODION_CLIENT_USER")
- See Also:
-
SAVE_DEFAULT_USERNAME
Specifies whether the client saves the last successful login username, which is then displayed as the default username the next time the application is started- Value type: Boolean
- Default value: true
-
STARTUP_DIALOG
Specifies whether a startup dialog should be shown- Value type: Boolean
- Default value: true
-
CONNECTION_INFO_UPPER_CASE
Specifies whether the connection information displayed in the frame title is automatically converted to upper case.
If not, the username as input via the login dialog is used along with the connection description as provided by the underlying
EntityConnection. This may result in "Scott@DevDb" or "scott@DEVSERVER@hostname" instead of the default "SCOTT@DEVDB" or "SCOTT@DEVSERVER@HOSTNAME".- Value type: Boolean
- Default value: true
-
-
Method Details
-
icon
- Parameters:
icon- the application icon- Returns:
- this
EntityApplicationinstance
-
defaultLookAndFeel
public EntityApplication<M,P> defaultLookAndFeel(Class<? extends LookAndFeel> defaultLookAndFeelClass) Sets the default look and feel class, used in case no look and feel settings are found in user preferences.- Parameters:
defaultLookAndFeelClass- the default look and feel class- Returns:
- this
EntityApplicationinstance - See Also:
-
defaultLookAndFeel
Sets the default look and feel classname, used in case no look and feel settings are found in user preferences.- Parameters:
defaultLookAndFeelClassName- the default look and feel classname- Returns:
- this
EntityApplicationinstance - See Also:
-
lookAndFeel
Sets the look and feel class, overrides any look and feel settings found in user preferences.- Parameters:
lookAndFeelClass- the look and feel class- Returns:
- this
EntityApplicationinstance - See Also:
-
lookAndFeel
Sets the look and feel classname, overrides any look and feel settings found in user preferences.- Parameters:
lookAndFeelClassName- the look and feel classname- Returns:
- this
EntityApplicationinstance - See Also:
-
name
Sets the application name, shown to the user: in the titles of the login dialog and the startup dialog, and in the frame's default title, which
frameTitle(String)replaces.DomainType.name()by default.- Parameters:
name- the application name- Returns:
- this
EntityApplicationinstance - Throws:
IllegalArgumentException- in case the name is empty- See Also:
-
clientType
Sets the client type of the connection the application creates, identifying the application to a server, which may choose its authenticator, session contexts and idle connection timeout by it. Not shown in the application, see
name(String).Applies only to the connection created by default, not to one
givenor created by aconnection function, which sets its own.DomainType.name()by default, as withEntityConnection.Builder.clientType(String).- Parameters:
clientType- the client type- Returns:
- this
EntityApplicationinstance - Throws:
IllegalArgumentException- in case the client type is empty
-
version
Sets the application version, shown in the frame title and the About panel.
Also identifies the application version to a server, via
EntityConnection.Builder.clientVersion(Version). This applies only to the connection created by default, not to onegivenor created by aconnection function, which sets its own.- Parameters:
version- the application version- Returns:
- this
EntityApplicationinstance
-
model
- Parameters:
model- the application model factory, receiving the connection- Returns:
- this
EntityApplicationinstance - See Also:
-
model
The application model factory, receiving the connection and the application user, the one logged in, for the model to hold, see
EntityApplicationModel.user().The application user differs from the connection's user when the
connection functionconnects as another user. With aconnectiongiven, no user is supplied and the application user is the connection's user.- Parameters:
model- the application model factory, receiving the connection and the application user- Returns:
- this
EntityApplicationinstance
-
panel
- Parameters:
panel- the application panel factory- Returns:
- this
EntityApplicationinstance
-
defaultUser
- Parameters:
defaultUser- the default user credentials to display in a login dialog- Returns:
- this
EntityApplicationinstance
-
preferences
The
Preferencesinstance the application-level preferences (frame size, look and feel, default user, scaling) are read from atstart()and, on exit, written to — in place of the default file-based user preferences. Any explicit builder call (e.g.frameSize(Dimension)) still takes precedence over a stored value.This is the application-level half only; the model and its panels keep their own preferences (see the
Preferencesconstructor ofAbstractEntityApplicationModel). For a fully self-contained application (e.g. a test usingJsonPreferences.jsonPreferences()), inject the same instance into both — here and via themodelfactory.- Parameters:
preferences- the preferences instance to use for the application-level preferences- Returns:
- this
EntityApplicationinstance
-
user
The application user, the one logging in, propagated to
connection(Function)and themodelfactory.If this user is null,
user(Supplier)is used to fetch a user.- Parameters:
user- the application user- Returns:
- this
EntityApplicationinstance - See Also:
-
user
Supplies the application user, the one logging in, propagated to
connection(Function)and themodelfactory.This may be via a login dialog or simply by returning a hardcoded instance.
Startup is silently cancelled in case the
Supplier.get()throws aCancelException.- Parameters:
userSupplier- supplies the application user, for example via a login dialog- Returns:
- this
EntityApplicationinstance
-
user
Supplies the application user, the one logging in, propagated to
connection(Function)and themodelfactory.This may be via a login dialog or simply by returning a hardcoded instance.
This function receives the default user set via
defaultUser(User)or the one saved in application preferences, null if none is available.Startup is silently cancelled in case the
Supplier.get()throws aCancelException.- Parameters:
userSupplier- supplies the application user, for example via a login dialog- Returns:
- this
EntityApplicationinstance
-
saveDefaultUsername
- Parameters:
saveDefaultUsername- true if the username should be saved in user preferences after a successful login- Returns:
- this
EntityApplicationinstance
-
frame
- Parameters:
frame- the supplies the frame to use- Returns:
- this
EntityApplicationinstance
-
frameTitle
- Parameters:
frameTitle- the frame title- Returns:
- this
EntityApplicationinstance
-
frameTitle
For a dynamic frame title.- Parameters:
frameTitle- the observable controlling the frame title- Returns:
- this
EntityApplicationinstance
-
connectionInfoUpperCase
- Parameters:
connectionInfoUpperCase- specifies whether the connection information displayed in the frame title is automatically converted to upper case- Returns:
- this
EntityApplicationinstance - See Also:
-
mainMenu
- Parameters:
mainMenu- if true then a main menu is included- Returns:
- this
EntityApplicationinstance
-
maximizeFrame
- Parameters:
maximizeFrame- specifies whether the frame should be maximized or use its preferred size- Returns:
- this
EntityApplicationinstance
-
displayFrame
- Parameters:
displayFrame- specifies whether the frame should be displayed or left invisible- Returns:
- this
EntityApplicationinstance
-
uncaughtExceptionHandler
Specifies whether to set the default uncaught exception handler when starting the application, true by default.- Parameters:
uncaughtExceptionHandler- if true the default uncaught exception handler is set on application start- Returns:
- this
EntityApplicationinstance - See Also:
-
startupDialog
- Parameters:
startupDialog- if true then a progress dialog is displayed while the application is being initialized- Returns:
- this
EntityApplicationinstance
-
frameSize
- Parameters:
frameSize- the frame size when not maximized- Returns:
- this
EntityApplicationinstance
-
defaultFrameSize
- Parameters:
defaultFrameSize- the default frame size when no previous size is available in user preferences- Returns:
- this
EntityApplicationinstance
-
loginPanelSouthComponent
public EntityApplication<M,P> loginPanelSouthComponent(Supplier<JComponent> loginPanelSouthComponentSupplier) Note that this does not apply when a customuser(Supplier)has been specified.- Parameters:
loginPanelSouthComponentSupplier- supplies the component to add to theBorderLayout.SOUTHposition of the default login panel- Returns:
- this
EntityApplicationinstance
-
onStarting
Runs as the application is starting, but after Look and Feel initialization. ThrowCancelExceptionin order to cancel the application startup.- Parameters:
onStarting- run before the application is started- Returns:
- this
EntityApplicationinstance
-
onStarted
- Parameters:
onStarted- called after a successful application start- Returns:
- this
EntityApplicationinstance
-
connection
Overrides
connection(Function).No user is then supplied, the connection's user being the application user.
- Parameters:
connection- the connection for the application to use- Returns:
- this
EntityApplicationinstance
-
connection
Note that the login dialog relies on the given function connecting eagerly, failing when given invalid credentials or an unreachable server.
EntityConnection.builder()and the transport specific builders guarantee this, building establishes the connection - a function returning an unestablished hand-rolledEntityConnectionwould validate any credentials.The function may connect as another user than the one it receives, the application user, a local database under a fixed user for example, the login meant for something else. The application user then reaches the model via
model(BiFunction), and once the model holds it, it's the user shown in the frame title and saved as the default username, seeEntityApplicationModel.user().- Parameters:
connection- provides the application connection, receives the user provided byuser(Supplier)- Returns:
- this
EntityApplicationinstance
-
start
public void start()Starts the application on the Event Dispatch Thread. -
start
public void start(boolean onEventDispatchThread) Starts the application.- Parameters:
onEventDispatchThread- if true then startup is performed on the Event Dispatch Thread
-
builder
public static <M extends SwingEntityApplicationModel,P extends EntityApplicationPanel<M>> EntityApplication.DomainStep<M,P> builder(Class<M> applicationModelClass, Class<P> applicationPanelClass) - Type Parameters:
M- the application model typeP- the application panel type- Parameters:
applicationModelClass- the application model classapplicationPanelClass- the application panel class- Returns:
- a
EntityApplication
-