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 org.apache.beehive.netui.tags.AbstractSimpleTag;
022: import org.apache.beehive.netui.util.logging.Logger;
023:
024: import javax.servlet.jsp.JspException;
025:
026: /**
027: * @jsptagref.tagdescription Set an attribute on the tree.
028: * @example The following example shows a <netui:tree> tag with both a
029: * child <netui:treeLabel> and <netui:treeHtmlAttribute> tag that form the
030: * label for the root folder of the tree. The <netui:treeHtmlAttribute>
031: * outputs the attribute <code>name="A1"</code> on the anchor element used for
032: * the selection link of the tree item.
033: *
034: * <pre> <netui:tree dataSource="pageFlow.myTree" selectionAction="postback" tagId="myTree">
035: * <netui:treeItem expanded="true" >
036: * <netui:treeLabel>Root Folder</netui:treeLabel>
037: <netui:treeHtmlAttribute attribute="name" value="A1" onSelectionLink="true"/>
038: * </netui:treeItem>
039: * </netui:tree></pre>
040: * @netui:tag name="treeHtmlAttribute" body-content="empty" description="Set an attribute on the tree."
041: * @see org.apache.beehive.netui.tags.tree.Tree
042: * @see org.apache.beehive.netui.tags.tree.TreeElement
043: */
044: public class TreeHtmlAttribute extends AbstractSimpleTag {
045: private static final Logger logger = Logger
046: .getInstance(TreeHtmlAttribute.class);
047:
048: TreeHtmlAttributeInfo _info = new TreeHtmlAttributeInfo();
049:
050: /**
051: * Return the name of the Tag.
052: */
053: public String getTagName() {
054: return "TreeHtmlAttribute";
055: }
056:
057: /**
058: * Sets the name of the attribute. This must be in the proper HTML Attribute form. For example,
059: * "onmouseclick" or "href".
060: * @param attr the name of the HTML attribute.
061: * @jsptagref.attributedescription Sets the name of the attribute. This must be in the proper HTML Attribute form. For example,
062: * "onmouseclick" or "href".
063: * @jsptagref.databindable false
064: * @jsptagref.attributesyntaxvalue <i>string</i>
065: * @netui:attribute required="true"
066: * description="Sets the name of the attribute."
067: */
068: public void setAttribute(String attr) {
069: _info.setAttribute(attr);
070: }
071:
072: /**
073: * Sets HTML attribute value.
074: * @param value The value of the HTML Attribute.
075: * @jsptagref.attributedescription Sets the HTML attribute value.
076: * @jsptagref.databindable true
077: * @jsptagref.attributesyntaxvalue <i>string_or_expression</i>
078: * @netui:attribute required="true"
079: * description="Sets HTML attribute value."
080: */
081: public void setValue(String value) {
082: _info.setValue(value);
083: }
084:
085: /**
086: * @param onIcon
087: * @jsptagref.attributedescription Set the attribute value on the icon
088: * @jsptagref.databindable true
089: * @jsptagref.attributesyntaxvalue <i>string_or_expression</i>
090: * @netui:attribute required="false"
091: * description="Set the attribute value on the icon."
092: */
093: public void setOnIcon(boolean onIcon) {
094: _info.setOnIcon(onIcon);
095: }
096:
097: /**
098: * @param onSelectionLink
099: * @jsptagref.attributedescription Set the attribute value on the link around the icon.
100: * @jsptagref.databindable true
101: * @jsptagref.attributesyntaxvalue <i>string_or_expression</i>
102: * @netui:attribute required="false"
103: * description="Set the attribute value on the link around the icon."
104: */
105: public void setOnSelectionLink(boolean onSelectionLink) {
106: _info.setOnSelectionLink(onSelectionLink);
107: }
108:
109: /**
110: * @param onDiv
111: * @jsptagref.attributedescription Set the attribute value on the item <div>.
112: * @jsptagref.databindable true
113: * @jsptagref.attributesyntaxvalue <i>string_or_expression</i>
114: * @netui:attribute required="false"
115: * description="Set the attribute value on the item div."
116: */
117: public void setOnDiv(boolean onDiv) {
118: _info.setOnDiv(onDiv);
119: }
120:
121: /**
122: * @param applyToDescendents
123: * @jsptagref.attributedescription Apply the attribute to descendents of this node.
124: * @jsptagref.databindable true
125: * @jsptagref.attributesyntaxvalue <i>boolean</i>
126: * @netui:attribute required="false"
127: * description="Apply the attribute value to descendents of this node."
128: */
129: public void setApplyToDescendents(boolean applyToDescendents) {
130: _info.setApplyToDescendents(applyToDescendents);
131: }
132:
133: public void doTag() throws JspException {
134: Object o = getParent();
135: assert (o != null);
136:
137: if (o instanceof TreeItem) {
138: TreeItem ti = (TreeItem) o;
139: ti.setItemAttribute(_info);
140: } else {
141: logger.error("Found an unexpected parent object'"
142: + o.getClass().getName() + "' expected a TreeItem");
143: }
144: }
145: }
|