Class EntityEditPanel

    • 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,
                               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 String 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
      • 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
      • 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
      • 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()
      • isPanelInitialized

        public final boolean isPanelInitialized()
        Returns:
        true if the method initializePanel() has been called on this EntityEditPanel instance
        See Also:
        initializePanel()
      • insert

        public final boolean insert()
        Performs insert on the active entity after asking for confirmation via confirmInsert(). Note that confirmInsert() 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()
      • insertWithoutConfirmation

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

        public final boolean delete()
        Performs delete on the active entity after asking for confirmation via confirmDelete().
        Returns:
        true if the delete operation was successful
      • deleteWithoutConfirmation

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

        public final boolean update()
        Performs update on the active entity after asking for confirmation via confirmUpdate().
        Returns:
        true if the update operation was successful
      • updateWithoutConfirmation

        public final boolean updateWithoutConfirmation()
        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
      • setControl

        protected final void setControl​(EntityEditPanel.ControlCode controlCode,
                                        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
      • 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() {
              createTextField(DomainModel.USER_NAME);
              createTextField(DomainModel.USER_ADDRESS);
              setLayout(new GridLayout(2, 1, 5, 5);
              addInputPanel(DomainModel.USER_NAME);
              addInputPanel(DomainModel.USER_ADDRESS);
          }