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

  • Constructor Details

  • Method Details

    • displayException

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

      public final M model()
      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
    • panels

      public final List<EntityPanel> panels()
      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
    • 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 SYSTEM_EXIT is true.

      Disposes all windows in the JVM so that it can end naturally when SYSTEM_EXIT is false, note that this closes the windows of any other Codion application sharing the JVM.

      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, showing the default key strokes of the controls, see ControlKey.defaultKeystroke().
    • displayAbout

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

      public final EntityApplicationPanel<M> initialize()
      Initializes this panel and marks it as initialized, subsequent calls have no effect, nor has a call made while the initialization is in progress.
      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.

      The keys application and version are stored in the given node, along with the child nodes entities and auxiliary, so custom preferences need other names, preferably a child node of their own.

      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 panels().

    • control

      public final <T extends Control> Value<T> control(ControlKey<T> controlKey)
      Returns a Value containing the control associated with controlKey, an empty Value if no such control is available.
      Type Parameters:
      T - the control type
      Parameters:
      controlKey - the control key
      Returns:
      the Value containing the control associated with controlKey
      See Also:
    • configureMainMenu

      protected final void configureMainMenu(Consumer<Controls.Layout> mainMenuLayout)
      Configures the main menu layout, before this panel is initialized.
      Note that the Controls.Layout instance has pre-configured defaults, which can be edited in place, see Controls.Layout.after(ControlKey) and Controls.Layout.remove(ControlKey), or cleared in order to start with an empty configuration.
      configureMainMenu(layout -> layout
              .controls(ControlKeys.TOOLS_MENU, tools -> tools
                      .control(createImportControl()))
              .controls(ControlKeys.VIEW_MENU, view -> view
                      .after(ControlKeys.SELECT_SCALING)
                      .control(createSelectLanguageControl()))
              .after(ControlKeys.TOOLS_MENU)
              .control(createReportsMenu()));
      Defaults: A menu left empty is left out.
      Parameters:
      mainMenuLayout - provides access to the main menu layout
      Throws:
      IllegalStateException - in case this panel has already been initialized
      See Also:
    • 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 layout or an empty Optional in case of no menu bar
      See Also: