KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > tree > TreeRootElement


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.tree;
19
20 import javax.servlet.ServletRequest JavaDoc;
21
22 /**
23  * This is a concrete implementation of <code>ITreeRootElement</code>. It is a subclass of the
24  * <code>TreeElement</code> and is created for the root element when a tree is defined
25  * through JSP tags.
26  */

27 public class TreeRootElement extends TreeElement implements ITreeRootElement
28 {
29     private TreeElement _selectedNode; // The currently selected node
30
private TreeRenderState _trs; // The tree render state used by TreeRenderer
31
private InheritableState _state; // The tree's root inheritableState
32
private String JavaDoc _name = null; // The name of the tree
33
private String JavaDoc _rootNodeExpandedImage; // The image used when the root is expanded.
34
private String JavaDoc _rootNodeCollapsedImage; // The image used when the root is collapsed
35

36
37     /**
38      * Default constructor for creating a simple tree.
39      */

40     public TreeRootElement()
41     {
42         super();
43     }
44
45     /**
46      * Construct a new TreeElement with the specified parameters.
47      * @param expanded Should this node be expanded?
48      */

49     public TreeRootElement(String JavaDoc label, boolean expanded)
50     {
51         super(label, expanded);
52     }
53
54     /**
55      * Change the node that is selected. This is an optimization were the
56      * root node can track which node is currently selected so it can unselect
57      * that node instead of searching the whole tree to find the selected node.
58      * @param selectNode
59      */

60     public void changeSelected(String JavaDoc selectNode, ServletRequest JavaDoc request)
61     {
62         _selectedNode = TreeHelpers.changeSelected(this, _selectedNode, selectNode, request);
63     }
64
65     /**
66      * Return the currently selected <code>TreeElement</code>. This method
67      * will return null if no element is currently selected.
68      *
69      * <p>Implementation Note: The method that changes the selected node based on the request,
70      * {@link TreeHelpers#processTreeRequest(String, TreeElement, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)},
71      * gets called during the processing of the {@link Tree} tag within a JSP. If the
72      * <code>getSelectedNode</code> method is called from an Action in a Page Flow Controller,
73      * the value of the selected node will have not yet been updated.</p>
74      *
75      * @return the currently selected node.
76      */

77     public TreeElement getSelectedNode()
78     {
79         return _selectedNode;
80     }
81
82     /**
83      * return the TreeRenderState for this tree.
84      * @return the <code>TreeRenderState</code>
85      */

86     public TreeRenderState getTreeRenderState()
87     {
88         return _trs;
89     }
90
91     /**
92      * Set the TreeRenderState
93      * @param trs
94      */

95     public void setTreeRenderState(TreeRenderState trs)
96     {
97         _trs = trs;
98     }
99
100     /**
101      * Property that returns the InheritableState that was set on the Tree.
102      * @return InheritableState
103      */

104     public InheritableState getInheritableState()
105     {
106         return _state;
107     }
108
109     /**
110      * Property that sets the InheritableState that is set on the Tree tag.
111      * @param state
112      */

113     public void setInheritableState(InheritableState state)
114     {
115         _state = state;
116     }
117
118     /**
119      * Returns the expanded image for the root node.
120      * @return the expanded image for the root.
121      */

122     public String JavaDoc getRootNodeExpandedImage()
123     {
124         return _rootNodeExpandedImage;
125     }
126
127     /**
128      * Sets the expanded image for the root node.
129      * @param rootNodeExpandedImage the name of the image to display. This will be searched
130      * for below the image root.
131      */

132     public void setRootNodeExpandedImage(String JavaDoc rootNodeExpandedImage)
133     {
134         _rootNodeExpandedImage = rootNodeExpandedImage;
135     }
136
137     /**
138      * Returns the collapsed image for the root node.
139      * @return the name of the collapsed image for the root.
140      */

141     public String JavaDoc getRootNodeCollapsedImage()
142     {
143         return _rootNodeCollapsedImage;
144     }
145
146     /**
147      * Sets the name of the collapsed image for the root node.
148      * @param rootNodeCollapsedImage the name of the collapsed image to display. This will be searched
149      * for below the image root.
150      */

151     public void setRootNodeCollapsedImage(String JavaDoc rootNodeCollapsedImage)
152     {
153         _rootNodeCollapsedImage = rootNodeCollapsedImage;
154     }
155
156
157     /**
158      * Set the ObjectName of the INameable object. This should only
159      * be set once. If it is called a second time an IllegalStateException
160      * should be thrown
161      * @param name the Object's name.
162      * @throws IllegalStateException if this method is called more than once for an object
163      */

164     public void setObjectName(String JavaDoc name)
165     {
166         if (_name != null) {
167             throw new IllegalStateException JavaDoc("Attempt to set the ObjectName twice");
168         }
169         _name = name;
170     }
171
172     /**
173      * Returns the ObjectName of the INameable object.
174      * @return the ObjectName.
175      */

176     public String JavaDoc getObjectName()
177     {
178         return _name;
179     }
180 }
181
Popular Tags