001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.faces.component.html;
030:
031: import java.util.*;
032:
033: import javax.el.*;
034:
035: import javax.faces.component.*;
036: import javax.faces.context.*;
037:
038: public class HtmlPanelGroup extends UIPanel {
039: public static final String COMPONENT_TYPE = "javax.faces.HtmlPanelGroup";
040:
041: private static final HashMap<String, PropEnum> _propMap = new HashMap<String, PropEnum>();
042:
043: private String _layout;
044: private ValueExpression _layoutExpr;
045:
046: private String _style;
047: private ValueExpression _styleExpr;
048:
049: private String _styleClass;
050: private ValueExpression _styleClassExpr;
051:
052: public HtmlPanelGroup() {
053: setRendererType("javax.faces.Group");
054: }
055:
056: //
057: // properties
058: //
059:
060: public String getLayout() {
061: if (_layout != null)
062: return _layout;
063: else if (_layoutExpr != null)
064: return Util.evalString(_layoutExpr);
065: else
066: return null;
067: }
068:
069: public void setLayout(String value) {
070: _layout = value;
071: }
072:
073: public String getStyle() {
074: if (_style != null)
075: return _style;
076: else if (_styleExpr != null)
077: return Util.evalString(_styleExpr);
078: else
079: return null;
080: }
081:
082: public void setStyle(String value) {
083: _style = value;
084: }
085:
086: public String getStyleClass() {
087: if (_styleClass != null)
088: return _styleClass;
089: else if (_styleClassExpr != null)
090: return Util.evalString(_styleClassExpr);
091: else
092: return null;
093: }
094:
095: public void setStyleClass(String value) {
096: _styleClass = value;
097: }
098:
099: //
100: // value expression override
101: //
102:
103: /**
104: * Returns the value expression with the given name.
105: */
106: @Override
107: public ValueExpression getValueExpression(String name) {
108: PropEnum prop = _propMap.get(name);
109:
110: if (prop != null) {
111: switch (prop) {
112: case LAYOUT:
113: return _layoutExpr;
114: case STYLE:
115: return _styleExpr;
116: case STYLE_CLASS:
117: return _styleClassExpr;
118: }
119: }
120:
121: return super .getValueExpression(name);
122: }
123:
124: /**
125: * Sets the value expression with the given name.
126: */
127: @Override
128: public void setValueExpression(String name, ValueExpression expr) {
129: PropEnum prop = _propMap.get(name);
130:
131: if (prop != null) {
132: switch (prop) {
133: case LAYOUT:
134: if (expr != null && expr.isLiteralText()) {
135: _layout = Util.evalString(expr);
136: return;
137: } else
138: _layoutExpr = expr;
139: break;
140:
141: case STYLE:
142: if (expr != null && expr.isLiteralText()) {
143: _style = Util.evalString(expr);
144: return;
145: } else
146: _styleExpr = expr;
147: break;
148:
149: case STYLE_CLASS:
150: if (expr != null && expr.isLiteralText()) {
151: _styleClass = Util.evalString(expr);
152: return;
153: } else
154: _styleClassExpr = expr;
155: break;
156: }
157: }
158:
159: super .setValueExpression(name, expr);
160: }
161:
162: //
163: // state
164: //
165:
166: public Object saveState(FacesContext context) {
167: Object parent = super .saveState(context);
168:
169: return new Object[] { parent,
170:
171: _layout, _style, _styleClass, };
172: }
173:
174: public void restoreState(FacesContext context, Object value) {
175: Object[] state = (Object[]) value;
176:
177: int i = 0;
178:
179: if (state != null)
180: super .restoreState(context, state[i++]);
181:
182: _layout = (String) state[i++];
183: _style = (String) state[i++];
184: _styleClass = (String) state[i++];
185: }
186:
187: //
188: // utility
189: //
190:
191: private enum PropEnum {
192: LAYOUT, STYLE, STYLE_CLASS,
193: }
194:
195: static {
196: _propMap.put("layout", PropEnum.LAYOUT);
197: _propMap.put("style", PropEnum.STYLE);
198: _propMap.put("styleClass", PropEnum.STYLE_CLASS);
199: }
200: }
|