KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > webui > tree > WebTreeNodeTreeRenderer


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 /*
14  * Created on May 29, 2003
15  *
16  * Render a JavaScript representation of the web tree.
17  */

18 package com.openedit.webui.tree;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * DOCUMENT ME!
25  *
26  * @author Matt Avery
27  */

28 public class WebTreeNodeTreeRenderer extends BaseTreeRenderer
29 {
30     protected boolean fieldFriendlyNames = false;
31     
32     public WebTreeNodeTreeRenderer(WebTree inWebTree)
33     {
34         super( inWebTree );
35     }
36
37     public boolean isFriendlyNames()
38     {
39         return fieldFriendlyNames;
40     }
41
42     public void setFriendlyNames(boolean inFriendlyNames)
43     {
44         fieldFriendlyNames = inFriendlyNames;
45     }
46
47     /* (non-javadoc)
48      * @see com.openedit.webui.tree.BaseTreeRenderer#toName(java.lang.Object)
49      */

50     public String JavaDoc toName(Object JavaDoc inNode)
51     {
52         DefaultWebTreeNode node = (DefaultWebTreeNode)inNode;
53         String JavaDoc name = node.getName();
54         if( isFriendlyNames())
55         {
56             name = name.replace('_', ' ');
57             name = name.substring(0,1).toUpperCase() + name.substring(1);
58                 
59             int p = name.lastIndexOf('.');
60             if ( p > 0 )
61             {
62                 name = name.substring(0,p);
63             }
64         }
65         return name;
66     }
67
68     /* (non-javadoc)
69      * @see com.openedit.webui.tree.BaseTreeRenderer#toUrl(java.lang.Object)
70      */

71     public String JavaDoc toUrl(Object JavaDoc inNode)
72     {
73         DefaultWebTreeNode node = (DefaultWebTreeNode)inNode;
74
75         return node.getURL();
76     }
77
78     /* (non-javadoc)
79      * @see com.openedit.webui.tree.BaseTreeRenderer#toId(java.lang.Object)
80      */

81     public String JavaDoc toId(Object JavaDoc inNode)
82     {
83         DefaultWebTreeNode node = (DefaultWebTreeNode)inNode;
84
85         return node.getID();
86     }
87
88     public void expandAll(Object JavaDoc inRoot)
89     {
90         expandNode(inRoot);
91         List JavaDoc children = getWebTree().getModel().getChildren(inRoot);
92         for (Iterator JavaDoc iterator = children.iterator(); iterator.hasNext();)
93         {
94             Object JavaDoc object = (Object JavaDoc) iterator.next();
95             expandAll(object);
96         }
97     }
98
99 }
100
Popular Tags