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:
  • Field Details

    • USE_KEYBOARD_NAVIGATION

      public static final PropertyValue<Boolean> USE_KEYBOARD_NAVIGATION
      Indicates whether keyboard navigation will be enabled
      Value type: Boolean
      Default value: true
    • DISPOSE_EDIT_DIALOG_ON_ESCAPE

      public static final PropertyValue<Boolean> DISPOSE_EDIT_DIALOG_ON_ESCAPE
      Indicates whether entity edit panel dialogs should be closed on escape
      Value type: Boolean
      Default value: true
    • INCLUDE_TOGGLE_EDIT_PANEL_CONTROL

      public static final PropertyValue<Boolean> INCLUDE_TOGGLE_EDIT_PANEL_CONTROL
      Specifies whether a control for toggling the edit panel is available to the user
      Value type: Boolean
      Default value: true
    • TOOLBAR_CONTROLS

      public static final PropertyValue<Boolean> TOOLBAR_CONTROLS
      Specifies whether the edit controls (Save, update, delete, clear, refresh) should be on a toolbar instead of a button panel
      Value type: Boolean
      Default value: false
    • USE_FRAME_PANEL_DISPLAY

      public static final PropertyValue<Boolean> USE_FRAME_PANEL_DISPLAY
      Specifies whether detail and edit panels should be displayed in a frame instead of the default dialog
      Value type: Boolean
      Default value: false
    • CONTROL_PANEL_CONSTRAINTS

      public static final PropertyValue<String> CONTROL_PANEL_CONSTRAINTS
      Specifies where the control panel should be placed in a BorderLayout
      Value type: Boolean
      Default value: BorderLayout.EAST
      See Also:
    • CONTROL_TOOLBAR_CONSTRAINTS

      public static final PropertyValue<String> CONTROL_TOOLBAR_CONSTRAINTS
      Specifies where the control toolbar should be placed in a BorderLayout
      Value type: Boolean
      Default value: BorderLayout.WEST
      See Also:
    • INCLUDE_CONTROLS

      public static final PropertyValue<Boolean> INCLUDE_CONTROLS
      Specifies whether entity panels should include controls by default
      Value type: Boolean
      Default value: true
    • KEYBOARD_SHORTCUTS

      public static final KeyboardShortcuts<EntityPanel.KeyboardShortcut> KEYBOARD_SHORTCUTS
      The default keyboard shortcut keyStrokes.
  • 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, EntityPanel.PanelLayout panelLayout)
      Instantiates a new EntityPanel instance. The panel is not laid out and initialized until initialize() is called.
      Parameters:
      entityModel - the EntityModel
      panelLayout - the detail panel layout
    • 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, EntityPanel.PanelLayout panelLayout)
      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
      panelLayout - the detail panel layout
    • 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, EntityPanel.PanelLayout panelLayout)
      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
      panelLayout - the detail panel layout
    • 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, EntityPanel.PanelLayout panelLayout)
      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
      panelLayout - the detail panel layout
  • 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
    • configure

      public final EntityPanel.Settings configure()
      Provides a way to configure settings before the panel is initialized.
      Returns:
      the EntityPanel.Settings instance
      Throws:
      IllegalStateException - in case the panel has already been initialized
    • detailController

      public final <T extends EntityPanel.DetailController> T detailController()
      Type Parameters:
      T - the detail panel controller type
      Returns:
      the detail panel controller
    • addDetailPanels

      public final void addDetailPanels(EntityPanel... detailPanels)
      Parameters:
      detailPanels - the detail panels
    • 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 been initialized or if it 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 avilable
      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 avilable
      See Also:
    • containsTablePanel

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

      public final JPanel editControlPanel()
      Returns the panel containing the edit panel and the controls component.
      Returns:
      the edit control panel
    • activeDetailPanels

      public final Collection<EntityPanel> activeDetailPanels()
      Returns:
      the currently visible/active detail EntityPanels, if any
    • detailPanel

      public final <T extends EntityPanel> T detailPanel(EntityType entityType)
      Returns the detail panel for the given entityType, if one is available
      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 the panel was not found
    • detailPanels

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

      public final boolean containsDetailPanel(EntityType entityType)
      Returns true if this panel contains a detail panel for the given entityType
      Parameters:
      entityType - the entityType
      Returns:
      true if a detail panel for the given entityType is found
    • toString

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

      public final Value<String> caption()
      Setting this caption Value to null reverts back to the default entity caption.
      Returns:
      a Value for the caption used when presenting this entity panel
    • setDescription

      public final void setDescription(String description)
      Sets the description text to use in f.ex. tool tips for tabbed panes
      Parameters:
      description - the description
    • getDescription

      public final String getDescription()
      Returns:
      the description
    • addActivateListener

      public final void addActivateListener(Consumer<EntityPanel> listener)
      Parameters:
      listener - 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(Throwable 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
    • disposeEditDialogOnEscape

      public final State disposeEditDialogOnEscape()
      Returns:
      the State controlling whtether the edit dialog is disposed of on ESC
      See Also:
    • 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
    • setFocusCycleRoot

      public final void setFocusCycleRoot(boolean focusCycleRoot)
      Overrides:
      setFocusCycleRoot in class Container
    • 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.Settings.controlComponentConstraints(String). The resulting panel is added at BorderLayout.CENTER on the editControlPanel()
      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 controls is included as well.
      Returns:
      the control component controls, an empty Controls instance in case of no controls.
      See Also:
    • editControlTablePanel

      protected final JPanel editControlTablePanel()
      Returns the base panel containing the edit and table panels (north, center).
      Returns:
      the edit and table base panel
    • setupKeyboardActions

      protected final void setupKeyboardActions()
      Sets up the keyboard navigation actions. CTRL-T transfers focus to the table in case one is available, CTR-E transfers focus to the edit panel in case one is available, CTR-S opens a select search condition panel dialog, in case one is available, CTR-I opens a select input field dialog and CTR-F selects the table search field
    • 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.