info.magnolia.ui.form.field.transformer.multi
Class MultiValueChildrenNodeTransformer

java.lang.Object
  extended by info.magnolia.ui.form.field.transformer.basic.BasicTransformer<com.vaadin.data.util.PropertysetItem>
      extended by info.magnolia.ui.form.field.transformer.multi.MultiValueChildrenNodeTransformer
All Implemented Interfaces:
I18NAwareHandler, Transformer<com.vaadin.data.util.PropertysetItem>
Direct Known Subclasses:
MultiValueSubChildrenNodePropertiesTransformer, MultiValueSubChildrenNodeTransformer

public class MultiValueChildrenNodeTransformer
extends BasicTransformer<com.vaadin.data.util.PropertysetItem>

Sub Nodes implementation of Transformer storing and retrieving properties (as PropertysetItem) displayed in MultiField.
Storage strategy:
- root node (relatedFormItem)
-- child node 1 (used to store the first value of the MultiField as a property)
--- property1 (store the first value of the MultiField)
-- child node 2 (used to store the second value of the MultiField as a property)
--- property2 (store the second value of the MultiField)
...
Each element of the MultiField is stored in a property located in a child node of the root node.
Child node name : Incremental number (00, 01,....)
Property name : field name
Override createChildItemName(Set, Object, JcrNodeAdapter) to define the child node name.
Override setChildValuePropertyName(String) to change the property name used to store the MultiField value element.


Field Summary
 
Fields inherited from class info.magnolia.ui.form.field.transformer.basic.BasicTransformer
basePropertyName, definition, i18NPropertyName, relatedFormItem, type
 
Constructor Summary
MultiValueChildrenNodeTransformer(com.vaadin.data.Item relatedFormItem, ConfiguredFieldDefinition definition, Class<com.vaadin.data.util.PropertysetItem> type)
           
 
Method Summary
protected  String createChildItemName(Set<String> childNames, Object value, JcrNodeAdapter rootItem)
          Basic Implementation that create child Nodes with increasing number as Name.
protected  org.apache.jackrabbit.commons.predicate.Predicate createPredicateToEvaluateChildNode()
          Create a Predicate used to evaluate the child node of the root to handle.
Only return child node that have a number name's.
protected  JcrNodeAdapter getOrCreateChildNode(String childNodeName, String childNodeType)
          Retrieve or create a child node as JcrNodeAdapter.
protected  JcrNodeAdapter getRootItem()
          Define the root Item used in order to set the SubNodes list.
protected  List<javax.jcr.Node> getStoredChildNodes(JcrNodeAdapter parent)
          Get all childNodes of parent passing the Predicate created by createPredicateToEvaluateChildNode() or
with type NodeTypes.ContentNode.NAME if the Predicate is null.
protected  Object getValueFromChildNode(javax.jcr.Node child)
          Return a specific value from the child node.
protected  void handleRootitemAndParent(JcrNodeAdapter rootItem)
          Handle the relation between parent and rootItem.
Typically, if rootItem would be a child of parentItem:
 boolean hasI18NSupport()
          No I18N Support implemented for subNode.
protected  JcrNodeAdapter initializeChildItem(JcrNodeAdapter rootItem, javax.jcr.Node rootNode, String childName)
          Create a Child Item.
- if the related node already has a Child Node called 'childName', initialize the ChildItem based on this child Node.
- else create a new JcrNodeAdapter.
 com.vaadin.data.util.PropertysetItem readFromItem()
          Retrieve a list of values based on the sub nodes.
- get a list of childNodes to handle
- for each childNode retrieve the value to set to the PropertysetItem
If no childNodes are present, return an empty PropertysetItem.
protected  void setChildItemValue(JcrNodeAdapter childItem, Object value)
          Set the value as property to the childItem.
 void setChildValuePropertyName(String newName)
           
protected  void setNewChildItem(JcrNodeAdapter rootItem, com.vaadin.data.util.PropertysetItem newValue)
           
 void writeToItem(com.vaadin.data.util.PropertysetItem newValue)
          Create new Child Items based on the newValues.
 
