001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.renderer;
042:
043: import com.sun.rave.web.ui.util.ConversionUtilities;
044: import java.io.IOException;
045: import javax.faces.context.FacesContext;
046: import javax.faces.context.ResponseWriter;
047: import javax.faces.component.UIComponent;
048:
049: import com.sun.rave.web.ui.util.LogUtil;
050: import com.sun.rave.web.ui.component.Tab;
051: import com.sun.rave.web.ui.component.TabSet;
052: import com.sun.rave.web.ui.theme.Theme;
053: import com.sun.rave.web.ui.theme.ThemeStyles;
054: import com.sun.rave.web.ui.util.ThemeUtilities;
055:
056: /**
057: * <p>Renders a Tab component.</p>
058: *
059: * <p>A Tab is a Hyperlink that, when clicked, also udpates the
060: * lastSelectedChild value of any parent Tab instance as well as the selected
061: * value of the enclosing TabSet component.</p>
062: *
063: * @author Sean Comerford
064: */
065: public class TabRenderer extends HyperlinkRenderer {
066:
067: /** Default constructor */
068: public TabRenderer() {
069: super ();
070: }
071:
072: /**
073: * This method is always called by the base class (HyperlinkRenderer)
074: * renderEnd method. TabRenderer should NOT render any Tab children as the
075: * enclosing TabSet component will do so (if necessary).
076: *
077: * @param context The current FacesContext
078: * @param component The current component
079: */
080: protected void renderChildren(FacesContext context,
081: UIComponent component) throws IOException {
082: // do nothing
083: }
084:
085: /**
086: * <p>Render the start of an anchor (hyperlink) tag.</p>
087: * @param context <code>FacesContext</code> for the current request
088: * @param component <code>UIComponent</code> to be rendered
089: * @param writer <code>ResponseWriter</code> to which the element
090: * start should be rendered
091: * @exception IOException if an input/output error occurs
092: */
093: protected void renderStart(FacesContext context,
094: UIComponent component, ResponseWriter writer)
095: throws IOException {
096: super .renderStart(context, component, writer);
097:
098: // ensure that this tab's parent is either a Tab or TabSet
099: UIComponent parent = component.getParent();
100:
101: if (!(parent instanceof Tab || parent instanceof TabSet)) {
102: if (LogUtil.infoEnabled()) {
103: LogUtil.info(TabRenderer.class, "WEBUI0006",
104: new String[] { component.getId() });
105: }
106: }
107: }
108:
109: protected void finishRenderAttributes(FacesContext context,
110: UIComponent component, ResponseWriter writer)
111: throws IOException {
112:
113: Tab tab = (Tab) component;
114:
115: // Set up local variables we will need
116: int tabIndex = tab.getTabIndex();
117: if (tabIndex >= 0) {
118: writer.writeAttribute("tabIndex", Integer
119: .toString(tabIndex), null);
120: }
121: super .finishRenderAttributes(context, component, writer);
122: }
123:
124: /**
125: * This function returns the style classes necessary to display the {@link Hyperlink} component as it's state indicates
126: * @return the style classes needed to display the current state of the component
127: */
128: protected String getStyles(FacesContext context,
129: UIComponent component) {
130: Tab link = (Tab) component;
131:
132: StringBuffer sb = new StringBuffer(200);
133: String tabStyleClass = link.getExtraStyles();
134: if (tabStyleClass != null) {
135: sb.append(tabStyleClass);
136: }
137:
138: Theme theme = ThemeUtilities.getTheme(context);
139: if (link.isDisabled()) {
140: sb.append(" "); //NOI18N
141: sb.append(theme.getStyleClass(ThemeStyles.LINK_DISABLED));
142: }
143:
144: // <RAVE>
145: // if (link.getText() != null && link.getText().length() <= 6) {
146: // sb.append(" "); // NOI18N
147: // sb.append(theme.getStyleClass(ThemeStyles.TAB_PADDING));
148: // }
149: Object value = link.getText();
150: if (value != null) {
151: String text = ConversionUtilities.convertValueToString(
152: link, link.getText());
153: if (text.length() <= 6) {
154: sb.append(" "); // NOI18N
155: sb.append(theme.getStyleClass(ThemeStyles.TAB_PADDING));
156: }
157: }
158: // </RAVE>
159:
160: return (sb.length() > 0) ? sb.toString() : null;
161: }
162: }
|