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.ext;
035:
036: import com.icesoft.faces.component.panelseries.UISeries;
037:
038: import javax.faces.component.NamingContainer;
039: import javax.faces.component.UIComponent;
040: import javax.faces.context.FacesContext;
041: import javax.faces.el.ValueBinding;
042: import javax.faces.event.PhaseId;
043:
044: import java.io.IOException;
045: import java.util.HashMap;
046: import java.util.Iterator;
047:
048: public class UIColumns extends UISeries {
049: public static final String COMPONENT_TYPE = "com.icesoft.faces.Columns";
050: public static final String COMPONENT_FAMILY = "javax.faces.Columns";
051:
052: public String getFamily() {
053: return (COMPONENT_FAMILY);
054: }
055:
056: public UIColumns() {
057: setRendererType(null);
058: }
059:
060: /**
061: * <p>The "should this component be rendered" flag.</p>
062: */
063: private boolean rendered = true;
064: private boolean renderedSet = false;
065:
066: public boolean isRendered() {
067: if (renderedSet) {
068: return (rendered);
069: }
070: ValueBinding vb = getValueBinding("rendered");
071: if (vb != null) {
072: return (!Boolean.FALSE.equals(vb
073: .getValue(getFacesContext())));
074: } else {
075: return (this .rendered);
076: }
077:
078: }
079:
080: public void setRendered(boolean rendered) {
081: this .rendered = rendered;
082: this .renderedSet = true;
083: }
084:
085: protected void iterate(FacesContext facesContext, PhaseId phase) {
086: // process the column header facet
087: if (isHeaderFacet()
088: && (UIComponent) getFacets().get("header") != null) {
089: // clear row index
090: setRowIndex(-1);
091: UIComponent facet = (UIComponent) getFacets().get("header");
092: int rowsProcessed = 0;
093: int currentRowIndex = getFirst() - 1;
094: int displayedRows = getRows();
095: // loop over dataModel processing each row once
096: while (1 == 1) {
097: // break if we have processed the number of rows requested
098: if ((displayedRows > 0)
099: && (++rowsProcessed > displayedRows)) {
100: break;
101: }
102: // process the row at currentRowIndex
103: setRowIndex(++currentRowIndex);
104: // break if we've moved past the last row
105: if (!isRowAvailable()) {
106: break;
107: }
108: Iterator kids = facet.getChildren().iterator();
109: while (kids.hasNext()) {
110: UIComponent kid = (UIComponent) kids.next();
111: processKids(facesContext, phase, kid);
112: }
113: }
114: } else {
115: // clear row index
116: setRowIndex(-1);
117: int rowsProcessed = 0;
118: int currentRowIndex = getFirst() - 1;
119: int displayedRows = getRows();
120: // loop over dataModel processing each row once
121: while (1 == 1) {
122: // break if we have processed the number of rows requested
123: if ((displayedRows > 0)
124: && (++rowsProcessed > displayedRows)) {
125: break;
126: }
127: // process the row at currentRowIndex
128: setRowIndex(++currentRowIndex);
129: // break if we've moved past the last row
130: if (!isRowAvailable()) {
131: break;
132: }
133: Iterator kids = getChildren().iterator();
134: while (kids.hasNext()) {
135: UIComponent kid = (UIComponent) kids.next();
136: processKids(facesContext, phase, kid);
137: }
138: }
139: // reset row index
140: setRowIndex(-1);
141: }
142: }
143:
144: public String getId() {
145: return String.valueOf(getRowIndex()) + getRowId();
146: }
147:
148: public void processKids(FacesContext context, PhaseId phaseId,
149: UIComponent kid) {
150: if (phaseId == PhaseId.APPLY_REQUEST_VALUES) {
151: kid.processDecodes(context);
152: } else if (phaseId == PhaseId.PROCESS_VALIDATIONS) {
153: kid.processValidators(context);
154: } else if (phaseId == PhaseId.UPDATE_MODEL_VALUES) {
155: kid.processUpdates(context);
156: } else {
157: throw new IllegalArgumentException();
158: }
159: }
160:
161: protected void restoreChildrenState(FacesContext facesContext) {
162: Iterator children = null;
163: if (isHeaderFacet()) {
164: children = getFacets().values().iterator();
165: } else {
166: if (getRowIndex() < 0) {
167: return;
168: } else {
169: children = getChildren().iterator();
170: }
171: }
172: while (children.hasNext()) {
173: UIComponent child = (UIComponent) children.next();
174: restoreChildState(facesContext, child);
175: }
176: }
177:
178: /**
179: * <p>Save state information for all descendant components, as described for
180: * <code>setRowIndex()</code>.</p>
181: */
182: protected void saveChildrenState(FacesContext facesContext) {
183: Iterator children = null;
184: if (isHeaderFacet()) {
185: children = getFacets().values().iterator();
186: } else {
187: if (getRowIndex() < 0) {
188: return;
189: } else {
190: children = getChildren().iterator();
191: }
192: }
193: while (children.hasNext()) {
194: UIComponent child = (UIComponent) children.next();
195: saveChildState(facesContext, child);
196: }
197: }
198:
199: public int getRowId() {
200: if (getParent() != null
201: && ((HtmlDataTable) getParent()).getRowIndex() >= 0) {
202: return ((HtmlDataTable) getParent()).getRowIndex();
203: } else {
204: return 0;
205: }
206: }
207:
208: public String getClientId(FacesContext context) {
209: if (context == null) {
210: throw new NullPointerException();
211: }
212: String baseClientId = super .getClientId(context);
213: if (getRowIndex() >= 0) {
214: return (baseClientId + NamingContainer.SEPARATOR_CHAR
215: + getRowIndex() + getRowId());
216: } else {
217: return (baseClientId);
218: }
219:
220: }
221:
222: public boolean isHeaderFacet() {
223: return (((HtmlDataTable) getParent()).getRowIndex() < 0) ? true
224: : false;
225: }
226:
227: public void processDecodes(FacesContext context) {
228:
229: if (context == null) {
230: throw new NullPointerException();
231: }
232: if (!isRendered()) {
233: return;
234: }
235:
236: dataModel = null; // Re-evaluate even with server-side state saving
237: if (null == savedChildren) {
238: savedChildren = new HashMap();
239: }
240: iterate(context, PhaseId.APPLY_REQUEST_VALUES);
241: decode(context);
242: }
243:
244: }
|