info.magnolia.ui.workbench.container
Class AbstractJcrContainer

java.lang.Object
  extended by info.magnolia.ui.workbench.container.AbstractContainer
      extended by info.magnolia.ui.workbench.container.AbstractJcrContainer
All Implemented Interfaces:
com.vaadin.data.Container, com.vaadin.data.Container.Indexed, com.vaadin.data.Container.ItemSetChangeNotifier, com.vaadin.data.Container.Ordered, com.vaadin.data.Container.Sortable, Serializable
Direct Known Subclasses:
FlatJcrContainer, HierarchicalJcrContainer

public abstract class AbstractJcrContainer
extends AbstractContainer
implements com.vaadin.data.Container.Sortable, com.vaadin.data.Container.Indexed, com.vaadin.data.Container.ItemSetChangeNotifier

Vaadin container that reads its items from a JCR repository. Implements a simple mechanism for lazy loading items from a JCR repository and a cache for items and item ids.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class info.magnolia.ui.workbench.container.AbstractContainer
AbstractContainer.ItemSetChangeEvent, AbstractContainer.PropertySetChangeEvent
 
Nested classes/interfaces inherited from interface com.vaadin.data.Container
com.vaadin.data.Container.Editor, com.vaadin.data.Container.Filter, com.vaadin.data.Container.Filterable, com.vaadin.data.Container.Hierarchical, com.vaadin.data.Container.Indexed, com.vaadin.data.Container.ItemSetChangeEvent, com.vaadin.data.Container.ItemSetChangeListener, com.vaadin.data.Container.ItemSetChangeNotifier, com.vaadin.data.Container.Ordered, com.vaadin.data.Container.PropertySetChangeEvent, com.vaadin.data.Container.PropertySetChangeListener, com.vaadin.data.Container.PropertySetChangeNotifier, com.vaadin.data.Container.SimpleFilterable, com.vaadin.data.Container.Sortable, com.vaadin.data.Container.Viewer
 
Field Summary
protected static String ASCENDING_KEYWORD
           
static int DEFAULT_CACHE_RATIO
           
static String DEFAULT_NODE_TYPE
          Node type to use if none is configured.
static int DEFAULT_PAGE_LENGTH
           
protected static String DESCENDING_KEYWORD
           
protected static String JCR_NAME_FUNCTION
           
protected static String ORDER_BY
           
static String PROPERTY_NAME_AND_UUID_SEPARATOR
          String separating a properties name and the uuid of its node.
protected static String SELECT_TEMPLATE
           
protected static String SELECTOR_NAME
           
protected static String WHERE_TEMPLATE_FOR_PATH
           
 
Constructor Summary
AbstractJcrContainer(WorkbenchDefinition workbenchDefinition)
           
 
Method Summary
 Object addItem()
           
 com.vaadin.data.Item addItem(Object itemId)
           
 Object addItemAfter(Object previousItemId)
           
 com.vaadin.data.Item addItemAfter(Object previousItemId, Object newItemId)
          *******************************
 Object addItemAt(int index)
           
 com.vaadin.data.Item addItemAt(int index, Object newItemId)
           
 void addItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
           
 void addListener(com.vaadin.data.Container.ItemSetChangeListener listener)
           
 void addSortableProperty(String sortableProperty)
           
protected  void clearItemIndexes()
           
protected  String constructJCRQuery(boolean considerSorting)
           
 boolean containsId(Object itemId)
           
protected  javax.jcr.query.QueryResult executeQuery(String statement, String language, long limit, long offset)
           
protected  Set<javax.jcr.nodetype.NodeType> findSearchableNodeTypes()
           
 void fireItemSetChange()
           
 Object firstItemId()
           
 int getCacheRatio()
           
 com.vaadin.data.Property<?> getContainerProperty(Object itemId, Object propertyId)
           
protected  int getCurrentOffset()
           
protected  OrderBy getDefaultOrderBy(String property)
           
 Object getIdByIndex(int index)
           
 com.vaadin.data.Item getItem(Object itemId)
           
 Collection<String> getItemIds()
           
 List<?> getItemIds(int startIndex, int numberOfItems)
           
protected  Map<Long,String> getItemIndexes()
           
 javax.jcr.Item getJcrItem(Object itemId)
           
protected  String getJcrNameOrderByFunction()
           
protected  String getMainNodeType()
          Deprecated. since 5.1. All node types declared in the workbench definition are equal, meaning that their position doesn't matter when it comes to which ones are used in a query. The discriminating factor is the hideInList boolean property. If that property is true, then the node will be excluded from the query.
 int getPageLength()
           
