|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.vaadin.ui.DefaultFieldFactory
com.vaadin.addon.jpacontainer.fieldfactory.FieldFactory
public class FieldFactory
A FormFieldFactory and TableFieldFactory implementation
suitable for JPAContainer users.
As where the DefaultFieldFactory in Vaadin can only handle basic data
types, this field factory can also automatically create proper fields for
various referenced entities. This greatly speeds up construction of CRUD
views. Below are field types supported by this FieldFactory:
Example of a mapped property: @ManyToOne private Address address;
Default type: NativeSelect
Created by
createManyToOneField(EntityContainer, Object, Object, Component)
method.
The method
constructReferenceSelect(EntityContainer, Object, Object, Component, Class)
can be used to override the select type. The type can also be set per
reference type with setMultiSelectType(Class, Class).
Example of a mapped property: @ManyToMany private Set<Address> addresses;
Default type: Table (in multiselect mode)
Created by
createManyToManyField(EntityContainer, Object, Object, Component)
method.
The method
constructCollectionSelect(EntityContainer, Object, Object, Component, Class)
can be used to override the select type. Type can also be set per reference
type with setMultiSelectType(Class, Class).
Example of a mapped property: @OneToMany(mappedBy="person", cascade=CascadeType.ALL, orphanRemoval = true) private Set<Address> addresses;
Default type: MasterDetailEditor (in multiselect mode)
Created by
createOneToManyField(EntityContainer, Object, Object, Component)
method.
Some things to note:
MasterDetailEditor.Example of a mapped property: @OneToOne private Address address;
Default type: OneToOneForm
Created by
createOneToOneField(EntityContainer, Object, Object, Component)
method.
Example of a mapped property: @Embedded private Address address;
Default type: EmbeddedForm
Created by
createEmbeddedField(EntityContainer, Object, Object, Component)
method.
Example of a mapped property: @ElementCollection private Set<Address> addresses;
Default type: ElementCollectionEditor
Created by
createElementCollectionField(EntityContainer, Object, Object, Component)
method.
Note that creation of new elements uses empty paramater constructor. Also the
ElementCollectionEditor does not currently support Map type element
collection.
FieldFactory works recursively. E.g. sub forms or MasterDetailEditors
it creates uses the same fieldfactory by default. When using the class in
such conditions one often wants to use
setVisibleProperties(Class, String...) to configure created fields.
| Constructor Summary | |
|---|---|
FieldFactory()
Creates a new instance of a FieldFactory. |
|
| Method Summary | |
|---|---|
protected com.vaadin.ui.Field |
configureBasicFields(com.vaadin.ui.Field field)
This method can be used to configure field generated by the DefaultFieldFactory. |
protected void |
configureContainer(EntityContainer<?> referenceContainer,
JPAContainer<?> container)
This method does additional configurations for the container instantiated for a field. |
protected com.vaadin.ui.AbstractSelect |
constructCollectionSelect(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext,
Class<?> type)
|
protected com.vaadin.ui.AbstractSelect |
constructReferenceSelect(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext,
Class<?> type)
|
protected com.vaadin.ui.Field |
createElementCollectionField(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
|
protected com.vaadin.ui.Field |
createEmbeddedField(EntityContainer jpacontainer,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
|
protected com.vaadin.ui.Field |
createEnumSelect(Class<?> type,
Object propertyId)
|
com.vaadin.ui.Field |
createField(com.vaadin.data.Container container,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
|
com.vaadin.ui.Field |
createField(com.vaadin.data.Item item,
Object propertyId,
com.vaadin.ui.Component uiContext)
|
protected com.vaadin.ui.Field |
createIdentifierField()
This method creates field for identifier property. |
protected JPAContainer<?> |
createJPAContainerFor(EntityContainer<?> referenceContainer,
Class<?> type,
boolean buffered)
This method creates new JPAContainer instances to be used in fields generated by this FieldFactory. |
protected com.vaadin.ui.Field |
createManyToManyField(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
|
protected com.vaadin.ui.Field |
createManyToOneField(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
Creates a field for simple reference (ManyToOne) |
protected com.vaadin.ui.Field |
createOneToManyField(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
|
protected OneToOneForm |
createOneToOneField(EntityContainer<?> jpacontainer,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
|
protected Class |
detectReferencedType(javax.persistence.EntityManagerFactory emf,
Object propertyId,
Class masterEntityClass)
Detects the type entities in "collection types" (oneToMany, ManyToMany). |
protected javax.persistence.EntityManagerFactory |
getEntityManagerFactory(EntityContainer<?> containerForProperty)
|
String[] |
getVisibleProperties(Class<?> containerType)
Returns customized visible properties (and their order) for given entity type. |
void |
setMultiSelectType(Class<?> referenceType,
Class<? extends com.vaadin.ui.AbstractSelect> selectType)
|
void |
setSingleSelectType(Class<?> referenceType,
Class<? extends com.vaadin.ui.AbstractSelect> selectType)
|
void |
setVisibleProperties(Class<?> containerType,
String... propertyIdentifiers)
Configures visible properties and their order for fields created for reference/collection types referencing to given entity type. |
| Methods inherited from class com.vaadin.ui.DefaultFieldFactory |
|---|
createCaptionByPropertyId, createFieldByPropertyType, get |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FieldFactory()
FieldFactory.
| Method Detail |
|---|
public com.vaadin.ui.Field createField(com.vaadin.data.Item item,
Object propertyId,
com.vaadin.ui.Component uiContext)
createField in interface com.vaadin.ui.FormFieldFactorycreateField in class com.vaadin.ui.DefaultFieldFactory
protected com.vaadin.ui.Field createEnumSelect(Class<?> type,
Object propertyId)
type - propertyId -
protected com.vaadin.ui.Field createIdentifierField()
protected com.vaadin.ui.Field configureBasicFields(com.vaadin.ui.Field field)
field -
public com.vaadin.ui.Field createField(com.vaadin.data.Container container,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
createField in interface com.vaadin.ui.TableFieldFactorycreateField in class com.vaadin.ui.DefaultFieldFactory
protected com.vaadin.ui.Field createEmbeddedField(EntityContainer jpacontainer,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
protected OneToOneForm createOneToOneField(EntityContainer<?> jpacontainer,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
protected com.vaadin.ui.Field createManyToManyField(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
protected com.vaadin.ui.Field createOneToManyField(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
protected com.vaadin.ui.Field createElementCollectionField(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
protected Class detectReferencedType(javax.persistence.EntityManagerFactory emf,
Object propertyId,
Class masterEntityClass)
propertyId - masterEntityClass -
protected javax.persistence.EntityManagerFactory getEntityManagerFactory(EntityContainer<?> containerForProperty)
protected com.vaadin.ui.Field createManyToOneField(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext)
containerForProperty - propertyId -
protected com.vaadin.ui.AbstractSelect constructReferenceSelect(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext,
Class<?> type)
protected com.vaadin.ui.AbstractSelect constructCollectionSelect(EntityContainer containerForProperty,
Object itemId,
Object propertyId,
com.vaadin.ui.Component uiContext,
Class<?> type)
protected JPAContainer<?> createJPAContainerFor(EntityContainer<?> referenceContainer,
Class<?> type,
boolean buffered)
After setting up the container (with provider) the method configures it
with configureContainer(EntityContainer, JPAContainer) method.
If you need to use JPAContaiener with some special settings (e.g. customized EntityProvider) you should override this method.
referenceContainer - most commonly this is the container for which property the
field is being created. The default implementation uses this
extensively to decide the new JPAContainer should be
configured.type - the entity type to be listed in the containerbuffered - true if the container should be "buffered" (e.g. for a
MasterDetailEditor that is used in a buffered Form).
protected void configureContainer(EntityContainer<?> referenceContainer,
JPAContainer<?> container)
LazyLoadingDelegate and EntityManagerProvider from the
reference container.
referenceContainer - container -
public void setVisibleProperties(Class<?> containerType,
String... propertyIdentifiers)
Tables created for OneToMany or ManyToMany
reference types.
containerType - the entity type for which the visible properties will be setpropertyIdentifiers - the identifiers in wished order to be displayed
public void setMultiSelectType(Class<?> referenceType,
Class<? extends com.vaadin.ui.AbstractSelect> selectType)
public void setSingleSelectType(Class<?> referenceType,
Class<? extends com.vaadin.ui.AbstractSelect> selectType)
public String[] getVisibleProperties(Class<?> containerType)
containerType -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||