Class ItemForm<T,U extends ItemView<T>>

java.lang.Object
net.tangly.ui.components.ItemForm<T,U>
Type Parameters:
T - Type of the entity manipulated in the form
Direct Known Subclasses:
DocumentsView.DocumentForm, EntityForm, MutableEntityForm

public abstract class ItemForm<T,U extends ItemView<T>> extends Object
Defines the CRUD contract for a form used to display or modify an entity. The abstract methods are:
value(Object)
Fill the form with properties of the entity and business logic.
clear()
Clear all fields in the form
createOrUpdateInstance(Object)
Create a new entity based on the fields and business logic.

A form has a binder to transfer values between the form fields and the entity. The form has also a reference to the view containing the entities, which could be displayed in the form.

Buttons

Cancel
The cancel button cancels the operation without any changes. The button shortcut is ESC.
Action
The action button executes the operation. The label is dependant on the operation. The button shortcut is ENTER.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ItemForm(U view)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected com.vaadin.flow.component.tabs.Tab
    addTabAt(@NotNull String tabText, @NotNull com.vaadin.flow.component.Component content, int position)
     
    protected com.vaadin.flow.data.binder.Binder<T>
     
    protected void
    Clears the content of the form.
    protected void
     
    void
    Create a new entity form.
    protected com.vaadin.flow.component.Component
    Creates the CRUD button bar.
    static <T extends net.tangly.core.codes.Code>
    com.vaadin.flow.component.combobox.ComboBox<T>
    createCodeField(@NotNull net.tangly.core.codes.CodeType<T> codeType, @NotNull String label)
    Creates a code combobox field with the specified code type and label.
    protected abstract T
    Create or update the instance with the new values from the user interface.
    boolean
     
    void
    delete(T entity)
    Display an entity with properties for deletion.
    protected T
    Deletes the entity from the backend and refreshes the grid.
    void
    display(T entity)
    Display an entity with properties for viewing.
    protected void
    display(T value, @NotNull net.tangly.core.domain.Operation operation)
    Display the value in the form.
    void
    duplicate(T entity)
    Display and support editing of a duplicated entity.
    void
    edit(T entity)
    Display an entity with properties for modification.
    protected Class<T>
     
    protected com.vaadin.flow.component.orderedlayout.VerticalLayout
    Creates the form containing all the fields to display an entity.
    protected <V> V
     
    net.tangly.core.domain.Operation
    Returns the operation of the form.
    void
    operation(@NotNull net.tangly.core.domain.Operation operation)
    Sets the operation of the form and propagates the readonly status to the form fields.
    com.vaadin.flow.component.formlayout.FormLayout
     
    static com.vaadin.flow.component.formlayout.FormLayout
    textForm(@NotNull AsciiDocField text)
    Creates a form with an AsciiDoc field to edit the text of the entity.
    Update the entity upon modification.
    Returns the value displayed in the form.
    void
    value(T value)
    Sets the value displayed in the form.
    protected U
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ItemForm

      protected ItemForm(@NotNull U view)
  • Method Details

    • createCodeField

      public static <T extends net.tangly.core.codes.Code> com.vaadin.flow.component.combobox.ComboBox<T> createCodeField(@NotNull @NotNull net.tangly.core.codes.CodeType<T> codeType, @NotNull @NotNull String label)
      Creates a code combobox field with the specified code type and label. The combobox is configured to display the code of the code type.
      Type Parameters:
      T - type of the code
      Parameters:
      codeType - type of the table code. It contains all code values
      label - label of the combobox
      Returns:
      a combobox field with the specified code type and label
    • textForm

      public static com.vaadin.flow.component.formlayout.FormLayout textForm(@NotNull @NotNull AsciiDocField text)
      Creates a form with an AsciiDoc field to edit the text of the entity.
      Parameters:
      text - field to edit the text of the entity
      Returns:
      a form layout with the AsciiDoc field
    • textForm

      public com.vaadin.flow.component.formlayout.FormLayout textForm()
    • operation

      public net.tangly.core.domain.Operation operation()
      Returns the operation of the form.
      Returns:
      the operation of the form
      See Also:
    • operation

      public void operation(@NotNull @NotNull net.tangly.core.domain.Operation operation)
      Sets the operation of the form and propagates the readonly status to the form fields. Overwrite the method to update form components accordingly.
      Parameters:
      operation - operation of the form
      See Also:
    • value

      public T value()
      Returns the value displayed in the form.
      Returns:
      value displayed in the form or null.
    • value

      public void value(T value)
      Sets the value displayed in the form. If the value is null, the form fields are reset to empty values.

      Overwrite the method to update components not supported by Vaadin binder for example an image. Handle null value accordingly. Do not forget to call the overwritten method to trigger the binding mechanism.

      Parameters:
      value - value to display in the form
    • creating

      public boolean creating()
    • binder

      protected com.vaadin.flow.data.binder.Binder<T> binder()
    • view

      protected U view()
    • entityClass

      protected Class<T> entityClass()
    • display

      public void display(@NotNull T entity)
      Display an entity with properties for viewing.
      Parameters:
      entity - entity to view
    • edit

      public void edit(@NotNull T entity)
      Display an entity with properties for modification.
      Parameters:
      entity - entity to modify
    • create

      public void create()
      Create a new entity form.
    • duplicate

      public void duplicate(@NotNull T entity)
      Display and support editing of a duplicated entity.
      Parameters:
      entity - entity to duplicate
    • delete

      public void delete(@NotNull T entity)
      Display an entity with properties for deletion.
      Parameters:
      entity - entity to delete.
    • display

      protected void display(T value, @NotNull @NotNull net.tangly.core.domain.Operation operation)
      Display the value in the form. The form is revealed in the user interface. The new mode is used to propagate the mode and configure the action buttons.
      Parameters:
      value - value to display
      operation - operation to perform
    • closeForm

      protected void closeForm()
    • clear

      protected void clear()
      Clears the content of the form. All property fields are reset to empty or a default value. The default implementation clears all fields registered in the binder. Custom fields are cleared as regular fields because both implements HasValue and therefore are eligible for the binder.
    • form

      protected com.vaadin.flow.component.orderedlayout.VerticalLayout form()
      Creates the form containing all the fields to display an entity. The form is added into the CRUD form with the associated operations.
      Returns:
      the vertical layout containing all fields to display the entity
    • createButtonBar

      protected com.vaadin.flow.component.Component createButtonBar()
      Creates the CRUD button bar. The button bar has always a cancel operation and an additional CRUD operation.
      Returns:
      domain containing the CRUD form command button
    • createOrUpdateInstance

      protected abstract T createOrUpdateInstance(T entity) throws com.vaadin.flow.data.binder.ValidationException
      Create or update the instance with the new values from the user interface.
      Parameters:
      entity - the entity to update or null if it is a created or duplicated instance
      Returns:
      new or updated instance
      Throws:
      com.vaadin.flow.data.binder.ValidationException
    • updateEntity

      public T updateEntity() throws RuntimeException
      Update the entity upon modification. The properties are validated before storing the data. Update means either changing properties of an existing entity or creating a new entity. The creation is used to create a new immutable object. If a new instance was created, the old one is deleted.

      The createOrUpdateInstance(Object) is responsible to extract the updated data from the user interface.

      Returns:
      the updated entity.
      Throws:
      RuntimeException
    • deleteEntity

      protected T deleteEntity()
      Deletes the entity from the backend and refreshes the grid.
      Returns:
      deleted entity instance
    • addTabAt

      protected com.vaadin.flow.component.tabs.Tab addTabAt(@NotNull @NotNull String tabText, @NotNull @NotNull com.vaadin.flow.component.Component content, int position)
    • fromBinder

      protected <V> V fromBinder(String field)