Coverage Report - org.equanda.tapestry5.components.TreeTable
 
Classes in this File Line Coverage Branch Coverage Complexity
TreeTable
0%
0/27
0%
0/12
0
 
 1  
 /**
 2  
  * This file is part of the equanda project.
 3  
  *
 4  
  * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 7  
  *
 8  
  * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
 9  
  * ANY KIND, either express or implied. See the License for the specific language governing rights and
 10  
  * limitations under the License.
 11  
  *
 12  
  * Alternatively, the contents of this file may be used under the terms of
 13  
  * either the GNU General Public License Version 2 or later (the "GPL"), or
 14  
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 15  
  * in which case the provisions of the GPL or the LGPL are applicable instead
 16  
  * of those above. If you wish to allow use of your version of this file only
 17  
  * under the terms of either the GPL or the LGPL, and not to allow others to
 18  
  * use your version of this file under the terms of the MPL, indicate your
 19  
  * decision by deleting the provisions above and replace them with the notice
 20  
  * and other provisions required by the GPL or the LGPL. If you do not delete
 21  
  * the provisions above, a recipient may use your version of this file under
 22  
  * the terms of any one of the MPL, the GPL or the LGPL.
 23  
  */
 24  
 
 25  
 package org.equanda.tapestry5.components;
 26  
 
 27  
 import org.apache.tapestry5.Block;
 28  
 import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
 29  
 import org.apache.tapestry5.annotations.IncludeStylesheet;
 30  
 import org.apache.tapestry5.annotations.Parameter;
 31  
 import org.apache.tapestry5.annotations.SupportsInformalParameters;
 32  
 import org.equanda.tapestry5.data.FlattenedTree;
 33  
 import org.equanda.tapestry5.data.Tree;
 34  
 
 35  
 import java.util.ArrayList;
 36  
 import java.util.List;
 37  
 
 38  
 /**
 39  
  * TreeTable is a tapestry 5 component class. It is based upon <a href="http://sstree.tigris.org/">sstree</a>
 40  
  *
 41  
  * @author Geert Mergan
 42  
  * @author <a href="mailto:joachim@progs.be">Joachim Van der Auwera</a>
 43  
  */
 44  
 @SupportsInformalParameters
 45  
 @IncludeStylesheet( "classpath:/org/equanda/tapestry5/resources/treetable.css" )
 46  
 @IncludeJavaScriptLibrary( "classpath:/org/equanda/tapestry5/resources/treetable.js" )
 47  0
 public class TreeTable
 48  
 {
 49  
     /** Defines the source Tree to walk over. */
 50  
     @Parameter( required = true )
 51  
     private List<Tree> tree;
 52  
 
 53  
     @Parameter( required = true )
 54  
     private Tree value;
 55  
 
 56  
     @Parameter( required = true )
 57  
     private Block content;
 58  
 
 59  
     private List<FlattenedTree> flattenedTreeList;
 60  
 
 61  
     /** Current node of the tree. */
 62  
     private FlattenedTree flatValue;
 63  
 
 64  
     public Block getContent()
 65  
     {
 66  0
         return content;
 67  
     }
 68  
 
 69  
 
 70  
     public void setContent( Block content )
 71  
     {
 72  0
         this.content = content;
 73  0
     }
 74  
 
 75  
     public FlattenedTree getFlatValue()
 76  
     {
 77  0
         return flatValue;
 78  
     }
 79  
 
 80  
     public void setFlatValue( FlattenedTree flatValue )
 81  
     {
 82  0
         this.flatValue = flatValue;
 83  0
         value = flatValue.getTree();
 84  0
     }
 85  
 
 86  
     public List<FlattenedTree> getList()
 87  
     {
 88  0
         if ( null == flattenedTreeList )
 89  
         {
 90  0
             flattenedTreeList = new ArrayList<FlattenedTree>();
 91  0
             if ( null != tree )
 92  
             {
 93  0
                 int i = 0;
 94  0
                 for ( Tree node : tree )
 95  
                 {
 96  0
                     buildSourceList( flattenedTreeList, node, 0, Integer.toString( i ) );
 97  0
                     i++;
 98  
                 }
 99  
             }
 100  
         }
 101  0
         return flattenedTreeList;
 102  
     }
 103  
 
 104  
     public void setList( List<FlattenedTree> source )
 105  
     {
 106  0
         this.flattenedTreeList = source;
 107  0
     }
 108  
 
 109  
     private void buildSourceList( List<FlattenedTree> list, Tree treeNode, int depth, String dotId )
 110  
     {
 111  0
         list.add( new FlattenedTree( treeNode, depth, dotId ) );
 112  0
         List<Tree> children = treeNode.getChildren();
 113  0
         if ( children != null )
 114  
         {
 115  0
             int i = 0;
 116  0
             for ( Tree node : children )
 117  
             {
 118  
                 // TODO check if stopping recursion works.. we probably have to forsee equals and hashCode method on FlattenedTree
 119  0
                 if ( !list.contains( node ) )
 120  
                 {
 121  0
                     buildSourceList( list, node, depth + 1, dotId + "-" + i );
 122  0
                     i++;
 123  
                 }
 124  
             }
 125  
         }
 126  0
     }
 127  
 }