Class EntityApplicationPanel<M extends SwingEntityApplicationModel>

Type Parameters:
M - the application model type
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class EntityApplicationPanel<M extends SwingEntityApplicationModel> extends JPanel
A central application panel class.
See Also:
  • Field Details

    • CALL_SYSTEM_EXIT

      public static final PropertyValue<Boolean> CALL_SYSTEM_EXIT
      Specifies whether the application should call System.exit(int) when exiting.
      • Value type: Boolean
      • Default value: false
      See Also:
    • DISPLAY_SYSTEM_PROPERTIES

      public static final PropertyValue<Boolean> DISPLAY_SYSTEM_PROPERTIES
      Specifies whether a button for displaying system properties is included on the about panel.
      • Value type: Boolean
      • Default value: true
      See Also:
    • SQL_TRACING

      public static final PropertyValue<Boolean> SQL_TRACING
      Specifies whether to include sql tracing related controls in the log menu.
      • Value type: Boolean
      • Default value: false
    • HELP_URL

      public static final PropertyValue<String> HELP_URL
      Specifies the URL to the application help
      • Value type: String
      • Default value: https://codion.is/doc/{version}/help/client.html
    • CONFIRM_EXIT

      public static final PropertyValue<Boolean> CONFIRM_EXIT
      Indicates whether the application should ask for confirmation when exiting
      • Value type: Boolean
      • Default value: false
    • CACHE_ENTITY_PANELS

      public static final PropertyValue<Boolean> CACHE_ENTITY_PANELS
      Specifies whether EntityPanels displayed via displayEntityPanelDialog(EntityPanel) or displayEntityPanelFrame(EntityPanel) should be cached, instead of being created each time the dialog/frame is shown.
      • Value type: Boolean
      • Default value: false
      See Also:
    • LEGACY_PREFERENCES

      public static final PropertyValue<Boolean> LEGACY_PREFERENCES
      Controls whether legacy flat file-based preferences are applied and written. When true, both legacy (flat) and hierarchical (JSON) preferences are used, with hierarchical preferences taking precedence when present.
      • Value type: Boolean
      • Default value: true (for backward compatibility during transition)
  • Constructor Details

  • Method Details

    • displayException

      public final void displayException(Exception exception)
      Displays the exception in a dialog
      Parameters:
      exception - the exception to display
    • applicationModel

      public final M applicationModel()
      Returns:
      the application model this application panel is based on
    • applicationLayout

      public final EntityApplicationPanel.ApplicationLayout applicationLayout()
      Returns:
      the application layout
    • entityPanel

      public final EntityPanel entityPanel(EntityType entityType)
      Parameters:
      entityType - the entityType
      Returns:
      the first entity panel found based on the given entity type
      Throws:
      IllegalArgumentException - in case this application panel does not contain a panel for the given entity type
    • entityPanels

      public final List<EntityPanel> entityPanels()
      Returns:
      an unmodifiable view of the main application panels
    • alwaysOnTop

      public final State alwaysOnTop()
      Returns:
      a State controlling the alwaysOnTop state of this panels parent window
    • viewApplicationTree

      public final void viewApplicationTree()
      Displays in a dialog a tree describing the application layout
    • viewDependencyTree

      public final void viewDependencyTree()
      Shows a dialog containing a dependency tree view of all defined entities
    • initialized

      public final Observer<EntityApplicationPanel<M>> initialized()
      Returns:
      an observer notified when this application panel is initialized
      See Also:
    • exit

      public final void exit()
      Exits this application. Calls System.exit(int) in case CALL_SYSTEM_EXIT is true.
      Throws:
      CancelException - if the exit is cancelled
      See Also:
    • displayHelp

      public void displayHelp() throws Exception
      Displays the help.
      Throws:
      Exception - in case of an exception, for example a malformed URL
      See Also:
    • displayKeyboardShortcuts

      public final void displayKeyboardShortcuts()
      Displays a keyboard shortcut overview panel.
    • displayAbout

      public final void displayAbout()
      Shows an about-dialog
      See Also:
    • initialize

      public final EntityApplicationPanel<M> initialize()
      Initializes this panel and marks is as initialized, subsequent calls have no effect.
      Returns:
      this application panel
    • restore

      public void restore(Preferences preferences)
      Restores preferences for this application panel and its sub-panels. Override to apply any custom preferences.

      Remember to call super.restore(preferences) when overriding.

      Parameters:
      preferences - the preferences instance from which to restore
    • store

      public void store(Preferences preferences)
      Stores application preferences. Override to store custom preferences.

      Remember to call super.store(preferences) when overriding.

      Parameters:
      preferences - the Preferences instance to write to
    • requestInitialFocus

      public void requestInitialFocus()

      Requests the initial application focus by calling EntityPanel.requestInitialFocus() on the main entity panel.

      By default, the main entity panel is the first one returned by entityPanels().

    • createDependencyTreeModel

      public static TreeModel createDependencyTreeModel(Entities entities)
      Parameters:
      entities - the entities
      Returns:
      a tree model showing the dependencies between entities via foreign keys
    • createMainMenuControls

      protected Optional<Controls> createMainMenuControls()
      Returns:
      the controls on which to base the main menu or an empty Optional if the menu should be excluded
      See Also:
    • createFileMenuControls

      protected Optional<Controls> createFileMenuControls()
      Returns:
      the Controls specifying the items in the 'File' menu or an empty Optional to skip the menu
    • createToolsMenuControls

      protected Optional<Controls> createToolsMenuControls()
      Returns:
      the Controls specifying the items in the 'Tools' menu or an empty Optional to skip the menu
    • createViewMenuControls

      protected Optional<Controls> createViewMenuControls()
      Returns:
      the Controls specifying the items in the 'View' menu or an empty Optional to skip the menu
    • createHelpMenuControls

      protected Optional<Controls> createHelpMenuControls()
      Returns:
      the Controls specifying the items in the 'Help' menu or an empty Optional to skip the menu
    • createLookupMenuControls

      protected Optional<Controls> createLookupMenuControls()
      Returns:
      the Controls on which to base the Lookup menu or an empty Optional to skip the menu
    • createExitControl

      protected final Control createExitControl()
      Returns:
      a Control for exiting the application
    • createLogLevelControl

      protected final Controls createLogLevelControl()
      Returns:
      Controls for setting the log level
    • createViewApplicationTreeControl

      protected final Control createViewApplicationTreeControl()
      Returns:
      a Control for viewing the application structure tree
    • createViewDependencyTree

      protected final Control createViewDependencyTree()
      Returns:
      a Control for viewing the application dependency tree
    • createSelectLookAndFeelControl

      protected final Control createSelectLookAndFeelControl()
      Allows the user the select between the available Look and Feels.
      Returns:
      a Control for selecting the application look and feel
      See Also:
    • createSelectScalingControl

      protected final Control createSelectScalingControl()
      Returns:
      a Control for selecting the scaling
    • createAlwaysOnTopControl

      protected final ToggleControl createAlwaysOnTopControl()
      Returns:
      a Control controlling the always on top status
    • createAboutControl

      protected final Control createAboutControl()
      Returns:
      a Control for viewing information about the application
    • createHelpControl

      protected final Control createHelpControl()
      Returns:
      a Control for displaying the help
    • createLogControls

      protected final Controls createLogControls()
      Returns:
      Controls for log handling
    • createViewKeyboardShortcutsControl

      protected final Control createViewKeyboardShortcutsControl()
      Returns:
      a Control for displaying the keyboard shortcuts overview
    • createAboutPanel

      protected JPanel createAboutPanel()
      Returns:
      the panel shown when Help -> About is selected
    • bindEvents

      protected void bindEvents()
      Override to add event bindings after initialization
    • displayEntityPanelWindow

      protected final void displayEntityPanelWindow(EntityPanel.Builder panelBuilder)
      Displays the panel provided by the given builder in a frame or dialog, depending on EntityPanel.Config.WINDOW_TYPE.
      Parameters:
      panelBuilder - the entity panel builder
      See Also:
    • displayEntityPanelWindow

      protected final void displayEntityPanelWindow(EntityPanel entityPanel)
      Displays the given panel in a frame or dialog, depending on EntityPanel.Config.WINDOW_TYPE.
      Parameters:
      entityPanel - the entity panel
      See Also:
    • displayEntityPanelFrame

      protected final void displayEntityPanelFrame(EntityPanel entityPanel)
      Displays a frame containing the given entity panel
      Parameters:
      entityPanel - the entity panel
    • displayEntityPanelDialog

      protected final void displayEntityPanelDialog(EntityPanel entityPanel)
      Displays a non-modal dialog containing the given entity panel
      Parameters:
      entityPanel - the entity panel
    • displayEntityPanelDialog

      protected final void displayEntityPanelDialog(EntityPanel entityPanel, boolean modal)
      Shows a dialog containing the given entity panel
      Parameters:
      entityPanel - the entity panel
      modal - if true the dialog should be modal
    • exiting

      protected final Observer<EntityApplicationPanel<M>> exiting()
      To cancel the exit add a listener throwing a CancelException.
      Returns:
      an observer notified when the application is about to exit.
    • createMenuBar

      protected Optional<JMenuBar> createMenuBar()
      Creates the JMenuBar to use on the application Frame
      Returns:
      by default a JMenuBar based on the main menu controls or an empty Optional in case of no menu bar
      See Also:
    • writePreferences

      @Deprecated protected void writePreferences(Preferences preferences)
      Deprecated.
      replaced with hierarchical preferences

      Called during the exit() method, override to write custom user preferences on program exit.

      Remember to call super.writePreferences(preferences) when overriding.

      Parameters:
      preferences - the preferences instance to write to
    • applyPreferences

      @Deprecated protected void applyPreferences(Preferences preferences)
      Deprecated.
      replaced with hierarchical preferences

      Called on application start when using legacy flat preferences.

      Remember to call super.applyLegacyPreferences(preferences) when overriding.

      Parameters:
      preferences - the preferences instance containing the preferences to apply
    • legacyPreferences

      protected Preferences legacyPreferences()