Package org.vaadin.firitin.form
Class AbstractForm<T>
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.Composite<com.vaadin.flow.component.html.Div>
-
- org.vaadin.firitin.form.AbstractForm<T>
-
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,Serializable
@CssImport(value="./org/vaadin/firitin/padding-fix-for-dialog.css", id="dialog-overlay-styles", themeFor="vaadin-dialog-overlay") public abstract class AbstractForm<T> extends com.vaadin.flow.component.Composite<com.vaadin.flow.component.html.Div>- Author:
- mstahv
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractForm.DeleteHandler<T>static interfaceAbstractForm.ResetHandler<T>static interfaceAbstractForm.SavedHandler<T>
-
Constructor Summary
Constructors Constructor Description AbstractForm(Class<T> entityType)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidadjustResetButtonState()protected voidadjustSaveButtonState()protected voidbind()By default just does simple name based binding.voidclosePopup()protected abstract com.vaadin.flow.component.ComponentcreateContent()This method should return the actual content of the form, including possible toolbar.protected com.vaadin.flow.component.button.ButtoncreateDeleteButton()protected com.vaadin.flow.component.button.ButtoncreateResetButton()protected com.vaadin.flow.component.button.ButtoncreateSaveButton()protected voiddelete(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e)voidfocusFirst()Focuses the first field found from the form.com.vaadin.flow.data.binder.Binder<T>getBinder()StringgetCancelCaption()com.vaadin.flow.component.button.ButtongetDeleteButton()StringgetDeleteCaption()AbstractForm.DeleteHandler<T>getDeleteHandler()TgetEntity()StringgetModalWindowTitle()com.vaadin.flow.component.dialog.DialoggetPopup()com.vaadin.flow.component.button.ButtongetResetButton()AbstractForm.ResetHandler<T>getResetHandler()com.vaadin.flow.component.button.ButtongetSaveButton()StringgetSaveCaption()AbstractForm.SavedHandler<T>getSavedHandler()com.vaadin.flow.component.orderedlayout.HorizontalLayoutgetToolbar()booleanhasChanges()protected booleanisBound()booleanisValid()protected voidlazyInit()VDialogopenInModalPopup()protected voidreset(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e)protected voidsave(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e)voidsetBinder(com.vaadin.flow.data.binder.Binder<T> binder)voidsetCancelCaption(String cancelCaption)voidsetDeleteButton(com.vaadin.flow.component.button.Button deleteButton)voidsetDeleteCaption(String deleteCaption)voidsetDeleteHandler(AbstractForm.DeleteHandler<T> deleteHandler)voidsetEntity(T entity)Sets the object to be edited by this form.voidsetEntityWithEnabledSave(T entity)by default only save button get's enabled when form has any changes
you can use this method in case the prefilled entity is already valid and save should be possible to press without any changes
if entity is not valid saveButton will stay disabled!protected voidsetHasChanges(boolean hasChanges)voidsetModalWindowTitle(String modalWindowTitle)voidsetResetButton(com.vaadin.flow.component.button.Button resetButton)voidsetResetHandler(AbstractForm.ResetHandler<T> resetHandler)voidsetSaveButton(com.vaadin.flow.component.button.Button button)voidsetSaveCaption(String saveCaption)voidsetSavedHandler(AbstractForm.SavedHandler<T> savedHandler)-
Methods inherited from class com.vaadin.flow.component.Composite
getChildren, getContent, getElement, initContent
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
-
-
-
-
Method Detail
-
setEntity
public void setEntity(T entity)
Sets the object to be edited by this form. This method binds all fields from this form to given objects.If your form needs to manually configure something based on the state of the edited object, you can override this method to do that either before the object is bound to fields or to do something after the bean binding.
- Parameters:
entity- the object to be edited by this form
-
setEntityWithEnabledSave
public void setEntityWithEnabledSave(T entity)
by default only save button get's enabled when form has any changes
you can use this method in case the prefilled entity is already valid and save should be possible to press without any changes
if entity is not valid saveButton will stay disabled!- Parameters:
entity- the object to be edited by this form
-
hasChanges
public boolean hasChanges()
- Returns:
- true if bean has been changed since last setEntity call.
-
setHasChanges
protected void setHasChanges(boolean hasChanges)
-
isValid
public boolean isValid()
-
setSavedHandler
public void setSavedHandler(AbstractForm.SavedHandler<T> savedHandler)
-
setResetHandler
public void setResetHandler(AbstractForm.ResetHandler<T> resetHandler)
-
setDeleteHandler
public void setDeleteHandler(AbstractForm.DeleteHandler<T> deleteHandler)
-
getResetHandler
public AbstractForm.ResetHandler<T> getResetHandler()
-
getSavedHandler
public AbstractForm.SavedHandler<T> getSavedHandler()
-
getDeleteHandler
public AbstractForm.DeleteHandler<T> getDeleteHandler()
-
getSaveCaption
public String getSaveCaption()
-
setSaveCaption
public void setSaveCaption(String saveCaption)
-
getModalWindowTitle
public String getModalWindowTitle()
-
setModalWindowTitle
public void setModalWindowTitle(String modalWindowTitle)
-
getDeleteCaption
public String getDeleteCaption()
-
setDeleteCaption
public void setDeleteCaption(String deleteCaption)
-
getCancelCaption
public String getCancelCaption()
-
setCancelCaption
public void setCancelCaption(String cancelCaption)
-
getBinder
public com.vaadin.flow.data.binder.Binder<T> getBinder()
-
setBinder
public void setBinder(com.vaadin.flow.data.binder.Binder<T> binder)
-
lazyInit
protected void lazyInit()
-
bind
protected void bind()
By default just does simple name based binding. Override this method to customize the binding.
-
createContent
protected abstract com.vaadin.flow.component.Component createContent()
This method should return the actual content of the form, including possible toolbar. Use setEntity(T entity) to fill in the data. Am example implementation could look like this:public class PersonForm extends AbstractForm<Person> { private TextField firstName = new MTextField("First Name"); private TextField lastName = new MTextField("Last Name"); @Override protected Component createContent() { return new MVerticalLayout( new FormLayout( firstName, lastName ), getToolbar() ); } }- Returns:
- the content of the form
-
adjustSaveButtonState
protected void adjustSaveButtonState()
-
getSaveButton
public com.vaadin.flow.component.button.Button getSaveButton()
-
createSaveButton
protected com.vaadin.flow.component.button.Button createSaveButton()
-
isBound
protected boolean isBound()
-
createResetButton
protected com.vaadin.flow.component.button.Button createResetButton()
-
getResetButton
public com.vaadin.flow.component.button.Button getResetButton()
-
setResetButton
public void setResetButton(com.vaadin.flow.component.button.Button resetButton)
-
createDeleteButton
protected com.vaadin.flow.component.button.Button createDeleteButton()
-
setDeleteButton
public void setDeleteButton(com.vaadin.flow.component.button.Button deleteButton)
-
getDeleteButton
public com.vaadin.flow.component.button.Button getDeleteButton()
-
adjustResetButtonState
protected void adjustResetButtonState()
-
setSaveButton
public void setSaveButton(com.vaadin.flow.component.button.Button button)
-
getEntity
public T getEntity()
- Returns:
- the currently edited entity or null if the form is currently unbound
-
save
protected void save(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e)
-
reset
protected void reset(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e)
-
delete
protected void delete(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e)
-
getToolbar
public com.vaadin.flow.component.orderedlayout.HorizontalLayout getToolbar()
- Returns:
- A default toolbar containing save/cancel/delete buttons
-
openInModalPopup
public VDialog openInModalPopup()
-
focusFirst
public void focusFirst()
Focuses the first field found from the form. It often improves UX to call this method, or focus another field, when you assign a bean for editing.
-
getPopup
public com.vaadin.flow.component.dialog.Dialog getPopup()
- Returns:
- the last Popup into which the Form was opened with #openInModalPopup method or null if the form hasn't been use in window
-
closePopup
public void closePopup()
-
-