protected  String getQuerySelectStatement()
           
protected  String getQueryWhereClause()
           
protected  String getQueryWhereClauseNodeTypes()
           
protected  String getQueryWhereClauseWorkspacePath()
           
 Set<javax.jcr.nodetype.NodeType> getSearchableNodeTypes()
           
 List<String> getSortableContainerPropertyIds()
           
 WorkbenchDefinition getWorkbenchDefinition()
           
 String getWorkspace()
           
protected  void handleRepositoryException(org.slf4j.Logger logger, String message, javax.jcr.RepositoryException repositoryException)
          Central method for uniform treatment of RepositoryExceptions in JcrContainers.
 int indexOfId(Object itemId)
          *****************************************
 boolean isFirstId(Object itemId)
           
 boolean isLastId(Object itemId)
           
 Object lastItemId()
           
 Object nextItemId(Object itemId)
          *****************************************
 Object prevItemId(Object itemId)
           
 void refresh()
          Refreshes the container - clears all caches and resets size and offset.
 boolean removeAllItems()
           
 boolean removeItem(Object itemId)
           
 void removeItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
           
 void removeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
           
protected  void resetOffset()
           
 void setCacheRatio(int cacheRatio)
           
 void setPageLength(int pageLength)
           
protected  void setSize(int size)
           
 int size()
          Gets the number of visible Items in the Container.
 void sort(Object[] propertyId, boolean[] ascending)
          ******************************************
 void updateSize()
           
 
Methods inherited from class info.magnolia.ui.workbench.container.AbstractContainer
addContainerProperty, getContainerPropertyIds, getType, removeContainerProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.data.Container
addContainerProperty, getContainerPropertyIds, getType, removeContainerProperty
 

Field Detail

DEFAULT_PAGE_LENGTH

public static final int DEFAULT_PAGE_LENGTH
See Also:
Constant Field Values

DEFAULT_CACHE_RATIO

public static final int DEFAULT_CACHE_RATIO
See Also:
Constant Field Values

PROPERTY_NAME_AND_UUID_SEPARATOR

public static final String PROPERTY_NAME_AND_UUID_SEPARATOR
String separating a properties name and the uuid of its node.

See Also:
Constant Field Values

DEFAULT_NODE_TYPE

public static final String DEFAULT_NODE_TYPE
Node type to use if none is configured.

See Also:
Constant Field Values

SELECTOR_NAME

protected static final String SELECTOR_NAME
See Also:
Constant Field Values

SELECT_TEMPLATE

protected static final String SELECT_TEMPLATE
See Also:
Constant Field Values

WHERE_TEMPLATE_FOR_PATH

protected static final String WHERE_TEMPLATE_FOR_PATH
See Also:
Constant Field Values

ORDER_BY

protected static final String ORDER_BY
See Also:
Constant Field Values

ASCENDING_KEYWORD

protected static final String ASCENDING_KEYWORD
See Also:
Constant Field Values

DESCENDING_KEYWORD

protected static final String DESCENDING_KEYWORD
See Also:
Constant Field Values

JCR_NAME_FUNCTION

protected static final String JCR_NAME_FUNCTION
See Also:
Constant Field Values
Constructor Detail

AbstractJcrContainer

public AbstractJcrContainer(WorkbenchDefinition workbenchDefinition)
Method Detail

addSortableProperty

public void addSortableProperty(String sortableProperty)

getWorkbenchDefinition

public WorkbenchDefinition getWorkbenchDefinition()

addItemSetChangeListener

public void addItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
Specified by:
addItemSetChangeListener in interface com.vaadin.data.Container.ItemSetChangeNotifier

addListener

public void addListener(com.vaadin.data.Container.ItemSetChangeListener listener)
Specified by:
addListener in interface com.vaadin.data.Container.ItemSetChangeNotifier

removeItemSetChangeListener

public void removeItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
Specified by:
removeItemSetChangeListener in interface com.vaadin.data.Container.ItemSetChangeNotifier

removeListener

public void removeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
Specified by:
removeListener in interface com.vaadin.data.Container.ItemSetChangeNotifier

fireItemSetChange

public void fireItemSetChange()

getItemIndexes

protected Map<Long,String> getItemIndexes()

getPageLength

public int getPageLength()

setPageLength

public void setPageLength(int pageLength)

getCacheRatio

public int getCacheRatio()

