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 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 keyboard shortcuts available forEntityPanel
s.static enum
The possible states of a detail or edit panel.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> configuration) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityEditPanel editPanel, Consumer<EntityPanel.Config> configuration) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityTablePanel tablePanel) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityTablePanel tablePanel, Consumer<EntityPanel.Config> configuration) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, Consumer<EntityPanel.Config> configuration) 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 Collection<EntityPanel>
Returns the detail panels which models are active.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 new EntityPanel.Builderstatic EntityPanel.Builder
builder
(SwingEntityModel model) Instantiates a new EntityPanel.Builderstatic EntityPanel.Builder
builder
(SwingEntityModel.Builder modelBuilder) Instantiates a new EntityPanel.Buildercaption()
Setting this caption Value to null reverts back to the default entity caption.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 Controls
Creates theControls
instance on which to base the controls component.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 Control
protected final Control
protected final Control
protected final Control
protected final Control
Setting this description Value to null reverts back to the default entity description.protected final <T extends EntityPanel.DetailController>
Tprotected final <T extends EntityPanel.DetailLayout>
Tfinal <T extends EntityPanel>
TdetailPanel
(EntityType entityType) Returns the first detail panel based on the givenentityType
final Collection<EntityPanel>
Returns all detail panels.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.final State
final <T extends SwingEntityEditModel>
Tfinal <T extends EntityEditPanel>
Tfinal Value<EntityPanel.PanelState>
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.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 elementsfinal void
setFocusCycleRoot
(boolean focusCycleRoot) protected final void
Sets up the keyboard navigation 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, 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 EntityModelconfiguration
- 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> configuration) Instantiates a new EntityPanel instance. The panel is not laid out and initialized untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeleditPanel
- the edit panelconfiguration
- 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> configuration) Instantiates a new EntityPanel instance. The panel is not laid out and initialized untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeltablePanel
- the table panelconfiguration
- 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> configuration) 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 panelconfiguration
- 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.
-
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
-
activeDetailPanels
Returns the detail panels which models are active.- Returns:
- the currently active detail EntityPanels, if any
-
detailPanel
Returns the first detail panel 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
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
-
description
Setting this description Value to null reverts back to the default entity description.- Returns:
- a Value for the description 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
-
disposeEditDialogOnEscape
- Returns:
- the State controlling whtether the edit dialog is disposed of on ESC
- See Also:
-
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 -
setFocusCycleRoot
public final void setFocusCycleRoot(boolean focusCycleRoot) - Overrides:
setFocusCycleRoot
in classContainer
-
builder
Instantiates a new EntityPanel.Builder- Parameters:
entityType
- the entity type to base this panel builder on- Returns:
- a panel builder
-
builder
Instantiates a new EntityPanel.Builder- Parameters:
modelBuilder
- the SwingEntityModel.Builder to base this panel builder on- Returns:
- a panel builder
-
builder
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
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:
-
createControls
Creates theControls
instance on which to base the controls component. By default all controls fromEntityEditPanel.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:
-
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 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 -
createSelectInputComponentControl
- Returns:
- a Control instance for selecting a input component
-
createRequestEditPanelFocusControl
- Returns:
- a Control instance for requesting edit panel focus
-
createRequestTableSearchFieldControl
- Returns:
- a Control instance for requesting table search field focus
-
createToggleEditPanelControl
- Returns:
- a Control instance for toggling the edit panel state
-
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
- 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
-