Class EntityEditPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public abstract class EntityEditPanel extends EntityEditComponentPanel
A UI component based on a EntityEditModel.
See Also:
  • 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, Consumer<EntityEditPanel.Config> config)
      Instantiates a new EntityEditPanel based on the given EntityEditModel
      Parameters:
      editModel - the EntityEditModel instance to base this EntityEditPanel on
      config - provides access to the panel configuration
  • 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:
    • control

      public final is.codion.common.value.Value<is.codion.swing.common.ui.control.Control> control(EntityEditPanel.EntityEditPanelControl control)
      Returns a Value containing the control associated with control, an empty Value if no such control is available. Note that standard controls are populated during initialization, so until then, these values may be empty.
      Parameters:
      control - the control
      Returns:
      the Value containing the control associated with control
    • controls

      public final is.codion.swing.common.ui.control.Controls controls()
      Returns a Controls instance containing all the controls configured via configureControls(Consumer).
      Returns:
      the Controls provided by this edit panel
      Throws:
      IllegalStateException - in case the panel has not been initialized
      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 specified via EntityEditPanel.Config.insertConfirmer(Confirmer). 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 EntityEditPanel.Config.insertConfirmer(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
    • deleteWithConfirmation

      public final boolean deleteWithConfirmation()
      Performs delete on the active entity after asking for confirmation using the EntityEditPanel.Confirmer specified via EntityEditPanel.Config.deleteConfirmer(Confirmer).
      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
    • updateWithConfirmation

      public final boolean updateWithConfirmation()
      Performs update on the active entity after asking for confirmation using the EntityEditPanel.Confirmer specified via EntityEditPanel.Config.updateConfirmer(Confirmer).
      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
    • initialized

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

      protected final boolean confirmInsert()
      Returns:
      true if confirmed
    • confirmUpdate

      protected final boolean confirmUpdate()
      Returns:
      true if confirmed
    • confirmDelete

      protected final boolean confirmDelete()
      Returns:
      true if confirmed
    • insertCommand

      protected final EntityEditPanel.InsertCommandBuilder insertCommand()
      Returns an async insert command builder
      Returns:
      a new async insert command builder
    • updateCommand

      protected final EntityEditPanel.UpdateCommandBuilder updateCommand()
      Returns an async update command builder
      Returns:
      a new async update command builder
    • deleteCommand

      protected final EntityEditPanel.DeleteCommandBuilder deleteCommand()
      Returns an async delete command builder
      Returns:
      a new async delete command builder
    • onException

      protected void onException(Exception exception)
      Propagates the exception to onValidationException(ValidationException) or onReferentialIntegrityException(ReferentialIntegrityException) depending on type, otherwise forwards to the super implementation.
      Overrides:
      onException in class EntityEditComponentPanel
      Parameters:
      exception - the exception to handle
      See Also:
    • onReferentialIntegrityException

      protected void onReferentialIntegrityException(is.codion.common.db.exception.ReferentialIntegrityException exception)
      Called when a ReferentialIntegrityException occurs. If a Database.Operation.DELETE operation is being performed and the referential integrity error handling is ReferentialIntegrityErrorHandling.DISPLAY_DEPENDENCIES, the dependencies of the entity involved are displayed to the user, otherwise onException(Exception) 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
    • 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:
    • 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);
        }
       
    • configureControls

      protected final void configureControls(Consumer<is.codion.swing.common.ui.control.Controls.Config<EntityEditPanel.EntityEditPanelControl>> controlsConfig)
      Configures the controls.
      Note that the Controls.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:
      • Controls.Config.clear()