Class EntityPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class EntityPanel extends JPanel
A panel representing an Entity via a EntityModel, which facilitates browsing and editing of records.
   EntityType entityType = ...;
   EntityConnectionProvider connectionProvider = ...;
   SwingEntityModel entityModel = new SwingEntityModel(entityType, connectionProvider);
   EntityPanel entityPanel = new EntityPanel(entityModel);
   entityPanel.initialize();
   JFrame frame = new JFrame();
   frame.add(entityPanel);
   frame.pack();
   frame.setVisible(true);
 
See Also:
  • Constructor Details

    • EntityPanel

      public EntityPanel(SwingEntityModel entityModel)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
    • EntityPanel

      public EntityPanel(SwingEntityModel entityModel, Consumer<EntityPanel.Config> configuration)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
      configuration - provides access to the panel configuration
    • EntityPanel

      public EntityPanel(SwingEntityModel entityModel, EntityEditPanel editPanel)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
      editPanel - the edit panel
    • EntityPanel

      public EntityPanel(SwingEntityModel entityModel, EntityEditPanel editPanel, Consumer<EntityPanel.Config> configuration)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
      editPanel - the edit panel
      configuration - provides access to the panel configuration
    • EntityPanel

      public EntityPanel(SwingEntityModel entityModel, EntityTablePanel tablePanel)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
      tablePanel - the table panel
    • EntityPanel

      public EntityPanel(SwingEntityModel entityModel, EntityTablePanel tablePanel, Consumer<EntityPanel.Config> configuration)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
      tablePanel - the table panel
      configuration - provides access to the panel configuration
    • EntityPanel

      public EntityPanel(SwingEntityModel entityModel, EntityEditPanel editPanel, EntityTablePanel tablePanel)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
      editPanel - the edit panel
      tablePanel - the table panel
    • EntityPanel

      public EntityPanel(SwingEntityModel entityModel, EntityEditPanel editPanel, EntityTablePanel tablePanel, Consumer<EntityPanel.Config> configuration)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
      editPanel - the edit panel
      tablePanel - the table panel
      configuration - provides access to the panel configuration
  • Method Details

    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JPanel
    • model

      public final <T extends SwingEntityModel> T model()
      Type Parameters:
      T - the model type
      Returns:
      the EntityModel
    • editModel

      public final <T extends SwingEntityEditModel> T editModel()
      Type Parameters:
      T - the edit model type
      Returns:
      the EntityEditModel
    • tableModel

      public final <T extends SwingEntityTableModel> T tableModel()
      Type Parameters:
      T - the table model type
      Returns:
      the EntityTableModel
      Throws:
      IllegalStateException - in case no table model is available
    • parentPanel

      public final Optional<EntityPanel> parentPanel()
      Returns:
      the parent panel or an empty Optional in case of a root panel
    • addDetailPanels

      public final void addDetailPanels(EntityPanel... detailPanels)
      Parameters:
      detailPanels - the detail panels
      Throws:
      IllegalStateException - if the panel has already been initialized
      IllegalArgumentException - if this panel already contains a given detail panel
    • addDetailPanel

      public final void addDetailPanel(EntityPanel detailPanel)
      Adds the given detail panel and sets this panel as the parent panel of the given detail panel.
      Parameters:
      detailPanel - the detail panel to add
      Throws:
      IllegalStateException - if the panel has already been initialized
      IllegalArgumentException - if this panel already contains the given detail panel
    • initialize

      public final <T extends EntityPanel> T initialize()
      Initializes this EntityPanel, in case of some specific initialization code you can override the initializeUI() method and add your code there. Calling this method a second time has no effect.
      Type Parameters:
      T - the entity panel type
      Returns:
      this EntityPanel instance
    • editPanel

      public final <T extends EntityEditPanel> T editPanel()
      Type Parameters:
      T - the edit panel type
      Returns:
      the edit panel
      Throws:
      IllegalStateException - in case no edit panel is available
      See Also:
    • containsEditPanel

      public final boolean containsEditPanel()
      Returns:
      true if this panel contains a edit panel.
    • tablePanel

      public final <T extends EntityTablePanel> T tablePanel()
      Type Parameters:
      T - the table panel type
      Returns:
      the table panel
      Throws:
      IllegalStateException - in case no table panel is available
      See Also:
    • containsTablePanel

      public final boolean containsTablePanel()
      Returns:
      true if this panel contains a table panel.
    • addKeyEvent

      public final void addKeyEvent(KeyEvents.Builder keyEventBuilder)
      Enables the given key event on this panel
      Parameters:
      keyEventBuilder - the key event builder
    • removeKeyEvent

      public final void removeKeyEvent(KeyEvents.Builder keyEventBuilder)
      Disables the given key event on this panel
      Parameters:
      keyEventBuilder - the key event builder
    • activeDetailPanels

      public final Collection<EntityPanel> activeDetailPanels()
      Returns the detail panels which models are active.
      Returns:
      the currently active detail EntityPanels, if any
    • detailPanel

      public final <T extends EntityPanel> T detailPanel(EntityType entityType)
      Returns the first detail panel found based on the given entityType
      Type Parameters:
      T - the entity panel type
      Parameters:
      entityType - the entityType of the detail panel to retrieve
      Returns:
      the detail panel of the given type
      Throws:
      IllegalArgumentException - in case a panel based on the given entityType was not found
    • detailPanels

      public final Collection<EntityPanel> detailPanels()
      Returns all detail panels.
      Returns:
      the detail panels
    • toString

      public final String toString()
      Overrides:
      toString in class Component
    • caption

      public final String caption()
      Returns:
      the caption used when presenting this entity panel
    • description

      public final Optional<String> description()
      Returns:
      the description used when presenting this entity panel
    • icon

      public final Optional<ImageIcon> icon()
      Returns:
      the icon used when presenting this entity panel
    • activateEvent

      public final EventObserver<EntityPanel> activateEvent()
      Returns:
      an observer notified before this panel is activated
      See Also:
    • activate

      public final void activate()
      Activates this panel, by initializing it, bringing its parent window to front and requesting initial focus. It is up the panel or application layout to make sure this panel is made visible when activated.
      See Also:
    • displayException

      public final void displayException(Exception exception)
      Displays the exception in a dialog, with the dialog owner as the current focus owner or this panel if none is available.
      Parameters:
      exception - the exception to display
    • editPanelState

      public final Value<EntityPanel.PanelState> editPanelState()
      Returns:
      the value controlling the edit panel state, either HIDDEN, EMBEDDED or WINDOW
    • requestInitialFocus

      public final void requestInitialFocus()
      Requests focus for this panel. If an edit panel is available and not hidden, the component defined as the initialFocusComponent gets the input focus. If no edit panel is available the table panel gets the focus, otherwise the first child component of this EntityPanel is used.
      See Also:
    • savePreferences

      public void savePreferences()
      Saves any user preferences for all entity panels and associated elements
    • builder

      public static EntityPanel.Builder builder(EntityType entityType)
      Instantiates a new EntityPanel.Builder
      Parameters:
      entityType - the entity type to base this panel builder on
      Returns:
      a panel builder
    • builder

      public static EntityPanel.Builder builder(SwingEntityModel.Builder modelBuilder)
      Instantiates a new EntityPanel.Builder
      Parameters:
      modelBuilder - the SwingEntityModel.Builder to base this panel builder on
      Returns:
      a panel builder
    • builder

      public static EntityPanel.Builder builder(SwingEntityModel model)
      Instantiates a new EntityPanel.Builder
      Parameters:
      model - the SwingEntityModel to base this panel builder on
      Returns:
      a panel builder
    • initializeUI

      protected void initializeUI()
      Initializes this EntityPanels UI.
      See Also:
    • createEditBasePanel

      protected JPanel createEditBasePanel(EntityEditPanel editPanel)
      Creates a base panel containing the given edit panel. The default layout is a FlowLayout with the alignment depending on EntityPanel.Config.controlComponentConstraints(String).
      Parameters:
      editPanel - the initialized edit panel
      Returns:
      a base panel for the edit panel
      See Also:
    • createControlComponent

      protected JComponent createControlComponent(Controls controls)
      Creates the component to place next to the edit panel, containing the available controls, such as insert, update, delete, clear and refresh.
      Parameters:
      controls - the controls to display on the component
      Returns:
      the component containing the edit and table panel controls, null if no controls are available
      See Also:
    • createControls

      protected Controls createControls()
      Creates the Controls instance on which to base the controls component. By default all controls from EntityEditPanel.controls() are included and if a table panel is available a table refresh control is included as well. Override to customize the controls presented on this panel.
      Returns:
      the control component controls, an empty Controls instance in case of no controls.
      See Also:
    • createMainComponent

      protected final JComponent createMainComponent()
      Creates the main component, which is mainPanel() in case of no detail panels or the result of EntityPanel.DetailLayout.layout() in case of one or more detail panels.
      Returns:
      the main component to base this entity panel on
    • mainPanel

      protected final JPanel mainPanel()
      Returns:
      the main panel containing the table, edit and control panels
    • setupKeyboardActions

      protected final void setupKeyboardActions()
      Sets up the keyboard actions.
      See Also:
    • setupNavigation

      protected final void setupNavigation()
    • createSelectInputComponentControl

      protected final Control createSelectInputComponentControl()
      Returns:
      a Control instance for selecting a input component
    • createRequestEditPanelFocusControl

      protected final Control createRequestEditPanelFocusControl()
      Returns:
      a Control instance for requesting edit panel focus
    • createRequestTableSearchFieldControl

      protected final Control createRequestTableSearchFieldControl()
      Returns:
      a Control instance for requesting table search field focus
    • createToggleEditPanelControl

      protected final Control createToggleEditPanelControl()
      Returns:
      a Control instance for toggling the edit panel state
    • createRefreshTableControl

      protected final Control createRefreshTableControl()
      Returns:
      a Control instance for refreshing the table model
    • initializeEditPanel

      protected final void initializeEditPanel()
      Initializes the edit panel, if one is available.
    • initializeTablePanel

      protected final void initializeTablePanel()
      Initializes the table panel, if one is available.
    • detailLayout

      protected final <T extends EntityPanel.DetailLayout> T detailLayout()
      Type Parameters:
      T - the detail layout type
      Returns:
      the detail layout used by this panel
    • detailController

      protected final <T extends EntityPanel.DetailController> T detailController()
      Type Parameters:
      T - the detail controller type
      Returns:
      the detail controller used by this panel