java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
is.codion.swing.framework.ui.EntityPanel
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A builder forEntityPanel
instances.static final class
Contains configuration settings for aEntityPanel
which must be set before the panel is initialized.static final class
The standard controls available in a entity panelstatic interface
Controls the detail panels for a EntityPanel instance.static interface
Handles the layout of a EntityPanel with one or more detail panels.static enum
The navigation directions.static enum
The possible states of a detail or edit panel.static enum
Specifies the window type.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionEntityPanel
(SwingEntityModel entityModel) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityEditPanel editPanel) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityEditPanel editPanel, EntityTablePanel tablePanel) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityEditPanel editPanel, EntityTablePanel tablePanel, Consumer<EntityPanel.Config> config) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityEditPanel editPanel, Consumer<EntityPanel.Config> config) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityTablePanel tablePanel) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityTablePanel tablePanel, Consumer<EntityPanel.Config> config) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, Consumer<EntityPanel.Config> config) Instantiates a new EntityPanel instance. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
activate()
Activates this panel, by initializing it, bringing its parent window to front and requesting initial focus.final EventObserver<EntityPanel>
final void
addDetailPanel
(EntityPanel detailPanel) Adds the given detail panel and sets this panel as the parent panel of the given detail panel.final void
addDetailPanels
(EntityPanel... detailPanels) final void
addKeyEvent
(KeyEvents.Builder keyEventBuilder) Enables the given key event on this panelstatic EntityPanel.Builder
builder
(EntityType entityType) Instantiates a newEntityPanel.Builder
static EntityPanel.Builder
builder
(SwingEntityModel model) Instantiates a newEntityPanel.Builder
static EntityPanel.Builder
builder
(SwingEntityModel.Builder modelBuilder) Instantiates a newEntityPanel.Builder
final String
caption()
protected final void
configureControls
(Consumer<Controls.Config> controlsConfig) Configures the controls.
Note that theControls.Config
instance has pre-configured defaults, which must be cleared in order to start with an empty configuration.final boolean
final boolean
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.protected JPanel
createEditBasePanel
(EntityEditPanel editPanel) Creates a base panel containing the given edit panel.protected final JComponent
Creates the main component, which ismainPanel()
in case of no detail panels or the result ofEntityPanel.DetailLayout.layout()
in case of one or more detail panels.protected final <T extends EntityPanel.DetailController>
Tprotected final <T extends EntityPanel.DetailLayout>
Tfinal <T extends EntityPanel>
TdetailPanel
(EntityType entityType) Returns the first detail panel found based on the givenentityType
final Collection<EntityPanel>
Returns all detail panels.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.final <T extends SwingEntityEditModel>
Tfinal <T extends EntityEditPanel>
Tfinal Value<EntityPanel.PanelState>
icon()
final <T extends EntityPanel>
TInitializes this EntityPanel, in case of some specific initialization code you can override theinitializeUI()
method and add your code there.protected final void
Initializes the edit panel, if one is available.protected final void
Initializes the table panel, if one is available.protected void
Initializes this EntityPanels UI.final Collection<EntityPanel>
Returns the detail panels which models have an active link to this panels model.protected final JPanel
final <T extends SwingEntityModel>
Tmodel()
final Optional<EntityPanel>
final void
removeKeyEvent
(KeyEvents.Builder keyEventBuilder) Disables the given key event on this panelfinal void
Requests focus for this panel.void
Saves any user preferences for all entity panels and associated elementsprotected void
Override to setup any custom controls.protected final void
Sets up the keyboard actions.protected final void
final <T extends SwingEntityTableModel>
Tfinal <T extends EntityTablePanel>
Tfinal String
toString()
void
updateUI()
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
EntityPanel
Instantiates a new EntityPanel instance. The panel is not laid out and initialized untilinitialize()
is called.- Parameters:
entityModel
- the EntityModel
-
EntityPanel
Instantiates a new EntityPanel instance. The panel is not laid out and initialized untilinitialize()
is called.- Parameters:
entityModel
- the EntityModelconfig
- provides access to the panel configuration
-
EntityPanel
Instantiates a new EntityPanel instance. The panel is not laid out and initialized untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeleditPanel
- 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 untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeleditPanel
- the edit panelconfig
- provides access to the panel configuration
-
EntityPanel
Instantiates a new EntityPanel instance. The panel is not laid out and initialized untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeltablePanel
- 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 untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeltablePanel
- the table panelconfig
- 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 untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeleditPanel
- the edit paneltablePanel
- 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 untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeleditPanel
- the edit paneltablePanel
- the table panelconfig
- provides access to the panel configuration
-
-
Method Details
-
updateUI
public void updateUI() -
model
- Type Parameters:
T
- the model type- Returns:
- the EntityModel
-
editModel
- Type Parameters:
T
- the edit model type- Returns:
- the EntityEditModel
-
tableModel
- Type Parameters:
T
- the table model type- Returns:
- the EntityTableModel
- Throws:
IllegalStateException
- in case no table model is available
-
parentPanel
- Returns:
- the parent panel or an empty Optional in case of a root panel
-
addDetailPanels
- Parameters:
detailPanels
- the detail panels- Throws:
IllegalStateException
- if the panel has already been initializedIllegalArgumentException
- if this panel already contains a given detail panel
-
addDetailPanel
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 initializedIllegalArgumentException
- if this panel already contains the given detail panel
-
initialize
Initializes this EntityPanel, in case of some specific initialization code you can override theinitializeUI()
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
- 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
- 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
Returns aValue
containing the control associated withcontrolId
, an emptyValue
if no such control is available. Note that standard controls are populated during initialization, so until then, these values may be empty.- Parameters:
controlId
- the control id- Returns:
- the
Value
containing the control associated withcontrolId
-
addKeyEvent
Enables the given key event on this panel- Parameters:
keyEventBuilder
- the key event builder
-
removeKeyEvent
Disables the given key event on this panel- Parameters:
keyEventBuilder
- the key event builder
-
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
Returns the first detail panel found based on the givenentityType
- 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
Returns all detail panels.- Returns:
- the detail panels
-
toString
-
caption
- Returns:
- the caption used when presenting this entity panel
-
description
- Returns:
- the description used when presenting this entity panel
-
icon
- Returns:
- the icon used when presenting this entity panel
-
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
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
- 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. -
savePreferences
public void savePreferences()Saves any user preferences for all entity panels and associated elements -
builder
Instantiates a newEntityPanel.Builder
- Parameters:
entityType
- the entity type to base this panel builder on- Returns:
- a panel builder
-
builder
Instantiates a newEntityPanel.Builder
- Parameters:
modelBuilder
- theSwingEntityModel.Builder
to base this panel builder on- Returns:
- a panel builder
-
builder
Instantiates a newEntityPanel.Builder
- Parameters:
model
- theSwingEntityModel
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:
-
createEditBasePanel
Creates a base panel containing the given edit panel. The default layout is aFlowLayout
with the alignment depending onEntityPanel.Config.controlComponentConstraints(String)
.- Parameters:
editPanel
- the initialized edit panel- Returns:
- a base panel for the edit panel
- See Also:
-
createControlComponent
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:
-
configureControls
Configures the controls.
Note that theControls.Config
instance has pre-configured defaults, which must be cleared in order to start with an empty configuration.configureControls(config -> config .separator() .control(createCustomControl()))
Defaults:- Parameters:
controlsConfig
- provides access to the controls configuration- See Also:
-
createMainComponent
Creates the main component, which ismainPanel()
in case of no detail panels or the result ofEntityPanel.DetailLayout.layout()
in case of one or more detail panels.- Returns:
- the main component to base this entity panel on
-
mainPanel
- Returns:
- the main panel containing the table, edit and control panels
-
setupKeyboardActions
protected final void setupKeyboardActions()Sets up the keyboard actions.- 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
- Type Parameters:
T
- the detail layout type- Returns:
- the detail layout used by this panel
-
detailController
- Type Parameters:
T
- the detail controller type- Returns:
- the detail controller used by this panel
-