Package com.storedobject.vaadin
Interface ObjectFieldCreator<T>
- Type Parameters:
T
- Type type of "object" for which fields need to be created
- All Known Implementing Classes:
SOFieldCreator
public interface ObjectFieldCreator<T>
A class that implements this interface determines how fields (
HasValue
) are created for editing an "object". All methods of this
interface have default implementation.- Author:
- Syam
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
close()
Close the field creator once the "field creation" process is over.default ObjectFieldCreator
<T> create
(ObjectForm<T> objectForm) Create an instance of this interface for a particular "form".default com.vaadin.flow.component.HasValue
<?, ?> createField
(String fieldName, Class<?> fieldType, String label) Create a "field" for the name, type and label provided.default void
customizeField
(String fieldName, com.vaadin.flow.component.HasValue<?, ?> field) Customize a field.default Method
getFieldGetMethod
(String fieldName) Get the "getXXX" method for a given field name.Get the "getXXX" methods of the object from which name of the "fields" can be determined.default String
getFieldName
(Method getMethod) Get field name for a method (typically a getXXX or isXXX method).Get additional field names (in addition to the ones got fromgetFieldGetMethods()
.default int
getFieldOrder
(String fieldName) Determine the order in which field is displayed on the form.default Method
getFieldSetMethod
(String fieldName, Method getMethod) Get the "setXXX" method for a given field name.default String
Determine the label to be used for a field.getValueGetter
(String fieldName) Get the function that can obtain the value for a field from the object.default BiConsumer
<T, ?> getValueSetter
(String fieldName) Get the function that can be used to set the value of a field to the object.
-
Method Details
-
create
Create an instance of this interface for a particular "form".- Parameters:
objectForm
- Form- Returns:
- An instance of this interface. Default implementation returns the same instance.
-
getFieldGetMethods
Get the "getXXX" methods of the object from which name of the "fields" can be determined.- Returns:
- The default implementation returns
null
. Ifnull
is returned, reflection will be used on the object's class to determine the "getXXX" methods. (For example, if getFirstName() method exists, a field name of "FirstName" is assumed).
-
getFieldGetMethod
Get the "getXXX" method for a given field name.- Parameters:
fieldName
- Name of the field- Returns:
- The default implementation returns
null
. Ifnull
is returned, reflection will be used on the object's class to determine the "getXXX" method. (For example, getFirstName() method for field named "FirsrName").
-
getFieldSetMethod
Get the "setXXX" method for a given field name.- Parameters:
fieldName
- Name of the fieldgetMethod
- Get method for the field- Returns:
- The default implementation returns
null
. Ifnull
is returned, reflection will be used on the object's class to determine the "setXXX" method. (For example, setFirstName(String firstName) method for field named "FirstName").
-
getFieldNames
Get additional field names (in addition to the ones got fromgetFieldGetMethods()
.- Returns:
- Default implementation returns
null
(means no extra fields are added).
-
createField
-
customizeField
Customize a field. This is invoked after the field is created. The default implementation does nothing.- Parameters:
fieldName
- Name of the fieldfield
- Field
-
getFieldName
-
getValueGetter
Get the function that can obtain the value for a field from the object.- Parameters:
fieldName
- Field name- Returns:
- Default implementation returns
null
and in that case, it will try to get it from its "get" method if one exists. (If field name is "XXX", thengetXXX()
method is used to get the value).
-
getValueSetter
Get the function that can be used to set the value of a field to the object. Ifnull
is returned from this method, set method (setXXX()
for field "XXX") of the object is used for setting the value and if no such method exists, the field will be set to "read only".- Parameters:
fieldName
- Field name- Returns:
- Default implementaton returns
null
.
-
getFieldOrder
Determine the order in which field is displayed on the form. Fields with smaller "field orders" are displayed first.- Parameters:
fieldName
- Field name- Returns:
- Default implentation returns
Integer.MAX_VALUE
.
-
getLabel
Determine the label to be used for a field.- Parameters:
fieldName
- Field name- Returns:
- Default implementation returns the value obtained from
ApplicationEnvironment.createLabel(String)
.
-
close
default void close()Close the field creator once the "field creation" process is over. The default implemntation does nothing.
-