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> config)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
      config - 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> config)
      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
      config - 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> config)
      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
      config - 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> config)
      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
      config - 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.
    • 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
    • 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
    • linkedDetailPanels

      public final Collection<EntityPanel> linkedDetailPanels()
      Returns the detail panels which models have an active link to this panels model.
      Returns:
      the currently linked detail EntityPanels, if any
      See Also:
    • 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 Observer<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 user preferences for this entity panel and its detail panels.
      See Also:
    • applyPreferences

      public void applyPreferences()
      Applies any user preferences previously saved via savePreferences() for this panel and its detail panels.
      See Also:
    • 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:
    • setupControls

      protected void setupControls()
      Override to setup any custom controls. This default implementation is empty. This method is called after all standard controls have been initialized.
      See Also:
    • configureControls

      protected final void configureControls(Consumer<Controls.Layout> controlsLayout)
      Configures the controls layout.
      Note that the Controls.Layout instance has pre-configured defaults, which must be cleared in order to start with an empty configuration.
       
         configureControls(layout -> layout
                 .separator()
                 .control(createCustomControl()))
       
       
      Defaults:
      Parameters:
      controlsLayout - provides access to the controls layout configuration
      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()
      Sets up the navigation keyboard shortcuts.
      See Also:
    • 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