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.
   EntityConnectionProvider connectionProvider = createConnectionProvider();
   SwingEntityModel entityModel = new SwingEntityModel(Employee.TYPE, 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, @Nullable 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, @Nullable 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, @Nullable 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, @Nullable 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, @Nullable EntityEditPanel editPanel, @Nullable 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, @Nullable EntityEditPanel editPanel, @Nullable 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 SwingEntityModel model()
      Returns:
      the EntityModel
    • editModel

      public final SwingEntityEditModel editModel()
      Returns:
      the EntityEditModel
    • tableModel

      public final SwingEntityTableModel tableModel()
      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
    • detailPanels

      public final EntityPanel.DetailPanels detailPanels()
      Returns:
      the detail panels
    • initialize

      public final EntityPanel 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.
      Returns:
      this EntityPanel instance
    • editPanel

      public final EntityEditPanel editPanel()
      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 an edit panel.
    • tablePanel

      public final EntityTablePanel tablePanel()
      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
    • 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
    • activated

      public final Observer<EntityPanel> activated()
      Returns:
      an observer notified when 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 EntityApplicationPanel.ApplicationLayout (for top level panels) and the EntityPanel.DetailController (for detail panels) to make sure this panel is displayed 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 EntityPanel.PanelState.HIDDEN, EntityPanel.PanelState.EMBEDDED or EntityPanel.PanelState.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 initial focus component by EntityEditComponentPanel.focus() 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:
    • writePreferences

      @Deprecated public void writePreferences(Preferences preferences)
      Deprecated.
      replaced with hierarchical preferences
      Saves user preferences for this entity panel and its detail panels using the legacy flat format.

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

      Parameters:
      preferences - the Preferences instance into which to save the preferences
      See Also:
    • applyPreferences

      @Deprecated public void applyPreferences(Preferences preferences)
      Deprecated.
      replaced with hierarchical preferences
      Applies any user preferences previously written via writePreferences(Preferences) for this panel and its detail panels using the legacy flat format.

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

      Parameters:
      preferences - the Preferences instance containing the preferences to apply
      See Also:
    • restore

      public void restore(Preferences preferences)
      Restores preferences for this panel and its detail panels. Override to restore panel specific 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 preferences for this panel and its detail panels. Override to store panel specific preferences.

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

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

      public static EntityPanel.Builder.EntityTypeStep builder()
      Returns:
      a EntityPanel.Builder.EntityTypeStep
    • initializeUI

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

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

      public String preferencesKey()
      Returns the key used to identify user preferences for this panel. The default implementation is:
       return model().entityType().name();
      
      Override in case this key is not unique within the application, for example when the same entity type appears multiple times in different contexts.
      Returns:
      the key used to identify user preferences for this panel
    • 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:
    • initializeMainComponent

      protected final JComponent initializeMainComponent()
      Initializes the main component, which is defaultPanel() 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
      Throws:
      IllegalStateException - in case the panel has already been initialized
    • defaultPanel

      protected final JPanel defaultPanel()
      Returns:
      the default 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 EntityPanel.DetailLayout detailLayout()
      Returns:
      the detail layout used by this panel
    • detailController

      protected final EntityPanel.DetailController detailController()
      Returns:
      the detail controller used by this panel