Coverage Report - org.apache.tapestry.contrib.tree.simple.SimpleTreeDataModel
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleTreeDataModel
0%
0/26
0%
0/6
1.625
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.contrib.tree.simple;
 16  
 
 17  
 import java.io.Serializable;
 18  
 import java.util.Iterator;
 19  
 
 20  
 import javax.swing.tree.TreePath;
 21  
 
 22  
 import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
 23  
 import org.apache.tapestry.contrib.tree.model.ITreeNode;
 24  
 
 25  
 /**
 26  
  * @author ceco
 27  
  */
 28  
 public class SimpleTreeDataModel implements ITreeDataModel, Serializable
 29  
 {
 30  
 
 31  
     private static final long serialVersionUID = 9215832847660213349L;
 32  
 
 33  
     protected ITreeNode m_objRootNode;
 34  
 
 35  
     /**
 36  
      * Constructor for SimpleTreeDataModel.
 37  
      */
 38  
     public SimpleTreeDataModel(ITreeNode objRootNode)
 39  
     {
 40  0
         super();
 41  0
         m_objRootNode = objRootNode;
 42  0
     }
 43  
 
 44  
     /**
 45  
      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getRoot()
 46  
      */
 47  
     public Object getRoot()
 48  
     {
 49  0
         return m_objRootNode;
 50  
     }
 51  
 
 52  
     /**
 53  
      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getChildCount(Object)
 54  
      */
 55  
     public int getChildCount(Object objParent)
 56  
     {
 57  0
         ITreeNode objParentNode = (ITreeNode) objParent;
 58  
 
 59  0
         return objParentNode.getChildCount();
 60  
     }
 61  
 
 62  
     /**
 63  
      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getChildren(Object)
 64  
      */
 65  
     public Iterator getChildren(Object objParent)
 66  
     {
 67  0
         ITreeNode objParentNode = (ITreeNode) objParent;
 68  0
         return objParentNode.getChildren().iterator();
 69  
     }
 70  
 
 71  
     /**
 72  
      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getObject(Object)
 73  
      */
 74  
     public Object getObject(Object objUniqueKey)
 75  
     {
 76  0
         if (objUniqueKey != null)
 77  
         {
 78  0
             TreePath objPath = (TreePath) objUniqueKey;
 79  0
             return objPath.getLastPathComponent();
 80  
         }
 81  0
         return null;
 82  
     }
 83  
 
 84  
     /**
 85  
      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getUniqueKey(Object,
 86  
      *      Object)
 87  
      */
 88  
     public Object getUniqueKey(Object objTarget, Object objParentUniqueKey)
 89  
     {
 90  0
         TreePath objPath = (TreePath) objParentUniqueKey;
 91  0
         Object objTargetUID = null;
 92  0
         if (objPath != null)
 93  
         {
 94  0
             objTargetUID = objPath.pathByAddingChild(objTarget);
 95  
         }
 96  
         else
 97  
         {
 98  0
             objTargetUID = new TreePath(objTarget);
 99  
         }
 100  0
         return objTargetUID;
 101  
     }
 102  
 
 103  
     /**
 104  
      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#isAncestorOf(Object,
 105  
      *      Object)
 106  
      */
 107  
     public boolean isAncestorOf(Object objTargetUniqueKey,
 108  
             Object objParentUniqueKey)
 109  
     {
 110  0
         TreePath objParentPath = (TreePath) objParentUniqueKey;
 111  0
         TreePath objTargetPath = (TreePath) objTargetUniqueKey;
 112  0
         boolean bResult = objParentPath.isDescendant(objTargetPath);
 113  0
         return bResult;
 114  
     }
 115  
 
 116  
     /**
 117  
      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getParentUniqueKey
 118  
      */
 119  
     public Object getParentUniqueKey(Object objChildUniqueKey)
 120  
     {
 121  0
         TreePath objChildPath = (TreePath) objChildUniqueKey;
 122  0
         TreePath objParentPath = objChildPath.getParentPath();
 123  0
         if (objParentPath == null) return null;
 124  0
         return objParentPath.getLastPathComponent();
 125  
     }
 126  
 
 127  
 }