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.beans.Beans;
044: import java.io.IOException;
045: import java.util.Iterator;
046: import java.util.Map;
047: import javax.faces.FacesException;
048: import javax.faces.component.EditableValueHolder;
049: import javax.faces.component.NamingContainer;
050: import javax.faces.component.UIComponent;
051: import javax.faces.context.FacesContext;
052: import javax.faces.context.ResponseWriter;
053: import javax.faces.event.ActionEvent;
054: import javax.faces.render.Renderer;
055: import com.sun.rave.web.ui.component.Listbox;
056: import com.sun.rave.web.ui.component.ListManager;
057: import com.sun.rave.web.ui.component.ListSelector;
058: import com.sun.rave.web.ui.theme.Theme;
059: import com.sun.rave.web.ui.theme.ThemeStyles;
060: import com.sun.rave.web.ui.util.ThemeUtilities;
061:
062: /**
063: * <p>Renderer for a {@link com.sun.rave.web.ui.component.Listbox} component.</p>
064: */
065:
066: public class ListboxRenderer extends ListRendererBase {
067:
068: private final static boolean DEBUG = false;
069:
070: /**
071: * <p>Render the list.
072: *
073: * @param context <code>FacesContext</code> for the current request
074: * @param component <code>UIComponent</code> to be rendered
075: * end should be rendered
076: *
077: * @exception IOException if an input/output error occurs
078: */
079: public void encodeEnd(FacesContext context, UIComponent component)
080: throws IOException {
081:
082: if (DEBUG)
083: log("encodeEnd()");
084:
085: if (component instanceof ListSelector) {
086:
087: ListSelector selector = (ListSelector) component;
088:
089: if (!Beans.isDesignTime()) {
090: selector.checkSelectionModel(context);
091: }
092:
093: boolean useMonospace = false;
094: if (selector instanceof Listbox) {
095: useMonospace = ((Listbox) selector).isMonospace();
096: }
097:
098: super .renderListComponent(selector, context, getStyles(
099: context, component, useMonospace));
100: } else {
101: String message = "Component " + component.toString() + //NOI18N
102: " has been associated with a ListboxRenderer. " + //NOI18N
103: " This renderer can only be used by components " + //NOI18N
104: " that extend com.sun.rave.web.ui.component.Selector."; //NOI18N
105: throw new FacesException(message);
106: }
107: }
108:
109: /**
110: * <p>Render the appropriate element end, depending on the value of the
111: * <code>type</code> property.</p>
112: *
113: * @param context <code>FacesContext</code> for the current request
114: * @param monospace <code>UIComponent</code> if true, use the monospace
115: * styles to render the list.
116: *
117: * @exception IOException if an input/output error occurs
118: */
119: private String[] getStyles(FacesContext context,
120: UIComponent component, boolean monospace) {
121:
122: if (DEBUG)
123: log("getStyles()");
124:
125: Theme theme = ThemeUtilities.getTheme(context);
126:
127: String[] styles = new String[10];
128: styles[0] = getOnChangeJavaScript((ListManager) component,
129: "listbox_changed", context);
130: if (monospace) {
131: styles[1] = theme.getStyleClass(ThemeStyles.LIST_MONOSPACE);
132: styles[2] = theme
133: .getStyleClass(ThemeStyles.LIST_MONOSPACE_DISABLED);
134: } else {
135: styles[1] = theme.getStyleClass(ThemeStyles.LIST);
136: styles[2] = theme.getStyleClass(ThemeStyles.LIST_DISABLED);
137: }
138: styles[3] = theme.getStyleClass(ThemeStyles.LIST_OPTION);
139: styles[4] = theme
140: .getStyleClass(ThemeStyles.LIST_OPTION_DISABLED);
141: styles[5] = theme
142: .getStyleClass(ThemeStyles.LIST_OPTION_SELECTED);
143: styles[6] = theme.getStyleClass(ThemeStyles.LIST_OPTION_GROUP);
144: styles[7] = theme
145: .getStyleClass(ThemeStyles.LIST_OPTION_SEPARATOR);
146: styles[8] = theme.getStyleClass(ThemeStyles.HIDDEN);
147: styles[9] = theme.getStyleClass(ThemeStyles.LIST_ALIGN);
148: return styles;
149: }
150: }
|