Class EntityEditPanel

    • Field Detail

      • USE_SAVE_CONTROL

        public static final PropertyValue<Boolean> USE_SAVE_CONTROL
        Specifies whether edit panels should include a SAVE button (insert or update, depending on selection) or just a INSERT button
        Value type: Boolean
        Default value: true
    • 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​(EntityTablePanel.ReferentialIntegrityErrorHandling referentialIntegrityErrorHandling)
        Parameters:
        referentialIntegrityErrorHandling - the action to take on a referential integrity error on delete
      • getRefreshControl

        public final Control getRefreshControl()
        Returns:
        a control for refreshing the model data
      • getDeleteControl

        public final Control getDeleteControl()
        Returns:
        a control for deleting the active entity
      • getClearControl

        public final Control getClearControl()
        Returns:
        a control for clearing the UI controls
      • getUpdateControl

        public final Control getUpdateControl()
        Returns:
        a control for performing an update on the active entity
      • getInsertControl

        public final Control getInsertControl()
        Returns:
        a control for performing an insert on the active entity
      • getSaveControl

        public final Control getSaveControl()
        Returns:
        a control for performing a save on the active entity, that is, update if an entity is selected and modified or insert otherwise
      • onValidationException

        public void onValidationException​(ValidationException exception)
        Displays the exception message after which the component involved receives the focus.
        Parameters:
        exception - the exception
      • onException

        public void onException​(Exception exception)
        Handles the given exception, simply displays the error message to the user by default.
        Parameters:
        exception - the exception to handle
        See Also:
        displayException(Throwable, Window)
      • displayException

        public final void displayException​(Throwable throwable,
                                           Window dialogParent)
        Handle the given exception and display it to the user.
        Specified by:
        displayException in interface DialogExceptionHandler
        Parameters:
        throwable - the exception
        dialogParent - the Window to use as parent to the exception dialog
      • createControlPanel

        public final JPanel createControlPanel​(boolean horizontal)
        Initializes the control panel, that is, the panel containing buttons for editing entities (Insert, Update...)
        Parameters:
        horizontal - true if the buttons should be laid out horizontally, false otherwise
        Returns:
        the control panel, null if no controls are defined
        See Also:
        initializeControlPanelControlSet()
      • createControlToolBar

        public final JToolBar createControlToolBar​(int orientation)
        Initializes 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:
        initializeControlPanelControlSet()
      • 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()
      • isPanelInitialized

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

        public final void save()
        Saves the active entity, that is, if no entity is selected it performs a insert otherwise the user is asked whether to update the selected entity or insert a new one
      • insert

        public final boolean insert()
        Performs a insert on the active entity
        Returns:
        true in case of successful insert, false otherwise
      • insert

        public final boolean insert​(boolean confirmRequired)
        Performs a insert on the active entity
        Parameters:
        confirmRequired - if true then confirmInsert() is called
        Returns:
        true in case of successful insert, false otherwise
      • delete

        public final boolean delete()
        Performs a delete on the active entity
        Returns:
        true if the delete operation was successful
      • delete

        public final boolean delete​(boolean confirmRequired)
        Performs a delete on the active entity
        Parameters:
        confirmRequired - if true then confirmDelete() is called
        Returns:
        true if the delete operation was successful
      • update

        public final boolean update()
        Performs an update on the active entity
        Returns:
        true if the update operation was successful
      • update

        public final boolean update​(boolean confirmRequired)
        Performs an update on the active entity
        Parameters:
        confirmRequired - if true then confirmUpdate() is called
        Returns:
        true if the update operation was successful or if no update was required
      • createEditPanelAction

        public static Action createEditPanelAction​(EntityComboBox comboBox,
                                                   EntityPanelBuilder panelProvider)
        Creates a new Action which shows the edit panel provided by panelProvider and if an insert is performed selects the new entity in the lookupField.
        Parameters:
        comboBox - the combo box in which to select the new entity, if created
        panelProvider - the EntityPanelBuilder for providing the EntityEditPanel to use for creating the new entity
        Returns:
        the Action
      • createEditPanelAction

        public static Action createEditPanelAction​(EntityLookupField lookupField,
                                                   EntityPanelBuilder panelProvider)
        Creates a new Action which shows the edit panel provided by panelProvider and if an insert is performed selects the new entity in the lookupField.
        Parameters:
        lookupField - the lookup field in which to select the new entity, if created
        panelProvider - the EntityPanelBuilder for providing the EntityEditPanel to use for creating the new entity
        Returns:
        the Action
      • createEditPanelAction

        public static Action createEditPanelAction​(JComponent component,
                                                   EntityPanelBuilder panelProvider,
                                                   EntityConnectionProvider connectionProvider,
                                                   EventDataListener<List<Entity>> insertListener)
        Creates a new Action which shows the edit panel provided by panelProvider and if an insert is performed insertListener is notified.
        Parameters:
        component - this component used as dialog parent, receives the focus after insert
        panelProvider - the EntityPanelBuilder for providing the EntityEditPanel to use for creating the new entity
        connectionProvider - the connection provider
        insertListener - the listener notified when insert has been performed
        Returns:
        the Action
      • 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 a insert is performed, the default implementation simply returns true
        Returns:
        true if a insert should be performed, false if it should be vetoed
      • confirmDelete

        protected boolean confirmDelete()
        Called before a 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​(String message,
                                  String title)
        Presents a OK/Cancel confirm dialog with the given message and title, returns true if OK was selected.
        Parameters:
        message - the message
        title - the dialog title
        Returns:
        true if OK was selected
      • getConfirmationMessages

        protected String[] getConfirmationMessages​(EntityEditPanel.ConfirmType type)
        Parameters:
        type - the confirmation message type
        Returns:
        a string array containing two elements, the element at index 0 is used as the message displayed in the dialog and the element at index 1 is used as the dialog title, i.e. ["Are you sure you want to delete the selected records?", "About to delete selected records"]
      • 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
      • initializeControlPanelControlSet

        protected ControlSet initializeControlPanelControlSet()
        Initializes a ControlSet on which to base the control panel
        Returns:
        the ControlSet 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);
              addPropertyPanel(DomainModel.USER_NAME);
              addPropertyPanel(DomainModel.USER_ADDRESS);
          }