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 com.sun.rave.web.ui.el.ConstantMethodBinding;
044: import com.sun.rave.web.ui.theme.Theme;
045: import com.sun.rave.web.ui.theme.ThemeImages;
046: import com.sun.rave.web.ui.util.ThemeUtilities;
047: import java.beans.Beans;
048: import javax.faces.FactoryFinder;
049: import javax.faces.application.Application;
050: import javax.faces.application.ApplicationFactory;
051: import javax.faces.component.UIComponent;
052: import javax.faces.context.FacesContext;
053: import javax.faces.el.MethodBinding;
054:
055: /**
056: * <p>The inline Alert component.</p>
057: */
058: public class Alert extends AlertBase {
059: /**
060: * String for the appended id of the facet name for image
061: */
062: public static final String ALERT_IMAGE_FACET = "alertImage"; //NOI18N
063: /**
064: * String for the appended id of the facet name for the link
065: */
066: public static final String ALERT_LINK_FACET = "alertLink"; //NOI18N
067:
068: /**
069: * Gets the alert icon facet for this component.
070: * If none exists it will create one with the appropriate type.
071: * The default is a warning icon.
072: * @return always returns an icon component, will return a facet
073: * if it exists or a newly created one if it doesn't
074: */
075: public UIComponent getAlertIcon() {
076: // First check if a buttons facet was defined
077: UIComponent imageFacet = getFacet(ALERT_IMAGE_FACET);
078: if (imageFacet == null) {
079: Theme theme = ThemeUtilities.getTheme(FacesContext
080: .getCurrentInstance());
081: imageFacet = theme.getIcon(getIconIdentifier());
082: imageFacet.setId(getId() + "_" + ALERT_IMAGE_FACET); // NOI18N
083: }
084: if (imageFacet instanceof Icon) {
085: Icon icon = (Icon) imageFacet;
086: icon.setAlt(getAlt());
087: icon.setIcon(getIconIdentifier());
088: // <RAVE>
089: // getFacets().put(ALERT_IMAGE_FACET, imageFacet);
090: if (!Beans.isDesignTime())
091: getFacets().put(ALERT_IMAGE_FACET, imageFacet);
092: // </RAVE>
093: }
094:
095: return imageFacet;
096: }
097:
098: /**
099: * Gets the alert hyperlink facet for this component.
100: * If none exists it will create
101: * one with the appropriate type. The default is a warning icon.
102: * If the facet id is the internal facet id, it will update the links
103: * and text
104: * If the facet id is any other id then this component will just
105: * return the facet
106: * @return always returns a Hyperlink component, will return a facet
107: * if it exists or a newly created one if it doesn't
108: */
109: public UIComponent getAlertLink() {
110: UIComponent linkFacet = getFacet(ALERT_LINK_FACET);
111: String newId = getId() + "_" + ALERT_LINK_FACET;
112: if ((linkFacet == null || linkFacet.getId().equals(newId))
113: && getLinkText() != null) {
114: IconHyperlink h = new IconHyperlink();
115: h.setId(newId); // NOI18N
116: h.setTarget(getLinkTarget());
117: h.setText(getLinkText());
118: h.setToolTip(getLinkToolTip());
119: h.setUrl(getLinkURL());
120: h.setIcon(ThemeImages.HREF_LINK);
121:
122: MethodBinding action = getLinkAction();
123: if (action != null) {
124: h.setAction(action);
125: }
126: linkFacet = h;
127: // <RAVE>
128: // getFacets().put(ALERT_LINK_FACET, linkFacet);
129: if (!Beans.isDesignTime())
130: getFacets().put(ALERT_LINK_FACET, linkFacet);
131: // </RAVE>
132: }
133: return linkFacet;
134: }
135:
136: private String getIconIdentifier() {
137:
138: String type = getType();
139: if (type != null) {
140: String lower = type.toLowerCase();
141:
142: if (lower.startsWith("warn")) { // NOI18N
143: return ThemeImages.ALERT_WARNING_LARGE;
144: } else if (lower.startsWith("ques")) { // NOI18N
145: return ThemeImages.ALERT_HELP_LARGE;
146: } else if (lower.startsWith("info")) { // NOI18N
147: return ThemeImages.ALERT_INFO_LARGE;
148: } else if (lower.startsWith("succ")) { // NOI18N
149: return ThemeImages.ALERT_SUCCESS_LARGE;
150: }
151: }
152: return ThemeImages.ALERT_ERROR_LARGE;
153: }
154:
155: public void setLinkURL(String linkURL) {
156: super .setLinkURL(linkURL);
157: UIComponent link = getFacet(ALERT_LINK_FACET);
158: if (link != null && link instanceof IconHyperlink)
159: ((IconHyperlink) link).setUrl(linkURL);
160: }
161:
162: public void setLinkToolTip(String linkToolTip) {
163: super .setLinkToolTip(linkToolTip);
164: UIComponent link = getFacet(ALERT_LINK_FACET);
165: if (link != null && link instanceof IconHyperlink)
166: ((IconHyperlink) link).setToolTip(linkToolTip);
167: }
168:
169: public void setLinkText(String linkText) {
170: super .setLinkText(linkText);
171: UIComponent link = getFacet(ALERT_LINK_FACET);
172: if (link != null && link instanceof IconHyperlink)
173: ((IconHyperlink) link).setText(linkText);
174: }
175:
176: public void setLinkTarget(String linkTarget) {
177: super .setLinkTarget(linkTarget);
178: UIComponent link = getFacet(ALERT_LINK_FACET);
179: if (link != null && link instanceof IconHyperlink)
180: ((IconHyperlink) link).setTarget(linkTarget);
181: }
182:
183: public void setLinkAction(MethodBinding linkAction) {
184: super .setLinkAction(linkAction);
185: UIComponent link = getFacet(ALERT_LINK_FACET);
186: if (link != null && link instanceof IconHyperlink)
187: ((IconHyperlink) link).setAction(linkAction);
188: }
189:
190: }
|