001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.panelpopup;
035:
036: import com.icesoft.faces.component.CSS_DEFAULT;
037: import com.icesoft.faces.component.ext.HtmlPanelGroup;
038: import com.icesoft.faces.component.ext.taglib.Util;
039: import com.icesoft.faces.context.effects.JavascriptContext;
040:
041: import javax.faces.component.UIComponent;
042: import javax.faces.context.FacesContext;
043: import javax.faces.el.ValueBinding;
044:
045: /**
046: * PanelPopup is a JSF component class that represents an ICEfaces popup panel.
047: * The "header" and "body" named facets represent the components responsible for
048: * rendering the header and body of the popup panel.
049: * <p/>
050: * The component extends the ICEfaces extended HTMLPanelGroup.
051: * <p/>
052: * By default the component is rendered by the "com.icesoft.faces.PanelPopup"
053: * renderer type.
054: *
055: * @author Greg McCleary
056: * @version beta 1.0
057: */
058: public class PanelPopup extends HtmlPanelGroup {
059: /**
060: * The component type.
061: */
062: public static final String COMPONENT_TYPE = "com.icesoft.faces.PanelPopup";
063: /**
064: * The default renderer type.
065: */
066: public static final String DEFAULT_RENDERER_TYPE = "com.icesoft.faces.PanelPopup";
067: /**
068: * The default resizable property is false. This unused attribute is here
069: * for future use.
070: */
071: private static final boolean DEFAULT_RESIZABLE = false;
072: /**
073: * The default modal property is false.
074: */
075: private static final boolean DEFAULT_MODAL = false;
076: /**
077: * The header facet name.
078: */
079: private static final String HEADER_FACET = "header";
080: /**
081: * The body facet name.
082: */
083: private static final String BODY_FACET = "body";
084:
085: /**
086: * The current style class.
087: */
088: private String styleClass = null;
089: /**
090: * The current style.
091: */
092: private String style = null;
093: /**
094: * The current resizable state.
095: */
096: private Boolean resizable = null;
097: /**
098: * The current modal state.
099: */
100: private Boolean modal = null;
101:
102: /**
103: * Creates an instance and sets renderer type to "com.icesoft.faces.PanelPopup".
104: */
105: public PanelPopup() {
106: setRendererType(DEFAULT_RENDERER_TYPE);
107: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
108: FacesContext.getCurrentInstance());
109: }
110:
111: // typesafe facet getters
112:
113: /**
114: * @return the "header" facet.
115: */
116: public UIComponent getHeader() {
117: return (UIComponent) getFacet(HEADER_FACET);
118: }
119:
120: /**
121: * @return the "body" facet.
122: */
123: public UIComponent getBody() {
124: return (UIComponent) getFacet(BODY_FACET);
125: }
126:
127: /* (non-Javadoc)
128: * @see javax.faces.component.UIComponent#isRendered()
129: */
130: public boolean isRendered() {
131: if (!Util.isRenderedOnUserRole(this )) {
132: return false;
133: }
134: return super .isRendered();
135: }
136:
137: /**
138: * @return the headerClass style class name.
139: */
140: public String getHeaderClass() {
141: return Util.getQualifiedStyleClass(this ,
142: CSS_DEFAULT.POPUP_DEFAULT_HEADER_CLASS);
143: }
144:
145: /**
146: * @return the bodyClass style class name.
147: */
148: public String getBodyClass() {
149: return Util.getQualifiedStyleClass(this ,
150: CSS_DEFAULT.POPUP_DEFAULT_BODY_CLASS);
151: }
152:
153: /* (non-Javadoc)
154: * @see javax.faces.component.html.HtmlPanelGroup#setStyleClass(java.lang.String)
155: */
156: public void setStyleClass(String styleClass) {
157: this .styleClass = styleClass;
158: }
159:
160: /* (non-Javadoc)
161: * @see javax.faces.component.html.HtmlPanelGroup#getStyleClass()
162: */
163: public String getStyleClass() {
164: return Util.getQualifiedStyleClass(this , styleClass,
165: CSS_DEFAULT.POPUP_BASE, "styleClass");
166: }
167:
168: /* (non-Javadoc)
169: * @see javax.faces.component.html.HtmlPanelGroup#getStyle()
170: */
171: public String getStyle() {
172: if (style != null) {
173: return style;
174: }
175: ValueBinding vb = getValueBinding("style");
176: return vb != null ? (String) vb.getValue(getFacesContext())
177: : null;
178: }
179:
180: /* (non-Javadoc)
181: * @see javax.faces.component.html.HtmlPanelGroup#setStyle(java.lang.String)
182: */
183: public void setStyle(String style) {
184: this .style = style;
185: }
186:
187: /**
188: * Returns true if component is resizable. This method will always return
189: * false as the resizable functionality has not been implemented in the 1.0
190: * version.
191: *
192: * @return false
193: */
194: public boolean isResizable() {
195: return false; // resizable functionality is not added yet
196: }
197:
198: /**
199: * Sets the resizable attribute of the component. Note: The resizable
200: * function has not been implemented in the Beta relase.
201: *
202: * @param resizable a value of true will set the component to be resizable
203: */
204: public void setResizable(boolean resizable) {
205: this .resizable = Boolean.valueOf(resizable);
206: }
207:
208: /**
209: * @return true if the component is modal.
210: */
211: public boolean isModal() {
212: if (modal != null) {
213: return modal.booleanValue();
214: }
215: ValueBinding vb = getValueBinding("modal");
216: Boolean boolVal = vb != null ? (Boolean) vb
217: .getValue(getFacesContext()) : null;
218: return boolVal != null ? boolVal.booleanValue() : DEFAULT_MODAL;
219: }
220:
221: /**
222: * @param modal a value of true sets the component to be modal
223: */
224: public void setModal(boolean modal) {
225: this .modal = Boolean.valueOf(modal);
226: }
227:
228: /* (non-Javadoc)
229: * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
230: */
231: public Object saveState(FacesContext context) {
232: Object values[] = new Object[10];
233: values[0] = super .saveState(context);
234: values[5] = styleClass;
235: values[6] = style;
236: values[7] = resizable;
237: values[8] = modal;
238: values[9] = title;
239: return ((Object) (values));
240: }
241:
242: /* (non-Javadoc)
243: * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
244: */
245: public void restoreState(FacesContext context, Object state) {
246: Object values[] = (Object[]) state;
247: super .restoreState(context, values[0]);
248: styleClass = (String) values[5];
249: style = (String) values[6];
250: resizable = (Boolean) values[7];
251: modal = (Boolean) values[8];
252: title = (String) values[9];
253: }
254:
255: private String title = null;
256:
257: /**
258: * <p>Set the value of the <code>title</code> property.</p>
259: */
260: public void setTitle(String title) {
261: this .title = title;
262: }
263:
264: /**
265: * <p>Return the value of the <code>title</code> property.</p>
266: */
267: public String getTitle() {
268: if (title != null) {
269: return title;
270: }
271: ValueBinding vb = getValueBinding("title");
272: return vb != null ? (String) vb.getValue(getFacesContext())
273: : null;
274: }
275: }
|