info.magnolia.ui.form.field.transformer.item
Class FileTransformer<T extends UploadReceiver>

java.lang.Object
  extended by info.magnolia.ui.form.field.transformer.item.FileTransformer<T>
Type Parameters:
T - property type used by the related field.
All Implemented Interfaces:
info.magnolia.ui.api.i18n.I18NAwareHandler, Transformer<T>

public class FileTransformer<T extends UploadReceiver>
extends Object
implements Transformer<T>

Implementation of a Transformer that handle a Binary Item instead of a simple property.


Field Summary
protected  String basePropertyName
           
protected  BasicUploadFieldDefinition definition
           
protected  String i18NPropertyName
           
protected  com.vaadin.data.Item relatedFormItem
           
protected  Class<T> type
           
 
Constructor Summary
FileTransformer(com.vaadin.data.Item relatedFormItem, BasicUploadFieldDefinition definition, Class<T> type)
           
 
Method Summary
 T createPropertyFromItem(com.vaadin.data.Item item)
           
 String getBasePropertyName()
           
protected  String getItemName()
          Based on the i18n information, define the item name to use.
 Locale getLocale()
           
protected  com.vaadin.data.Item getOrCreateFileItem()
           
protected  com.vaadin.data.Property getOrCreateProperty(com.vaadin.data.Item item, String propertyName, Class<?> type)
          Get the required property from the Item, or create it if it does not exist.
protected  info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter getRootItem()
          Defines the root item used to retrieve and create child items.
protected  List<javax.jcr.Node> getStoredChildNodes(info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter parent)
          Fetches child nodes of the given parent from JCR, filtered using the NodeUtil.MAGNOLIA_FILTER predicate.
 Class<T> getType()
           
protected  void handleInvalid(T newValue, com.vaadin.data.Item item)
          Handle the related Item in case FileTransformer#isValid(Object, Item) return false.
 boolean hasI18NSupport()
          Return true if this Property has to support i18n.
protected  T initializeUploadReceiver()
           
protected  boolean isValid(T newValue, com.vaadin.data.Item item)
           
 com.vaadin.data.Item populateItem(T newValue, com.vaadin.data.Item item)
          Populate the related Item with the values of 'newItem' in case FileTransformer#isValid(Object, Item) return true.
protected  void populateStoredChildItems(info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter rootItem)
          Populates the given root item with its child items.
 T readFromItem()
          Get the stored Item, and based of this Item, return createPropertyFromItem(Item) .
 void setI18NPropertyName(String i18nPropertyName)
           
 void setLocale(Locale locale)
           
 void writeToItem(T newValue)
          Base on the validity of the received property, populate or not the property to the related Item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

relatedFormItem

protected com.vaadin.data.Item relatedFormItem

definition

protected final BasicUploadFieldDefinition definition

type

protected final Class<T extends UploadReceiver> type

basePropertyName

protected String basePropertyName

i18NPropertyName

protected String i18NPropertyName
Constructor Detail

FileTransformer

@Inject
public FileTransformer(com.vaadin.data.Item relatedFormItem,
                              BasicUploadFieldDefinition definition,
                              Class<T> type)
Method Detail

writeToItem

public void writeToItem(T newValue)
Base on the validity of the received property, populate or not the property to the related Item.
Call FileTransformer#populateItem(Object, Item) in case FileTransformer#isValid(Object, Item) return true.
Otherwise call FileTransformer#handleInvalid(Object, Item).

Specified by:
writeToItem in interface Transformer<T extends UploadReceiver>

readFromItem

public T readFromItem()
Get the stored Item, and based of this Item, return createPropertyFromItem(Item) .

Specified by:
readFromItem in interface Transformer<T extends UploadReceiver>

getOrCreateFileItem

protected com.vaadin.data.Item getOrCreateFileItem()
Returns:
the existing Item otherwise create an empty new Item.

getItemName

protected String getItemName()
Based on the i18n information, define the item name to use.


createPropertyFromItem

public T createPropertyFromItem(com.vaadin.data.Item item)
Returns:
related property initialized based on the Item.

initializeUploadReceiver

protected T initializeUploadReceiver()

isValid

protected boolean isValid(T newValue,
                          com.vaadin.data.Item item)
Returns:
true it the 'newValue' property is valid for being populated to the Item FileTransformer#populateItem(Object, Item).

populateItem

public com.vaadin.data.Item populateItem(T newValue,
                                         com.vaadin.data.Item item)
Populate the related Item with the values of 'newItem' in case FileTransformer#isValid(Object, Item) return true.

See Also:
FileTransformer#writeToItem(Object)}.

handleInvalid

protected void handleInvalid(T newValue,
                             com.vaadin.data.Item item)
Handle the related Item in case FileTransformer#isValid(Object, Item) return false.

See Also:
FileTransformer#writeToItem(Object)}.

getOrCreateProperty

protected com.vaadin.data.Property getOrCreateProperty(com.vaadin.data.Item item,
                                                       String propertyName,
                                                       Class<?> type)
Get the required property from the Item, or create it if it does not exist.


getRootItem

protected info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter getRootItem()
Defines the root item used to retrieve and create child items.


populateStoredChildItems

protected void populateStoredChildItems(info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter rootItem)
Populates the given root item with its child items.


getStoredChildNodes

protected List<javax.jcr.Node> getStoredChildNodes(info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter parent)
Fetches child nodes of the given parent from JCR, filtered using the NodeUtil.MAGNOLIA_FILTER predicate.


getBasePropertyName

public String getBasePropertyName()
Specified by:
getBasePropertyName in interface info.magnolia.ui.api.i18n.I18NAwareHandler

getType

public Class<T> getType()
Specified by:
getType in interface Transformer<T extends UploadReceiver>
Returns:
type the type of the value. value must be assignable to this type.

hasI18NSupport

public boolean hasI18NSupport()
Description copied from interface: Transformer
Return true if this Property has to support i18n.

Specified by:
hasI18NSupport in interface Transformer<T extends UploadReceiver>

setLocale

public void setLocale(Locale locale)
Specified by:
setLocale in interface info.magnolia.ui.api.i18n.I18NAwareHandler

setI18NPropertyName

public void setI18NPropertyName(String i18nPropertyName)
Specified by:
setI18NPropertyName in interface info.magnolia.ui.api.i18n.I18NAwareHandler

getLocale

public Locale getLocale()
Specified by:
getLocale in interface info.magnolia.ui.api.i18n.I18NAwareHandler


Copyright © 2014 Magnolia International Ltd.. All Rights Reserved.