KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > panelpopup > PanelPopup


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.component.panelpopup;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.ext.HtmlPanelGroup;
38 import com.icesoft.faces.component.ext.taglib.Util;
39 import com.icesoft.faces.context.effects.JavascriptContext;
40
41 import javax.faces.component.UIComponent;
42 import javax.faces.context.FacesContext;
43 import javax.faces.el.ValueBinding;
44
45 /**
46  * PanelPopup is a JSF component class that represents an ICEfaces popup panel.
47  * The "header" and "body" named facets represent the components responsible for
48  * rendering the header and body of the popup panel.
49  * <p/>
50  * The component extends the ICEfaces extended HTMLPanelGroup.
51  * <p/>
52  * By default the component is rendered by the "com.icesoft.faces.PanelPopup"
53  * renderer type.
54  *
55  * @author Greg McCleary
56  * @version beta 1.0
57  */

58 public class PanelPopup
59         extends HtmlPanelGroup {
60     /**
61      * The component type.
62      */

63     public static final String JavaDoc COMPONENT_TYPE = "com.icesoft.faces.PanelPopup";
64     /**
65      * The default renderer type.
66      */

67     public static final String JavaDoc DEFAULT_RENDERER_TYPE =
68             "com.icesoft.faces.PanelPopup";
69     /**
70      * The default resizable property is false. This unused attribute is here
71      * for future use.
72      */

73     private static final boolean DEFAULT_RESIZABLE = false;
74     /**
75      * The default modal property is false.
76      */

77     private static final boolean DEFAULT_MODAL = false;
78     /**
79      * The header facet name.
80      */

81     private static final String JavaDoc HEADER_FACET = "header";
82     /**
83      * The body facet name.
84      */

85     private static final String JavaDoc BODY_FACET = "body";
86
87     /**
88      * The current style class.
89      */

90     private String JavaDoc styleClass = null;
91     /**
92      * The current style.
93      */

94     private String JavaDoc style = null;
95     /**
96      * The current resizable state.
97      */

98     private Boolean JavaDoc resizable = null;
99     /**
100      * The current modal state.
101      */

102     private Boolean JavaDoc modal = null;
103
104     /**
105      * Creates an instance and sets renderer type to "com.icesoft.faces.PanelPopup".
106      */

107     public PanelPopup() {
108         setRendererType(DEFAULT_RENDERER_TYPE);
109         JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
110                                      FacesContext.getCurrentInstance());
111     }
112
113     // typesafe facet getters
114

115     /**
116      * @return the "header" facet.
117      */

118     public UIComponent getHeader() {
119         return (UIComponent) getFacet(HEADER_FACET);
120     }
121
122     /**
123      * @return the "body" facet.
124      */

125     public UIComponent getBody() {
126         return (UIComponent) getFacet(BODY_FACET);
127     }
128
129     /* (non-Javadoc)
130      * @see javax.faces.component.UIComponent#isRendered()
131      */

132     public boolean isRendered() {
133         if (!Util.isRenderedOnUserRole(this)) {
134             return false;
135         }
136         return super.isRendered();
137     }
138
139
140     /**
141      * @return the headerClass style class name.
142      */

143     public String JavaDoc getHeaderClass() {
144         return Util.getQualifiedStyleClass(this,
145                 CSS_DEFAULT.POPUP_DEFAULT_HEADER_CLASS);
146     }
147
148
149     /**
150      * @return the bodyClass style class name.
151      */

152     public String JavaDoc getBodyClass() {
153         return Util.getQualifiedStyleClass(this,
154                 CSS_DEFAULT.POPUP_DEFAULT_BODY_CLASS);
155     }
156
157
158     /* (non-Javadoc)
159      * @see javax.faces.component.html.HtmlPanelGroup#setStyleClass(java.lang.String)
160      */

161     public void setStyleClass(String JavaDoc styleClass) {
162         this.styleClass = styleClass;
163     }
164
165     /* (non-Javadoc)
166     * @see javax.faces.component.html.HtmlPanelGroup#getStyleClass()
167     */

168     public String JavaDoc getStyleClass() {
169         return Util.getQualifiedStyleClass(this,
170                     styleClass,
171                     CSS_DEFAULT.POPUP_BASE,
172                     "styleClass");
173     }
174
175     /* (non-Javadoc)
176      * @see javax.faces.component.html.HtmlPanelGroup#getStyle()
177      */

178     public String JavaDoc getStyle() {
179         if (style != null) {
180             return style;
181         }
182         ValueBinding vb = getValueBinding("style");
183         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
184     }
185
186     /* (non-Javadoc)
187     * @see javax.faces.component.html.HtmlPanelGroup#setStyle(java.lang.String)
188     */

189     public void setStyle(String JavaDoc style) {
190         this.style = style;
191     }
192
193     /**
194      * Returns true if component is resizable. This method will always return
195      * false as the resizable functionality has not been implemented in the 1.0
196      * version.
197      *
198      * @return false
199      */

200     public boolean isResizable() {
201         return false; // resizable functionality is not added yet
202
}
203
204     /**
205      * Sets the resizable attribute of the component. Note: The resizable
206      * function has not been implemented in the Beta relase.
207      *
208      * @param resizable a value of true will set the component to be resizable
209      */

210     public void setResizable(boolean resizable) {
211         this.resizable = Boolean.valueOf(resizable);
212     }
213
214     /**
215      * @return true if the component is modal.
216      */

217     public boolean isModal() {
218         if (modal != null) {
219             return modal.booleanValue();
220         }
221         ValueBinding vb = getValueBinding("modal");
222         Boolean JavaDoc boolVal =
223                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
224         return boolVal != null ? boolVal.booleanValue() : DEFAULT_MODAL;
225     }
226
227     /**
228      * @param modal a value of true sets the component to be modal
229      */

230     public void setModal(boolean modal) {
231         this.modal = Boolean.valueOf(modal);
232     }
233
234     /* (non-Javadoc)
235      * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
236      */

237     public Object JavaDoc saveState(FacesContext context) {
238         Object JavaDoc values[] = new Object JavaDoc[10];
239         values[0] = super.saveState(context);
240         values[5] = styleClass;
241         values[6] = style;
242         values[7] = resizable;
243         values[8] = modal;
244         values[9] = title;
245         return ((Object JavaDoc) (values));
246     }
247
248     /* (non-Javadoc)
249      * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
250      */

251     public void restoreState(FacesContext context, Object JavaDoc state) {
252         Object JavaDoc values[] = (Object JavaDoc[]) state;
253         super.restoreState(context, values[0]);
254         styleClass = (String JavaDoc) values[5];
255         style = (String JavaDoc) values[6];
256         resizable = (Boolean JavaDoc) values[7];
257         modal = (Boolean JavaDoc) values[8];
258         title = (String JavaDoc) values[9];
259     }
260
261     private String JavaDoc title = null;
262
263     /**
264      * <p>Set the value of the <code>title</code> property.</p>
265      */

266     public void setTitle(String JavaDoc title) {
267         this.title = title;
268     }
269
270     /**
271      * <p>Return the value of the <code>title</code> property.</p>
272      */

273     public String JavaDoc getTitle() {
274         if (title != null) {
275             return title;
276         }
277         ValueBinding vb = getValueBinding("title");
278         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
279     }
280 }
Popular Tags