Class EntityEditPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public abstract class EntityEditPanel extends EntityEditComponentPanel
A UI component based on a EntityEditModel.
See Also:
  • Field Details

    • USE_FOCUS_ACTIVATION

      public static final is.codion.common.property.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 is.codion.common.property.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
    • INCLUDE_ENTITY_MENU

      public static final is.codion.common.property.PropertyValue<Boolean> INCLUDE_ENTITY_MENU
      Specifies whether to include a EntityPopupMenu on this edit panel, triggered with CTRL-ALT-V.
      Value type: Boolean
      Default value: true
  • Constructor Details

    • EntityEditPanel

      public EntityEditPanel(is.codion.swing.framework.model.SwingEntityEditModel editModel)
      Instantiates a new EntityEditPanel based on the given EntityEditModel
      Parameters:
      editModel - the EntityEditModel instance to base this EntityEditPanel on
    • EntityEditPanel

      public EntityEditPanel(is.codion.swing.framework.model.SwingEntityEditModel editModel, EntityComponents entityComponents)
      Instantiates a new EntityEditPanel based on the given EntityEditModel
      Parameters:
      editModel - the EntityEditModel instance to base this EntityEditPanel on
      entityComponents - the entity components instance to use when creating components
    • EntityEditPanel

      public EntityEditPanel(is.codion.swing.framework.model.SwingEntityEditModel editModel, EntityEditPanel.ControlCode... controlCodes)
      Instantiates a new EntityEditPanel based on the given EntityEditModel
      Parameters:
      editModel - the EntityEditModel instance to base this EntityEditPanel on
      controlCodes - if specified only controls with those keys are initialized, null or an empty array will result in no controls being initialized
    • EntityEditPanel

      public EntityEditPanel(is.codion.swing.framework.model.SwingEntityEditModel editModel, EntityComponents entityComponents, EntityEditPanel.ControlCode... controlCodes)
      Instantiates a new EntityEditPanel based on the given EntityEditModel
      Parameters:
      editModel - the EntityEditModel instance to base this EntityEditPanel on
      entityComponents - the entity components instance to use when creating components
      controlCodes - if specified only controls with those keys are initialized, null or an empty array will result in no controls being initialized
  • Method Details

    • toString

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

      public final is.codion.common.state.State active()
      Returns:
      a State controlling whether this panel is active, enabled and ready to receive input
    • clearAndRequestFocus

      public final void clearAndRequestFocus()
      Clears the underlying edit model and requests the initial focus.
      See Also:
    • clearAfterInsert

      public final is.codion.common.state.State clearAfterInsert()
      Returns:
      the State controlling whether the UI should be cleared after insert has been performed
    • requestFocusAfterInsert

      public final is.codion.common.state.State requestFocusAfterInsert()
      Returns:
      the State controlling whether the UI should request focus after insert has been performed
      See Also:
    • referentialIntegrityErrorHandling

      public final is.codion.common.value.Value<ReferentialIntegrityErrorHandling> referentialIntegrityErrorHandling()
      Returns:
      the Value controlling the action to take on a referential integrity error on delete
    • setConfirmer

      public final void setConfirmer(EntityEditPanel.Confirmer.Action action, EntityEditPanel.Confirmer confirmer)
      Sets the confirmer to use for the given action.
      Parameters:
      action - the confirmation action
      confirmer - the confirmer to use for the given action, null for the default one
    • containsControl

      public final boolean containsControl(EntityEditPanel.ControlCode controlCode)
      Parameters:
      controlCode - the control code
      Returns:
      true if this edit panel contains a control assocated with the given controlCode
    • control

      public final is.codion.swing.common.ui.control.Control control(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 controlCode
      See Also:
    • initialize

      public final EntityEditPanel initialize()
      Initializes this EntityEditPanel. This method marks this panel as initialized which prevents it from running again, whether an exception occurs or not.
      Returns:
      this EntityEditPanel instance
    • insertWithConfirmation

      public final boolean insertWithConfirmation()
      Performs insert on the active entity after asking for confirmation using the EntityEditPanel.Confirmer associated with the EntityEditPanel.Confirmer.Action.INSERT action. Note that the default insert EntityEditPanel.Confirmer simply returns true, so in order to implement a insert confirmation you must set the EntityEditPanel.Confirmer via setConfirmer(Confirmer.Action, Confirmer).
      Returns:
      true in case of successful insert, false otherwise
      See Also:
    • insert

      public final boolean insert()
      Performs insert on the active entity without asking for confirmation
      Returns:
      true in case of successful insert, false otherwise
      See Also:
    • deleteWithConfirmation

      public final boolean deleteWithConfirmation()
      Performs delete on the active entity after asking for confirmation using the EntityEditPanel.Confirmer associated with the EntityEditPanel.Confirmer.Action.DELETE action.
      Returns:
      true if the delete operation was successful
      See Also:
    • delete

      public final boolean delete()
      Performs delete on the active entity without asking for confirmation
      Returns:
      true if the delete operation was successful
      See Also:
    • updateWithConfirmation

      public final boolean updateWithConfirmation()
      Performs update on the active entity after asking for confirmation using the EntityEditPanel.Confirmer associated with the EntityEditPanel.Confirmer.Action.UPDATE action.
      Returns:
      true if the update operation was successful
      See Also:
    • update

      public final boolean update()
      Performs update on the active entity without asking for confirmation.
      Returns:
      true if the update operation was successful
      See Also:
    • initialized

      public final boolean initialized()
      Returns:
      true if this panel has been initialized
      See Also:
    • beforeInsert

      protected void beforeInsert() throws is.codion.framework.domain.entity.exception.ValidationException
      Called before insert is performed. To cancel the insert throw a CancelException.
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case of a validation failure
    • beforeUpdate

      protected void beforeUpdate() throws is.codion.framework.domain.entity.exception.ValidationException
      Called before update is performed. To cancel the update throw a CancelException.
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case of a validation failure
    • beforeDelete

      protected void beforeDelete()
      Called before delete is performed. To cancel the delete throw a CancelException.
    • onReferentialIntegrityException

      protected void onReferentialIntegrityException(is.codion.common.db.exception.ReferentialIntegrityException exception)
      Called when a ReferentialIntegrityException occurs during a delete operation on the active entity. If the referential integrity error handling is ReferentialIntegrityErrorHandling.DISPLAY_DEPENDENCIES, the dependencies of the entity involved are displayed to the user, otherwise EntityEditComponentPanel.onException(Throwable) is called.
      Parameters:
      exception - the exception
      See Also:
    • onValidationException

      protected void onValidationException(is.codion.framework.domain.entity.exception.ValidationException exception)
      Displays the exception message after which the component involved receives the focus.
      Parameters:
      exception - the exception
    • setControl

      protected final void setControl(EntityEditPanel.ControlCode controlCode, is.codion.swing.common.ui.control.Control control)
      Associates control with controlCode
      Parameters:
      controlCode - the control code
      control - the control to associate with controlCode, null for none
      Throws:
      IllegalStateException - in case the panel has already been initialized
    • createControls

      protected is.codion.swing.common.ui.control.Controls createControls()
      Creates a Controls instance containing all the controls available in this edit panel
      Returns:
      the Controls available in this edit panel
      Throws:
      IllegalStateException - in case the panel has not been initialized
      See Also:
    • 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() {
            initialFocusAttribute().set(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);
        }