setCacheRatio

public void setCacheRatio(int cacheRatio)

getJcrItem

public javax.jcr.Item getJcrItem(Object itemId)

getItem

public com.vaadin.data.Item getItem(Object itemId)
Specified by:
getItem in interface com.vaadin.data.Container

getItemIds

public Collection<String> getItemIds()
Specified by:
getItemIds in interface com.vaadin.data.Container

getContainerProperty

public com.vaadin.data.Property<?> getContainerProperty(Object itemId,
                                                        Object propertyId)
Specified by:
getContainerProperty in interface com.vaadin.data.Container

size

public int size()
Gets the number of visible Items in the Container.

Specified by:
size in interface com.vaadin.data.Container

containsId

public boolean containsId(Object itemId)
Specified by:
containsId in interface com.vaadin.data.Container

addItem

public com.vaadin.data.Item addItem(Object itemId)
                             throws UnsupportedOperationException
Specified by:
addItem in interface com.vaadin.data.Container
Throws:
UnsupportedOperationException

addItem

public Object addItem()
               throws UnsupportedOperationException
Specified by:
addItem in interface com.vaadin.data.Container
Throws:
UnsupportedOperationException

removeAllItems

public boolean removeAllItems()
                       throws UnsupportedOperationException
Specified by:
removeAllItems in interface com.vaadin.data.Container
Throws:
UnsupportedOperationException

indexOfId

public int indexOfId(Object itemId)
*****************************************

Specified by:
indexOfId in interface com.vaadin.data.Container.Indexed

getIdByIndex

public Object getIdByIndex(int index)
Specified by:
getIdByIndex in interface com.vaadin.data.Container.Indexed

nextItemId

public Object nextItemId(Object itemId)
*****************************************

Specified by:
nextItemId in interface com.vaadin.data.Container.Ordered

prevItemId

public Object prevItemId(Object itemId)
Specified by:
prevItemId in interface com.vaadin.data.Container.Ordered

firstItemId

public Object firstItemId()
Specified by:
firstItemId in interface com.vaadin.data.Container.Ordered

lastItemId

public Object lastItemId()
Specified by:
lastItemId in interface com.vaadin.data.Container.Ordered

isFirstId

public boolean isFirstId(Object itemId)
Specified by:
isFirstId in interface com.vaadin.data.Container.Ordered

isLastId

public boolean isLastId(Object itemId)
Specified by:
isLastId in interface com.vaadin.data.Container.Ordered

sort

public void sort(Object[] propertyId,
                 boolean[] ascending)
******************************************

Specified by:
sort in interface com.vaadin.data.Container.Sortable

getSortableContainerPropertyIds

public List<String> getSortableContainerPropertyIds()
Specified by:
getSortableContainerPropertyIds in interface com.vaadin.data.Container.Sortable

removeItem

public boolean removeItem(Object itemId)
                   throws UnsupportedOperationException
Specified by:
removeItem in interface com.vaadin.data.Container
Throws:
UnsupportedOperationException

addItemAfter

public com.vaadin.data.Item addItemAfter(Object previousItemId,
                                         Object newItemId)
                                  throws UnsupportedOperationException
*******************************

Specified by:
addItemAfter in interface com.vaadin.data.Container.Ordered
Throws:
UnsupportedOperationException

addItemAt

public com.vaadin.data.Item addItemAt(int index,
                                      Object newItemId)
                               throws UnsupportedOperationException
Specified by:
addItemAt in interface com.vaadin.data.Container.Indexed
Throws:
UnsupportedOperationException

addItemAt

public Object addItemAt(int index)
                 throws UnsupportedOperationException
Specified by:
addItemAt in interface com.vaadin.data.Container.Indexed
Throws:
UnsupportedOperationException

addItemAfter

public Object addItemAfter(Object previousItemId)
                    throws UnsupportedOperationException
Specified by:
addItemAfter in interface com.vaadin.data.Container.Ordered
Throws:
UnsupportedOperationException

constructJCRQuery

protected final String constructJCRQuery(boolean considerSorting)
Parameters:
considerSorting - an optional ORDER BY is added if this parameter is true. Sorting options can be configured in the WorkbenchDefinition.
Returns:
a string representing a JCR statement to retrieve this container's items. It creates a JCR query in the form select * from [nt:base] as selectorName [WHERE] [ORDER BY]".

Subclasses can customize the optional WHERE clause by overriding getQueryWhereClause() or, at a more fine-grained level, getQueryWhereClauseNodeTypes() and getQueryWhereClauseWorkspacePath().