Methods inherited from class info.magnolia.ui.form.field.transformer.basic.BasicTransformer
definePropertyName, getBasePropertyName, getLocale, getOrCreateProperty, getType, setI18NPropertyName, setLocale, setType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiValueChildrenNodeTransformer

public MultiValueChildrenNodeTransformer(com.vaadin.data.Item relatedFormItem,
                                         ConfiguredFieldDefinition definition,
                                         Class<com.vaadin.data.util.PropertysetItem> type)
Method Detail

hasI18NSupport

public boolean hasI18NSupport()
No I18N Support implemented for subNode.

Specified by:
hasI18NSupport in interface Transformer<com.vaadin.data.util.PropertysetItem>
Overrides:
hasI18NSupport in class BasicTransformer<com.vaadin.data.util.PropertysetItem>

readFromItem

public com.vaadin.data.util.PropertysetItem readFromItem()
Retrieve a list of values based on the sub nodes.
- get a list of childNodes to handle
- for each childNode retrieve the value to set to the PropertysetItem
If no childNodes are present, return an empty PropertysetItem.

Specified by:
readFromItem in interface Transformer<com.vaadin.data.util.PropertysetItem>
Overrides:
readFromItem in class BasicTransformer<com.vaadin.data.util.PropertysetItem>

writeToItem

public void writeToItem(com.vaadin.data.util.PropertysetItem newValue)
Create new Child Items based on the newValues.
- on the rootItem, create or update childItems based on the newValues (one ChildItem per new Value). - remove the no more existing child from the source Item.

Specified by:
writeToItem in interface Transformer<com.vaadin.data.util.PropertysetItem>
Overrides:
writeToItem in class BasicTransformer<com.vaadin.data.util.PropertysetItem>

getRootItem

protected JcrNodeAdapter getRootItem()
Define the root Item used in order to set the SubNodes list.


getStoredChildNodes

protected List<javax.jcr.Node> getStoredChildNodes(JcrNodeAdapter parent)
Get all childNodes of parent passing the Predicate created by createPredicateToEvaluateChildNode() or
with type NodeTypes.ContentNode.NAME if the Predicate is null.


createPredicateToEvaluateChildNode

protected org.apache.jackrabbit.commons.predicate.Predicate createPredicateToEvaluateChildNode()
Create a Predicate used to evaluate the child node of the root to handle.
Only return child node that have a number name's.


getValueFromChildNode

protected Object getValueFromChildNode(javax.jcr.Node child)
Return a specific value from the child node.


setNewChildItem

protected void setNewChildItem(JcrNodeAdapter rootItem,
                               com.vaadin.data.util.PropertysetItem newValue)

setChildItemValue

protected void setChildItemValue(JcrNodeAdapter childItem,
                                 Object value)
Set the value as property to the childItem.


initializeChildItem

protected JcrNodeAdapter initializeChildItem(JcrNodeAdapter rootItem,
                                             javax.jcr.Node rootNode,
                                             String childName)
                                      throws javax.jcr.PathNotFoundException,
                                             javax.jcr.RepositoryException
Create a Child Item.
- if the related node already has a Child Node called 'childName', initialize the ChildItem based on this child Node.
- else create a new JcrNodeAdapter.

Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

handleRootitemAndParent

protected void handleRootitemAndParent(JcrNodeAdapter rootItem)
Handle the relation between parent and rootItem.
Typically, if rootItem would be a child of parentItem:

if (childItem.getChildren() != null && !childItem.getChildren().isEmpty()) { ((JcrNodeAdapter) parent).addChild(childItem); } else { ((JcrNodeAdapter) parent).removeChild(childItem); }


createChildItemName

protected String createChildItemName(Set<String> childNames,
                                     Object value,
                                     JcrNodeAdapter rootItem)
Basic Implementation that create child Nodes with increasing number as Name.


setChildValuePropertyName

public void setChildValuePropertyName(String newName)

getOrCreateChildNode

protected JcrNodeAdapter getOrCreateChildNode(String childNodeName,
                                              String childNodeType)
                                       throws javax.jcr.RepositoryException
Retrieve or create a child node as JcrNodeAdapter.

Throws:
javax.jcr.RepositoryException


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