KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.openedit.webui.tree;
14
15 import java.util.List JavaDoc;
16
17
18 /**
19  * This class is a Web tree, which can render a <code>{@link WebTreeModel}</code> to an XML
20  * document.
21  *
22  * @author Eric Galluzzo
23  */

24 public class WebTree
25 {
26     protected String JavaDoc fieldName;
27     protected String JavaDoc fieldId;
28     
29     protected WebTreeModel fieldModel;
30     protected TreeRenderer fieldTreeRenderer;
31
32     public WebTree()
33     {
34     }
35
36     /**
37      * Create a new WebTree which listens to the given model.
38      *
39      * @param inModel DOCUMENT ME!
40      */

41     public WebTree(WebTreeModel inModel)
42     {
43         setModel(inModel);
44         //expandNode(getModel().getRoot());
45
}
46
47     public boolean isEmpty()
48     {
49         if ((getModel() == null) || (getModel().getChildCount(getModel().getRoot()) == 0))
50         {
51             return true;
52         }
53         else
54         {
55             return false;
56         }
57     }
58
59     /**
60      * Sets the model.
61      *
62      * @param model The model to set
63      */

64     public void setModel(WebTreeModel model)
65     {
66         fieldModel = model;
67         if ( fieldModel != null && fieldTreeRenderer != null)
68         {
69             getTreeRenderer().expandNode( fieldModel.getRoot() );
70         }
71     }
72
73     /**
74      * Gets the model.
75      *
76      * @return Returns a WebTreeModel
77      */

78     public WebTreeModel getModel()
79     {
80         if (fieldModel == null)
81         {
82             fieldModel = new DefaultWebTreeModel();
83         }
84
85         return fieldModel;
86     }
87
88     public Object JavaDoc getChildChildren(int inCount)
89     {
90         List JavaDoc children = getModel().getChildren(getModel().getRoot() );
91         if( children.size() < inCount)
92         {
93             Object JavaDoc parent = children.get(inCount);
94             return getModel().getChildren(parent);
95         }
96         return null;
97     }
98     
99     
100     
101     /**
102      * DOCUMENT ME!
103      *
104      * @param inName
105      */

106     public void setName(String JavaDoc inName)
107     {
108         fieldName = inName;
109     }
110
111     /**
112      * DOCUMENT ME!
113      *
114      * @return
115      */

116     public String JavaDoc getName()
117     {
118         if (fieldName == null)
119         {
120             fieldName = "WebTree";
121         }
122
123         return fieldName;
124     }
125
126     /**
127      * DOCME
128      *
129      * @return DOCME
130      */

131     public String JavaDoc renderAsJavaScript()
132     {
133         TreeRenderer renderer = getTreeRenderer();
134         return renderer.renderAsString();
135     }
136
137     public TreeRenderer getTreeRenderer()
138     {
139         if (fieldTreeRenderer == null)
140         {
141             fieldTreeRenderer = new WebTreeNodeTreeRenderer(this);
142         }
143         return fieldTreeRenderer;
144     }
145
146     public void setTreeRenderer(TreeRenderer inTreeRenderer)
147     {
148         fieldTreeRenderer = inTreeRenderer;
149         if ( fieldModel != null && inTreeRenderer != null)
150         {
151             getTreeRenderer().expandNode( getModel().getRoot() );
152         }
153
154     }
155
156     public String JavaDoc toString()
157     {
158         return getTreeRenderer().renderAsString();
159     }
160
161     public String JavaDoc getId()
162     {
163         return fieldId;
164     }
165
166     public void setId(String JavaDoc inId)
167     {
168         fieldId = inId;
169     }
170 }
171
Popular Tags