com.arsdigita.kernel.ui
Class DataQueryTreeModel

java.lang.Object
  extended bycom.arsdigita.kernel.ui.DataQueryTreeModel
All Implemented Interfaces:
TreeModel
Direct Known Subclasses:
CategoryTreeModelLite, SiteNodeTreeModel

public class DataQueryTreeModel
extends Object
implements TreeModel

A generic tree model for representing data base backed trees in an efficient manner. The number of queries is proportional to the number of branches in the tree, rather than the total number of nodes. All that is required to use this class are two custom data queries, the names of which will be passed into the constructor. The first one is used to pull out the name, id and number of children for the root node. The following example shows an example implementation for category tree, which should be customized to suit your data model.

 query getRootCategory {
     do {
        select g.name,
               g.category_id,
               count(sd.category_id) as sub_count
        from cat_categories g,
             cat_category_category_map sd
        where g.category_id = :objectID
          and sd.category_id(+) = g.category_id
        group by g.name, g.category_id
    } map {
        id = g.category_id;
        name = g.name;
        nchild = sub_count;
    }
 }
 
The second data query does a similar task, but for *all* children of a particular node. Again the following example for categories can be customized by changing the table names:
 query getSubCategories {
     do {
         select g.name,
                g.category_id,
                count(sd2.category_id) as sub_count
         from cat_categories g,
              cat_category_category_map sd1,
              cat_category_category_map sd2
         where sd1.category_id = :objectID
           and g.category_id = sd1.related_category_id
           and sd2.category_id(+) = sd1.related_category_id
         group by g.name, g.category_id
     } map {
         id = g.category_id;
         name = g.name;
         nchild = sub_count;
     }
 }
 

Version:
$Id: //core-platform/dev/src/com/arsdigita/kernel/ui/DataQueryTreeModel.java#11 $
Author:
Daniel Berrange

Field Summary
static String versionId
           
 
Constructor Summary
DataQueryTreeModel(BigDecimal root, String getRootCategory, String getSubCategories)
          Constructor, which takes in the root Category.
DataQueryTreeModel(String getRootCategory, String getSubCategories)
           
 
Method Summary
 Iterator getChildren(TreeNode node, PageState data)
          Obtains all the children of the node as an iterator, returning CategoryTreeNodeLites.
protected  DataQueryTreeIterator getDataQueryTreeIterator(DataQueryTreeNode node, String getSubCategories)
           
 TreeNode getRoot(PageState state)
          Obtain the root node of the tree, passing in PageState for permissioning purposes
 boolean hasChildren(TreeNode node, PageState state)
          Indicates whether the specified tree node has children.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

DataQueryTreeModel

public DataQueryTreeModel(String getRootCategory,
                          String getSubCategories)

DataQueryTreeModel

public DataQueryTreeModel(BigDecimal root,
                          String getRootCategory,
                          String getSubCategories)
Constructor, which takes in the root Category.

Parameters:
root - the object id of the root category
getRootCategory - the data query name for root category
getSubCategories - the data query name for sub categories
Method Detail

getChildren

public Iterator getChildren(TreeNode node,
                            PageState data)
Obtains all the children of the node as an iterator, returning CategoryTreeNodeLites.

Specified by:
getChildren in interface TreeModel
Parameters:
data - the PageState to use for permissioning purposes
Returns:
an iterator of child TreeNodes.

hasChildren

public boolean hasChildren(TreeNode node,
                           PageState state)
Indicates whether the specified tree node has children.

Specified by:
hasChildren in interface TreeModel
Returns:
an iterator of child TreeNodes.

getRoot

public TreeNode getRoot(PageState state)
Description copied from interface: TreeModel
Obtain the root node of the tree, passing in PageState for permissioning purposes

Specified by:
getRoot in interface TreeModel

getDataQueryTreeIterator

protected DataQueryTreeIterator getDataQueryTreeIterator(DataQueryTreeNode node,
                                                         String getSubCategories)


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC