001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags.tree;
020:
021: import javax.servlet.ServletRequest;
022:
023: /**
024: * This is a concrete implementation of <code>ITreeRootElement</code>. It is a subclass of the
025: * <code>TreeElement</code> and is created for the root element when a tree is defined
026: * through JSP tags.
027: */
028: public class TreeRootElement extends TreeElement implements
029: ITreeRootElement {
030: private TreeElement _selectedNode; // The currently selected node
031: private TreeRenderState _trs; // The tree render state used by TreeRenderer
032: private InheritableState _state; // The tree's root inheritableState
033: private String _name = null; // The name of the tree
034: private String _rootNodeExpandedImage; // The image used when the root is expanded.
035: private String _rootNodeCollapsedImage; // The image used when the root is collapsed
036:
037: /**
038: * Default constructor for creating a simple tree.
039: */
040: public TreeRootElement() {
041: super ();
042: }
043:
044: /**
045: * Construct a new TreeElement with the specified parameters.
046: * @param expanded Should this node be expanded?
047: */
048: public TreeRootElement(String label, boolean expanded) {
049: super (label, expanded);
050: }
051:
052: /**
053: * Change the node that is selected. This is an optimization were the
054: * root node can track which node is currently selected so it can unselect
055: * that node instead of searching the whole tree to find the selected node.
056: * @param selectNode
057: */
058: public void changeSelected(String selectNode, ServletRequest request) {
059: _selectedNode = TreeHelpers.changeSelected(this , _selectedNode,
060: selectNode, request);
061: }
062:
063: /**
064: * Return the currently selected <code>TreeElement</code>. This method
065: * will return null if no element is currently selected.
066: *
067: * <p>Implementation Note: The method that changes the selected node based on the request,
068: * {@link TreeHelpers#processTreeRequest(String, TreeElement, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)},
069: * gets called during the processing of the {@link Tree} tag within a JSP. If the
070: * <code>getSelectedNode</code> method is called from an Action in a Page Flow Controller,
071: * the value of the selected node will have not yet been updated.</p>
072: *
073: * @return the currently selected node.
074: */
075: public TreeElement getSelectedNode() {
076: return _selectedNode;
077: }
078:
079: /**
080: * return the TreeRenderState for this tree.
081: * @return the <code>TreeRenderState</code>
082: */
083: public TreeRenderState getTreeRenderState() {
084: return _trs;
085: }
086:
087: /**
088: * Set the TreeRenderState
089: * @param trs
090: */
091: public void setTreeRenderState(TreeRenderState trs) {
092: _trs = trs;
093: }
094:
095: /**
096: * Property that returns the InheritableState that was set on the Tree.
097: * @return InheritableState
098: */
099: public InheritableState getInheritableState() {
100: return _state;
101: }
102:
103: /**
104: * Property that sets the InheritableState that is set on the Tree tag.
105: * @param state
106: */
107: public void setInheritableState(InheritableState state) {
108: _state = state;
109: }
110:
111: /**
112: * Returns the expanded image for the root node.
113: * @return the expanded image for the root.
114: */
115: public String getRootNodeExpandedImage() {
116: return _rootNodeExpandedImage;
117: }
118:
119: /**
120: * Sets the expanded image for the root node.
121: * @param rootNodeExpandedImage the name of the image to display. This will be searched
122: * for below the image root.
123: */
124: public void setRootNodeExpandedImage(String rootNodeExpandedImage) {
125: _rootNodeExpandedImage = rootNodeExpandedImage;
126: }
127:
128: /**
129: * Returns the collapsed image for the root node.
130: * @return the name of the collapsed image for the root.
131: */
132: public String getRootNodeCollapsedImage() {
133: return _rootNodeCollapsedImage;
134: }
135:
136: /**
137: * Sets the name of the collapsed image for the root node.
138: * @param rootNodeCollapsedImage the name of the collapsed image to display. This will be searched
139: * for below the image root.
140: */
141: public void setRootNodeCollapsedImage(String rootNodeCollapsedImage) {
142: _rootNodeCollapsedImage = rootNodeCollapsedImage;
143: }
144:
145: /**
146: * Set the ObjectName of the INameable object. This should only
147: * be set once. If it is called a second time an IllegalStateException
148: * should be thrown
149: * @param name the Object's name.
150: * @throws IllegalStateException if this method is called more than once for an object
151: */
152: public void setObjectName(String name) {
153: if (_name != null) {
154: throw new IllegalStateException(
155: "Attempt to set the ObjectName twice");
156: }
157: _name = name;
158: }
159:
160: /**
161: * Returns the ObjectName of the INameable object.
162: * @return the ObjectName.
163: */
164: public String getObjectName() {
165: return _name;
166: }
167: }
|