A restriction on the node types to be searched for can be applied via getQueryWhereClauseNodeTypes().


getDefaultOrderBy

protected OrderBy getDefaultOrderBy(String property)
Returns:
an OrderBy object for the passed in property to be used for the default order by clause.

getJcrNameOrderByFunction

protected String getJcrNameOrderByFunction()
Returns:
the jcr function used to sort the node name (or jcr name property) column. By default it's JCR_NAME_FUNCTION.

getQueryWhereClause

protected String getQueryWhereClause()
Returns:
the JCR query where clause to select only node types which are not hidden in list and nodes under the path configured in the workspace as String - if the latter is not configured return a blank string so that all nodes are considered.
See Also:
getQueryWhereClauseNodeTypes(), getQueryWhereClauseWorkspacePath()

getQueryWhereClauseNodeTypes

protected String getQueryWhereClauseNodeTypes()
Returns:
a String containing the node types to be displayed in a list view and searched for in a query. All node types declared in a workbench definition are returned unless their hideInList property is true or the node is of type mgnl:folder (custom implementations of this method may still decide to display folders). Assuming a node types declaration like the following
 ...
 + workbench
  + nodeTypes
   + foo
    * name = nt:foo
   + bar
    * name = nt:bar
    * hideInList = true
   + baz (a mixin type)
    * name = nt:baz
 ...
 
this method will return the following string [jcr:primaryType] = 'nt:foo' or [jcr:mixinTypes] = 'baz'. This will eventually be used to restrict the node types to be displayed in list views and searched for in search views, i.e. select * from [nt:base] where ([jcr:primaryType] = 'nt:foo' or [jcr:mixinTypes] = 'baz').
See Also:
findSearchableNodeTypes()

getQueryWhereClauseWorkspacePath

protected final String getQueryWhereClauseWorkspacePath()
Returns:
if WorkbenchDefinition.getPath() is not null or root ("/"), an ISDESCENDATNODE constraint narrowing the scope of search under the configured path, else an empty string.

getQuerySelectStatement

protected String getQuerySelectStatement()
Returns:
a SELECT statement whose node type is nt:base. Can be customized by subclasses to utilize other item types, i.e. select * from [my:fancytype]. Used internally by constructJCRQuery(boolean).

getMainNodeType

@Deprecated
protected String getMainNodeType()
Deprecated. since 5.1. All node types declared in the workbench definition are equal, meaning that their position doesn't matter when it comes to which ones are used in a query. The discriminating factor is the hideInList boolean property. If that property is true, then the node will be excluded from the query.


updateSize

public final void updateSize()
See Also:
getPage().

getItemIds

public List<?> getItemIds(int startIndex,
                          int numberOfItems)
Specified by:
getItemIds in interface com.vaadin.data.Container.Indexed

getWorkspace

public String getWorkspace()

getSearchableNodeTypes

public Set<javax.jcr.nodetype.NodeType> getSearchableNodeTypes()

refresh

public void refresh()
Refreshes the container - clears all caches and resets size and offset. Does NOT remove sorting or filtering rules!


resetOffset

protected void resetOffset()

clearItemIndexes

protected void clearItemIndexes()

getCurrentOffset

protected int getCurrentOffset()

setSize

protected void setSize(int size)

executeQuery

protected javax.jcr.query.QueryResult executeQuery(String statement,
                                                   String language,
                                                   long limit,
                                                   long offset)
                                            throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

handleRepositoryException

protected void handleRepositoryException(org.slf4j.Logger logger,
                                         String message,
                                         javax.jcr.RepositoryException repositoryException)
Central method for uniform treatment of RepositoryExceptions in JcrContainers.

Parameters:
logger - logger to be used - passed in so subclasses can still user their proper logger
message - message to be used in the handling
repositoryException - exception to be handled

findSearchableNodeTypes

protected Set<javax.jcr.nodetype.NodeType> findSearchableNodeTypes()
Returns:
a Set of searchable NodeTypes. A searchable node type is defined as follows
  • It is a primary or mixin node type configured under /modules/mymodule/apps/myapp/subApps/browser/workbench/nodeTypes
  • It is not hidden in list and search views (property hideInList=true). By default nodes are not hidden.
  • If not strict (property strict=false), then its subtypes (if any) are searchable too. By default nodes are not defined as strict.
  • Subtypes beginning with jcr:, nt:, mix:, rep: are not taken into account.


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