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 java.io.IOException;
044:
045: import javax.faces.FacesException;
046: import javax.faces.component.UIComponent;
047: import javax.faces.context.FacesContext;
048: import javax.faces.context.ResponseWriter;
049: import com.sun.rave.web.ui.component.DropDown;
050: import com.sun.rave.web.ui.component.ListSelector;
051: import com.sun.rave.web.ui.theme.Theme;
052: import com.sun.rave.web.ui.theme.ThemeStyles;
053: import com.sun.rave.web.ui.util.MessageUtil;
054: import com.sun.rave.web.ui.util.RenderingUtilities;
055: import com.sun.rave.web.ui.util.ThemeUtilities;
056:
057: /**
058: * <p>Renderer for a {@link DropDown} component.</p>
059: */
060:
061: public class DropDownRenderer extends ListRendererBase {
062:
063: private final static boolean DEBUG = false;
064:
065: /**
066: * <p>Render the drop-down dropDown.
067: *
068: * @param context <code>FacesContext</code> for the current request
069: * @param component <code>UIComponent</code> to be rendered
070: * end should be rendered
071: *
072: * @exception IOException if an input/output error occurs
073: */
074: public void encodeEnd(FacesContext context, UIComponent component)
075: throws IOException {
076:
077: if (DEBUG)
078: log("encodeEnd()");
079:
080: if (!(component instanceof DropDown)) {
081: Object[] params = { component.toString(),
082: this .getClass().getName(), DropDown.class.getName() };
083: String message = MessageUtil.getMessage(
084: "com.sun.rave.web.ui.resources.LogMessages", //NOI18N
085: "Renderer.component", params); //NOI18N
086: throw new FacesException(message);
087:
088: }
089:
090: DropDown dropDown = (DropDown) component;
091: if (dropDown.isForgetValue()) {
092: dropDown.setValue(null);
093: }
094:
095: // Render the element and attributes for this component
096: //ResponseWriter writer = context.getResponseWriter();
097:
098: String[] styles = null;
099: if (dropDown.isSubmitForm()) {
100: styles = getJumpDropDownStyles(dropDown, context);
101: } else {
102: styles = getDropDownStyles(dropDown, context);
103: }
104:
105: super .renderListComponent((ListSelector) dropDown, context,
106: styles);
107: if (dropDown.isSubmitForm()) {
108: ResponseWriter writer = context.getResponseWriter();
109: String id = dropDown.getClientId(context).concat(
110: DropDown.SUBMIT);
111: RenderingUtilities.renderHiddenField(dropDown, writer, id,
112: "false");
113: }
114: }
115:
116: /**
117: * <p>Render the appropriate element end, depending on the value of the
118: * <code>type</code> property.</p>
119: *
120: * @param context <code>FacesContext</code> for the current request
121: * @param monospace <code>UIComponent</code> if true, use the monospace
122: * styles to render the list.
123: *
124: * @exception IOException if an input/output error occurs
125: */
126: private String[] getDropDownStyles(DropDown component,
127: FacesContext context) {
128:
129: Theme theme = ThemeUtilities.getTheme(context);
130: String[] styles = new String[10];
131: styles[0] = getOnChangeJavaScript(component,
132: "dropDown_changed", context);
133: styles[1] = theme.getStyleClass(ThemeStyles.MENU_STANDARD);
134: styles[2] = theme
135: .getStyleClass(ThemeStyles.MENU_STANDARD_DISABLED);
136: styles[3] = theme
137: .getStyleClass(ThemeStyles.MENU_STANDARD_OPTION);
138: styles[4] = theme
139: .getStyleClass(ThemeStyles.MENU_STANDARD_OPTION_DISABLED);
140: styles[5] = theme
141: .getStyleClass(ThemeStyles.MENU_STANDARD_OPTION_SELECTED);
142: styles[6] = theme
143: .getStyleClass(ThemeStyles.MENU_STANDARD_OPTION_GROUP);
144: styles[7] = theme
145: .getStyleClass(ThemeStyles.MENU_STANDARD_OPTION_SEPARATOR);
146: styles[8] = theme.getStyleClass(ThemeStyles.HIDDEN);
147: return styles;
148: }
149:
150: /**
151: * Helper function to get the theme specific styles for this dropdown given
152: * the current context
153: */
154: private String[] getJumpDropDownStyles(DropDown component,
155: FacesContext context) {
156:
157: Theme theme = ThemeUtilities.getTheme(context);
158: String[] styles = new String[10];
159: styles[0] = getOnChangeJavaScript(component,
160: "jumpDropDown_changed", context);
161: styles[1] = theme.getStyleClass(ThemeStyles.MENU_JUMP);
162: styles[2] = ""; // jumpMENU can't be disabled
163: styles[3] = theme.getStyleClass(ThemeStyles.MENU_JUMP_OPTION);
164: styles[4] = theme
165: .getStyleClass(ThemeStyles.MENU_JUMP_OPTION_DISABLED);
166: styles[5] = theme
167: .getStyleClass(ThemeStyles.MENU_JUMP_OPTION_SELECTED);
168: styles[6] = theme
169: .getStyleClass(ThemeStyles.MENU_JUMP_OPTION_GROUP);
170: styles[7] = theme
171: .getStyleClass(ThemeStyles.MENU_JUMP_OPTION_SEPARATOR);
172: styles[8] = theme.getStyleClass(ThemeStyles.HIDDEN);
173: return styles;
174: }
175: }
|