- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- is.codion.swing.framework.ui.EntityEditComponentPanel
-
- is.codion.swing.framework.ui.EntityEditPanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
public abstract class EntityEditPanel extends EntityEditComponentPanel
A UI component based on aEntityEditModel
.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
EntityEditPanel.ConfirmType
The actions meriting user confirmationstatic class
EntityEditPanel.ControlCode
The standard controls available to the EditPanel-
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 Modifier and Type Field Description static PropertyValue<Boolean>
USE_FOCUS_ACTIVATION
Specifies whether edit panels should be activated when the panel (or its parent EntityPanel) receives focus
Value type: Boolean
Default value: truestatic PropertyValue<Boolean>
USE_SAVE_CAPTION
Specifies whether the add/insert button caption should be 'Save' (mnemonic S), instead of 'Add' (mnemonic A)
Value type: Boolean
Default value: false-
Fields inherited from class is.codion.swing.framework.ui.EntityEditComponentPanel
MODIFIED_INDICATOR_UNDERLINE_STYLE, USE_MODIFIED_INDICATOR
-
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
Constructors Constructor Description EntityEditPanel(SwingEntityEditModel editModel)
Instantiates a new EntityEditPanel based on the givenEntityEditModel
EntityEditPanel(SwingEntityEditModel editModel, EntityEditPanel.ControlCode... controlCodes)
Instantiates a new EntityEditPanel based on the givenEntityEditModel
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StateObserver
activeObserver()
void
addActiveListener(EventDataListener<Boolean> listener)
void
addPanelInitializedListener(EventDataListener<EntityEditPanel> listener)
void
clearAndRequestFocus()
Clears the underlying edit model and requests the initial focus.protected boolean
confirm(ConfirmationMessage message)
Presents an OK/Cancel confirm dialog with the message and title from the givenConfirmationMessage
instance.protected ConfirmationMessage
confirmationMessage(EntityEditPanel.ConfirmType type)
protected boolean
confirmDelete()
Called before delete is performed, if true is returned the delete action is performed otherwise it is cancelledprotected boolean
confirmInsert()
Called before insert is performed, the default implementation simply returns trueprotected boolean
confirmUpdate()
Called before an update is performed, if true is returned the update action is performed otherwise it is cancelledboolean
containsControl(EntityEditPanel.ControlCode controlCode)
protected Controls
createControlPanelControls()
Creates a Controls instance on which to base the control panelJToolBar
createControlToolBar(int orientation)
Creates the control toolbar, that is, the toolbar containing buttons for editing entities (Insert, Update...)JPanel
createHorizontalControlPanel()
Creates a horizontally laid out control panel, that is, the panel containing buttons for editing entities (Insert, Update...)JPanel
createVerticalControlPanel()
Creates a vertically laid out control panel, that is, the panel containing buttons for editing entities (Insert, Update...)boolean
delete()
Performs delete on the active entity without asking for confirmationboolean
deleteWithConfirmation()
Performs delete on the active entity after asking for confirmation viaconfirmDelete()
.Control
getControl(EntityEditPanel.ControlCode controlCode)
EntityEditPanel
initializePanel()
Initializes this EntityEditPanel UI.protected abstract void
initializeUI()
Initializes this EntityEditPanel UI, that is, creates and lays out the components required for editing the underlying entity type.boolean
insert()
Performs insert on the active entity without asking for confirmationboolean
insertWithConfirmation()
Performs insert on the active entity after asking for confirmation viaconfirmInsert()
.boolean
isActive()
boolean
isClearAfterInsert()
boolean
isPanelInitialized()
boolean
isRequestFocusAfterInsert()
void
onReferentialIntegrityException(ReferentialIntegrityException exception, Entity entity)
Handles the given exception.void
onValidationException(ValidationException exception)
Displays the exception message after which the component involved receives the focus.void
removeActiveListener(EventDataListener<Boolean> listener)
void
setActive(boolean active)
Sets the active state of this edit panel, an active edit panel should be enabled and ready to receive inputvoid
setClearAfterInsert(boolean clearAfterInsert)
protected void
setControl(EntityEditPanel.ControlCode controlCode, Control control)
Associatescontrol
withcontrolCode
void
setReferentialIntegrityErrorHandling(ReferentialIntegrityErrorHandling referentialIntegrityErrorHandling)
void
setRequestFocusAfterInsert(boolean requestFocusAfterInsert)
String
toString()
boolean
update()
Performs update on the active entity without asking for confirmation.boolean
updateWithConfirmation()
Performs update on the active entity after asking for confirmation viaconfirmUpdate()
.protected void
validateData()
Override to add UI level validation, called before insert/update-
Methods inherited from class is.codion.swing.framework.ui.EntityEditComponentPanel
addInputPanel, addInputPanel, addInputPanel, addInputPanel, afterInsertFocusComponent, componentAttributes, createAttributeComboBox, createBigDecimalField, createBooleanComboBox, createCheckBox, createComboBox, createDoubleField, createForeignKeyComboBox, createForeignKeyLabel, createForeignKeySearchField, createForeignKeyTextField, createInputPanel, createInputPanel, createInputPanel, createInputPanel, createInputPanel, createInputPanel, createIntegerField, createItemComboBox, createLabel, createLocalDateField, createLocalDateField, createLocalDateTimeField, createLocalDateTimeField, createLocalTimeField, createLocalTimeField, createLongField, createMaskedTextField, createOffsetDateTimeField, createOffsetDateTimeField, createTemporalField, createTemporalField, createTemporalInputPanel, createTemporalInputPanel, createTextArea, createTextField, createTextInputPanel, displayException, editModel, excludeComponentFromSelection, getAttribute, getComponent, initialFocusComponent, onException, requestComponentFocus, requestFocusAfterInsert, requestFocusAfterUpdate, requestInitialFocus, selectComponentAttributes, selectInputComponent, setAfterInsertFocusAttribute, setAfterInsertFocusComponent, setComponent, setDefaultTextFieldColumns, setInitialFocusAttribute, setInitialFocusComponent, setTransferFocusOnEnter, setUseModifiedIndicator
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
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
-
-
-
-
Field Detail
-
USE_FOCUS_ACTIVATION
public static final PropertyValue<Boolean> USE_FOCUS_ACTIVATION
Specifies whether edit panels should be activated when the panel (or its parent EntityPanel) receives focus
Value type: Boolean
Default value: true
-
USE_SAVE_CAPTION
public static final PropertyValue<Boolean> USE_SAVE_CAPTION
Specifies whether the add/insert button caption should be 'Save' (mnemonic S), instead of 'Add' (mnemonic A)
Value type: Boolean
Default value: false
-
-
Constructor Detail
-
EntityEditPanel
public EntityEditPanel(SwingEntityEditModel editModel)
Instantiates a new EntityEditPanel based on the givenEntityEditModel
- Parameters:
editModel
- theEntityEditModel
instance to base this EntityEditPanel on
-
EntityEditPanel
public EntityEditPanel(SwingEntityEditModel editModel, EntityEditPanel.ControlCode... controlCodes)
Instantiates a new EntityEditPanel based on the givenEntityEditModel
- Parameters:
editModel
- theEntityEditModel
instance to base this EntityEditPanel oncontrolCodes
- if specified only controls with those keys are initialized, null or an empty array will result in no controls being initialized
-
-
Method Detail
-
addActiveListener
public final void addActiveListener(EventDataListener<Boolean> listener)
- Parameters:
listener
- a listener notified each time the active state changes
-
removeActiveListener
public final void removeActiveListener(EventDataListener<Boolean> listener)
- Parameters:
listener
- the listener to remove
-
isActive
public final boolean isActive()
- Returns:
- true if this edit panel is active, enabled and ready to receive input
-
setActive
public final void setActive(boolean active)
Sets the active state of this edit panel, an active edit panel should be enabled and ready to receive input- Parameters:
active
- the active state
-
activeObserver
public final StateObserver activeObserver()
- Returns:
- a
StateObserver
indicating whether this panel is active
-
clearAndRequestFocus
public final void clearAndRequestFocus()
Clears the underlying edit model and requests the initial focus.
-
isClearAfterInsert
public final boolean isClearAfterInsert()
- Returns:
- true if the UI should be cleared after insert has been performed
-
setClearAfterInsert
public final void setClearAfterInsert(boolean clearAfterInsert)
- Parameters:
clearAfterInsert
- true if the UI should be cleared after insert has been performed
-
isRequestFocusAfterInsert
public final boolean isRequestFocusAfterInsert()
- Returns:
- true if the UI should request focus after insert has been performed
- See Also:
EntityEditComponentPanel.requestInitialFocus()
-
setRequestFocusAfterInsert
public final void setRequestFocusAfterInsert(boolean requestFocusAfterInsert)
- Parameters:
requestFocusAfterInsert
- true if the UI should request focus after insert has been performed- See Also:
EntityEditComponentPanel.requestInitialFocus()
-
setReferentialIntegrityErrorHandling
public final void setReferentialIntegrityErrorHandling(ReferentialIntegrityErrorHandling referentialIntegrityErrorHandling)
- Parameters:
referentialIntegrityErrorHandling
- the action to take on a referential integrity error on delete
-
containsControl
public final boolean containsControl(EntityEditPanel.ControlCode controlCode)
- Parameters:
controlCode
- the control code- Returns:
- true if this edit panel contains the given control
-
getControl
public final Control getControl(EntityEditPanel.ControlCode controlCode)
- Parameters:
controlCode
- the control code- Returns:
- the control associated with
controlCode
- Throws:
IllegalArgumentException
- in case no control is associated with the given control code- See Also:
containsControl(EntityEditPanel.ControlCode)
-
onReferentialIntegrityException
public void onReferentialIntegrityException(ReferentialIntegrityException exception, Entity entity)
Handles the given exception. If the referential integrity error handling isReferentialIntegrityErrorHandling.DISPLAY_DEPENDENCIES
, the dependencies of the given entity are displayed to the user, otherwiseEntityEditComponentPanel.onException(Throwable)
is called.- Parameters:
exception
- the exceptionentity
- the entity causing the exception- See Also:
setReferentialIntegrityErrorHandling(ReferentialIntegrityErrorHandling)
-
onValidationException
public void onValidationException(ValidationException exception)
Displays the exception message after which the component involved receives the focus.- Parameters:
exception
- the exception
-
createHorizontalControlPanel
public final JPanel createHorizontalControlPanel()
Creates a horizontally laid out control panel, that is, the panel containing buttons for editing entities (Insert, Update...)- Returns:
- the control panel, null if no controls are defined
- See Also:
createControlPanelControls()
-
createVerticalControlPanel
public final JPanel createVerticalControlPanel()
Creates a vertically laid out control panel, that is, the panel containing buttons for editing entities (Insert, Update...)- Returns:
- the control panel, null if no controls are defined
- See Also:
createControlPanelControls()
-
createControlToolBar
public final JToolBar createControlToolBar(int orientation)
Creates the control toolbar, that is, the toolbar containing buttons for editing entities (Insert, Update...)- Parameters:
orientation
- the orientation- Returns:
- the control toolbar, null if no controls are defined
- See Also:
createControlPanelControls()
,SwingConstants.VERTICAL
,SwingConstants.HORIZONTAL
-
initializePanel
public final EntityEditPanel initializePanel()
Initializes this EntityEditPanel UI. This method marks this panel as initialized which prevents it from running again, whether an exception occurs or not.- Returns:
- this EntityEditPanel instance
- See Also:
isPanelInitialized()
,addPanelInitializedListener(EventDataListener)
-
isPanelInitialized
public final boolean isPanelInitialized()
- Returns:
- true if the method
initializePanel()
has been called on this EntityEditPanel instance - See Also:
initializePanel()
-
addPanelInitializedListener
public final void addPanelInitializedListener(EventDataListener<EntityEditPanel> listener)
- Parameters:
listener
- a listener notified when this panel has been successfully initialized- Throws:
IllegalStateException
- in case this panel has already been initialized- See Also:
initializePanel()
,isPanelInitialized()
-
insertWithConfirmation
public final boolean insertWithConfirmation()
Performs insert on the active entity after asking for confirmation viaconfirmInsert()
. Note thatconfirmInsert()
returns true by default, so it needs to be overridden to ask for confirmation.- Returns:
- true in case of successful insert, false otherwise
- See Also:
confirmInsert()
-
insert
public final boolean insert()
Performs insert on the active entity without asking for confirmation- Returns:
- true in case of successful insert, false otherwise
-
deleteWithConfirmation
public final boolean deleteWithConfirmation()
Performs delete on the active entity after asking for confirmation viaconfirmDelete()
.- Returns:
- true if the delete operation was successful
- See Also:
confirmDelete()
-
delete
public final boolean delete()
Performs delete on the active entity without asking for confirmation- Returns:
- true if the delete operation was successful
-
updateWithConfirmation
public final boolean updateWithConfirmation()
Performs update on the active entity after asking for confirmation viaconfirmUpdate()
.- Returns:
- true if the update operation was successful
- See Also:
confirmUpdate()
-
update
public final boolean update()
Performs update on the active entity without asking for confirmation.- Returns:
- true if the update operation was successful or if no update was required
-
validateData
protected void validateData() throws ValidationException
Override to add UI level validation, called before insert/update- Throws:
ValidationException
- in case of a validation failure
-
confirmInsert
protected boolean confirmInsert()
Called before insert is performed, the default implementation simply returns true- Returns:
- true if insert should be performed, false if it should be vetoed
-
confirmDelete
protected boolean confirmDelete()
Called before delete is performed, if true is returned the delete action is performed otherwise it is cancelled- Returns:
- true if the delete action should be performed
-
confirmUpdate
protected boolean confirmUpdate()
Called before an update is performed, if true is returned the update action is performed otherwise it is cancelled- Returns:
- true if the update action should be performed
-
confirm
protected boolean confirm(ConfirmationMessage message)
Presents an OK/Cancel confirm dialog with the message and title from the givenConfirmationMessage
instance. Returns true if OK was selected.- Parameters:
message
- the confirmation message to present to the user- Returns:
- true if OK was selected
-
confirmationMessage
protected ConfirmationMessage confirmationMessage(EntityEditPanel.ConfirmType type)
- Parameters:
type
- the confirmation message type- Returns:
- a
ConfirmationMessage
instance
-
setControl
protected final void setControl(EntityEditPanel.ControlCode controlCode, Control control)
Associatescontrol
withcontrolCode
- Parameters:
controlCode
- the control codecontrol
- the control to associate withcontrolCode
, null for none- Throws:
IllegalStateException
- in case the panel has already been initialized
-
createControlPanelControls
protected Controls createControlPanelControls()
Creates a Controls instance on which to base the control panel- Returns:
- the Controls on which to base the control panel
-
initializeUI
protected abstract void initializeUI()
Initializes this EntityEditPanel UI, that is, creates and lays out the components required for editing the underlying entity type.protected void initializeUI() { setInitialFocusAttribute(DomainModel.USER_NAME); createTextField(DomainModel.USER_NAME); createTextField(DomainModel.USER_ADDRESS); setLayout(new GridLayout(2, 1, 5, 5); addInputPanel(DomainModel.USER_NAME); addInputPanel(DomainModel.USER_ADDRESS); }
-
-