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
Modifier and TypeClassDescriptionstatic interface
A builder forEntityPanel
instances.static interface
Controls the detail panels of a entity panelstatic enum
The navigation and resizing directions.static enum
The keyboard shortcuts available forEntityPanel
s.static interface
Handles the layout of a EntityPanelstatic enum
The possible states of a detail or edit panel.static interface
Selects an entity panel.final class
Contains configuration settings for aEntityPanel
which must be set before the panel is initialized.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
Modifier and TypeFieldDescriptionstatic final PropertyValue<String>
Specifies where the control panel should be placed in a BorderLayout
Value type: Boolean
Default value:BorderLayout.EAST
static final PropertyValue<String>
Specifies where the control toolbar should be placed in a BorderLayout
Value type: Boolean
Default value: BorderLayout.WESTstatic final PropertyValue<Boolean>
Indicates whether entity edit panel dialogs should be closed on escape
Value type: Boolean
Default value: truestatic final PropertyValue<Boolean>
Specifies whether entity panels should include controls by default
Value type: Boolean
Default value: truestatic final PropertyValue<Boolean>
Specifies whether a control for toggling the edit panel is available to the user
Value type: Boolean
Default value: truestatic final KeyboardShortcuts<EntityPanel.KeyboardShortcut>
The default keyboard shortcut keyStrokes.static final PropertyValue<Boolean>
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: falsestatic final PropertyValue<Boolean>
Specifies whether detail and edit panels should be displayed in a frame instead of the default dialog
Value type: Boolean
Default value: falsestatic final PropertyValue<Boolean>
Indicates whether keyboard navigation will be enabled
Value type: Boolean
Default value: trueFields 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
ConstructorDescriptionEntityPanel
(SwingEntityModel entityModel) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityEditPanel editPanel) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityEditPanel editPanel, EntityPanel.PanelLayout panelLayout) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityEditPanel editPanel, EntityTablePanel tablePanel) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityEditPanel editPanel, EntityTablePanel tablePanel, EntityPanel.PanelLayout panelLayout) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityPanel.PanelLayout panelLayout) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityTablePanel tablePanel) Instantiates a new EntityPanel instance.EntityPanel
(SwingEntityModel entityModel, EntityTablePanel tablePanel, EntityPanel.PanelLayout panelLayout) 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 Collection<EntityPanel>
final void
addActivateListener
(Consumer<EntityPanel> listener) 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) static 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 EntityPanel.Settings
Provides a way to configure settings before the panel is initialized.final boolean
containsDetailPanel
(EntityType entityType) Returns true if this panel contains a detail panel for the givenentityType
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 Control
protected final Control
protected final Control
protected final Control
protected final Control
final <T extends EntityPanel.DetailController>
Tfinal <T extends EntityPanel>
TdetailPanel
(EntityType entityType) Returns the detail panel for the givenentityType
, if one is availablefinal 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 JPanel
Returns the panel containing the edit panel and the controls component.protected final JPanel
Returns the base panel containing the edit and table panels (north, center).final <T extends SwingEntityEditModel>
Tfinal <T extends EntityEditPanel>
Tfinal Value<EntityPanel.PanelState>
final String
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 <T extends SwingEntityModel>
Tmodel()
final Optional<EntityPanel>
final void
Requests focus for this panel.void
Saves any user preferences for all entity panels and associated elementsfinal void
setDescription
(String description) Sets the description text to use in f.ex.final 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
-
Field Details
-
USE_KEYBOARD_NAVIGATION
Indicates whether keyboard navigation will be enabled
Value type: Boolean
Default value: true -
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
Specifies whether a control for toggling the edit panel is available to the user
Value type: Boolean
Default value: true -
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
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
Specifies where the control panel should be placed in a BorderLayout
Value type: Boolean
Default value:BorderLayout.EAST
- See Also:
-
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
Specifies whether entity panels should include controls by default
Value type: Boolean
Default value: true -
KEYBOARD_SHORTCUTS
The default keyboard shortcut keyStrokes.
-
-
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 EntityModelpanelLayout
- the detail panel layout
-
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, EntityPanel.PanelLayout panelLayout) Instantiates a new EntityPanel instance. The panel is not laid out and initialized untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeleditPanel
- the edit panelpanelLayout
- the detail panel layout
-
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, EntityPanel.PanelLayout panelLayout) Instantiates a new EntityPanel instance. The panel is not laid out and initialized untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeltablePanel
- the table panelpanelLayout
- 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 untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeleditPanel
- the edit paneltablePanel
- 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 untilinitialize()
is called.- Parameters:
entityModel
- the EntityModeleditPanel
- the edit paneltablePanel
- the table panelpanelLayout
- the detail panel layout
-
-
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
-
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
- Type Parameters:
T
- the detail panel controller type- Returns:
- the detail panel controller
-
addDetailPanels
- Parameters:
detailPanels
- the detail panels
-
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 been initialized or if it 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 avilable- 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 avilable- See Also:
-
containsTablePanel
public final boolean containsTablePanel()- Returns:
- true if this panel contains a table panel.
-
editControlPanel
Returns the panel containing the edit panel and the controls component.- Returns:
- the edit control panel
-
activeDetailPanels
- Returns:
- the currently visible/active detail EntityPanels, if any
-
detailPanel
Returns the detail panel for the givenentityType
, 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
Returns all detail panels.- Returns:
- the detail panels
-
containsDetailPanel
Returns true if this panel contains a detail panel for the givenentityType
- Parameters:
entityType
- the entityType- Returns:
- true if a detail panel for the given entityType is found
-
toString
-
setDescription
Sets the description text to use in f.ex. tool tips for tabbed panes- Parameters:
description
- the description
-
getDescription
- Returns:
- the description
-
addActivateListener
- 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
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:
-
panelLayout()
editControlPanel()
editControlTablePanel()
-
createEditBasePanel
Creates a base panel containing the given edit panel. The default layout is aFlowLayout
with the alignment depending onEntityPanel.Settings.controlComponentConstraints(String)
. The resulting panel is added atBorderLayout.CENTER
on theeditControlPanel()
- 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:
-
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 -
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.
-