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.component;
042:
043: import java.beans.Beans;
044: import javax.faces.component.UIComponent;
045: import javax.faces.context.FacesContext;
046: import com.sun.rave.web.ui.theme.Theme;
047: import com.sun.rave.web.ui.theme.ThemeImages;
048: import com.sun.rave.web.ui.util.ThemeUtilities;
049:
050: /**
051: * <p>The Page Alert component.</p>
052: */
053: public class PageAlert extends PageAlertBase {
054: /**
055: * The facets...
056: */
057: public static final String PAGEALERT_INPUT_FACET = "pageAlertInput"; //NOI18N
058: public static final String PAGEALERT_TITLE_FACET = "pageAlertTitle"; //NOI18N
059: public static final String PAGEALERT_BUTTONS_FACET = "pageAlertButtons"; //NOI18N
060: public static final String PAGEALERT_SEPARATOR_FACET = "pageAlertSeparator"; //NOI18N
061: public static final String PAGEALERT_IMAGE_FACET = "pageAlertImage"; //NOI18N
062:
063: /**
064: * Get the page alert input facet.
065: *
066: * @return A Back button (or a facet with buttons).
067: */
068: public UIComponent getPageAlertInput() {
069: return getFacet(PAGEALERT_INPUT_FACET);
070: }
071:
072: /**
073: * Get the page alert title facet.
074: *
075: * @return A Back button (or a facet with buttons).
076: */
077: public UIComponent getPageAlertTitle() {
078: UIComponent titleFacet = getFacet(PAGEALERT_TITLE_FACET);
079: String id = getId() + "_pageAlertTitle";
080: if (titleFacet == null) {
081: // create a facet for the title and add it:
082: titleFacet = new StaticText();
083: titleFacet.setId(id);
084: // <RAVE>
085: // getFacets().put(PAGEALERT_TITLE_FACET, titleFacet);
086: if (!Beans.isDesignTime())
087: getFacets().put(PAGEALERT_TITLE_FACET, titleFacet);
088: // </RAVE>
089: }
090:
091: if (titleFacet.getId() == id) {
092: //we created this facet so make sure the text is updated in case of
093: //value bindings
094: ((StaticText) titleFacet).setText(getSafeTitle());
095: }
096: return titleFacet;
097: }
098:
099: /**
100: * Get buttons for the Page Alert.
101: * Return a set of buttons if they were sepecifed in tha facet
102: *
103: * @return A Back button (or a facet with buttons).
104: */
105: public UIComponent getPageAlertButtons() {
106: // First check if a buttons facet was defined
107: UIComponent buttonFacet = getFacet(PAGEALERT_BUTTONS_FACET);
108: return buttonFacet;
109: }
110:
111: /**
112: * Get or create the separator for the Page Alert.
113: *
114: *
115: * @return a PageSeparator component
116: */
117: public UIComponent getPageAlertSeparator() {
118: // First check if a buttons facet was defined
119: UIComponent separatorFacet = getFacet(PAGEALERT_SEPARATOR_FACET);
120: if (separatorFacet == null) {
121: separatorFacet = new PageSeparator();
122: separatorFacet.setId(getId() + "_pageAlertSeparator");
123: // <RAVE>
124: // getFacets().put(PAGEALERT_SEPARATOR_FACET, separatorFacet);
125: if (!Beans.isDesignTime())
126: getFacets().put(PAGEALERT_SEPARATOR_FACET,
127: separatorFacet);
128: // </RAVE>
129:
130: }
131: return separatorFacet;
132: }
133:
134: /**
135: * Get or create the separator for the Page Alert.
136: *
137: *
138: * @return a PageSeparator component
139: */
140: public UIComponent getPageAlertImage() {
141: // First check if a buttons facet was defined
142: UIComponent imageFacet = getFacet(PAGEALERT_IMAGE_FACET);
143: if (imageFacet == null) {
144:
145: Icon icon = (Icon) getTheme().getIcon(getIconIdentifier());
146: icon.setAlt(getAlt());
147: icon.setId(getId() + "_pageAlertImage"); // NOI18N
148: imageFacet = icon;
149: // <RAVE>
150: // getFacets().put(PAGEALERT_IMAGE_FACET, imageFacet);
151: if (!Beans.isDesignTime())
152: getFacets().put(PAGEALERT_IMAGE_FACET, imageFacet);
153: // </RAVE>
154:
155: }
156: return imageFacet;
157: }
158:
159: public String getSafeTitle() {
160: String title = getTitle();
161: if (title == null) {
162: title = getAlt();
163: if (title == null) {
164: title = "";
165: }
166: }
167: return title;
168: }
169:
170: private String getIconIdentifier() {
171: String type = getType();
172: if (type != null) {
173: type.toLowerCase();
174:
175: if (type.startsWith("warn")) { // NOI18N
176: return ThemeImages.ALERT_WARNING_LARGE;
177: } else if (type.startsWith("ques")) { // NOI18N
178: return ThemeImages.ALERT_HELP_LARGE;
179: } else if (type.startsWith("info")) { // NOI18N
180: return ThemeImages.ALERT_INFO_LARGE;
181: }
182: }
183: return ThemeImages.ALERT_ERROR_LARGE;
184: }
185:
186: /*
187: * Utility to get theme.
188: */
189: private Theme getTheme() {
190: return ThemeUtilities.getTheme(FacesContext
191: .getCurrentInstance());
192: }
193:
194: }
|