KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > ext > UIColumns


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.ext;
35
36 import com.icesoft.faces.component.panelseries.UISeries;
37
38 import javax.faces.component.NamingContainer;
39 import javax.faces.component.UIComponent;
40 import javax.faces.context.FacesContext;
41 import javax.faces.el.ValueBinding;
42 import javax.faces.event.PhaseId;
43 import java.util.HashMap JavaDoc;
44 import java.util.Iterator JavaDoc;
45
46
47 public class UIColumns extends UISeries {
48     public static final String JavaDoc COMPONENT_TYPE = "com.icesoft.faces.Columns";
49     public static final String JavaDoc COMPONENT_FAMILY = "javax.faces.Columns";
50
51     public String JavaDoc getFamily() {
52         return (COMPONENT_FAMILY);
53     }
54
55     public UIColumns() {
56         setRendererType(null);
57     }
58
59
60     /**
61      * <p>The "should this component be rendered" flag.</p>
62      */

63     private boolean rendered = true;
64     private boolean renderedSet = false;
65
66     public boolean isRendered() {
67         if (renderedSet) {
68             return (rendered);
69         }
70         ValueBinding vb = getValueBinding("rendered");
71         if (vb != null) {
72             return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
73         } else {
74             return (this.rendered);
75         }
76
77     }
78
79
80     public void setRendered(boolean rendered) {
81         this.rendered = rendered;
82         this.renderedSet = true;
83     }
84
85     protected void iterate(FacesContext facesContext, PhaseId phase) {
86         // process the column header facet
87
if (isHeaderFacet() && (UIComponent) getFacets().get("header")!= null) {
88             // clear row index
89
setRowIndex(-1);
90             UIComponent facet = (UIComponent) getFacets().get("header");
91             int rowsProcessed = 0;
92             int currentRowIndex = getFirst() - 1;
93             int displayedRows = getRows();
94             // loop over dataModel processing each row once
95
while (1 == 1) {
96                 // break if we have processed the number of rows requested
97
if ((displayedRows > 0) && (++rowsProcessed > displayedRows)) {
98                     break;
99                 }
100                 // process the row at currentRowIndex
101
setRowIndex(++currentRowIndex);
102                 // break if we've moved past the last row
103
if (!isRowAvailable()) {
104                     break;
105                 }
106                 Iterator JavaDoc kids = facet.getChildren().iterator();
107                 while (kids.hasNext()) {
108                     UIComponent kid = (UIComponent) kids.next();
109                     processKids(facesContext, phase, kid);
110                 }
111             }
112         } else {
113             // clear row index
114
setRowIndex(-1);
115             int rowsProcessed = 0;
116             int currentRowIndex = getFirst() - 1;
117             int displayedRows = getRows();
118             // loop over dataModel processing each row once
119
while (1 == 1) {
120                 // break if we have processed the number of rows requested
121
if ((displayedRows > 0) && (++rowsProcessed > displayedRows)) {
122                     break;
123                 }
124                 // process the row at currentRowIndex
125
setRowIndex(++currentRowIndex);
126                 // break if we've moved past the last row
127
if (!isRowAvailable()) {
128                     break;
129                 }
130                 Iterator JavaDoc kids = getChildren().iterator();
131                 while (kids.hasNext()) {
132                     UIComponent kid = (UIComponent) kids.next();
133                     processKids(facesContext, phase, kid);
134                 }
135             }
136             // reset row index
137
setRowIndex(-1);
138         }
139     }
140
141     public String JavaDoc getId() {
142         return String.valueOf(getRowIndex()) + getRowId();
143     }
144
145     public void processKids(FacesContext context, PhaseId phaseId,
146                             UIComponent kid) {
147         if (phaseId == PhaseId.APPLY_REQUEST_VALUES) {
148             kid.processDecodes(context);
149         } else if (phaseId == PhaseId.PROCESS_VALIDATIONS) {
150             kid.processValidators(context);
151         } else if (phaseId == PhaseId.UPDATE_MODEL_VALUES) {
152             kid.processUpdates(context);
153         } else {
154             throw new IllegalArgumentException JavaDoc();
155         }
156     }
157
158
159     protected void restoreChildrenState(FacesContext facesContext) {
160         Iterator JavaDoc children = null;
161         if (isHeaderFacet()) {
162             children = getFacets().values().iterator();
163         } else {
164             if (getRowIndex() < 0) {
165                 return;
166             } else {
167                 children = getChildren().iterator();
168             }
169         }
170         while (children.hasNext()) {
171             UIComponent child = (UIComponent) children.next();
172             restoreChildState(facesContext, child);
173         }
174     }
175
176     /**
177      * <p>Save state information for all descendant components, as described for
178      * <code>setRowIndex()</code>.</p>
179      */

180     protected void saveChildrenState(FacesContext facesContext) {
181         Iterator JavaDoc children = null;
182         if (isHeaderFacet()) {
183             children = getFacets().values().iterator();
184         } else {
185             if (getRowIndex() < 0) {
186                 return;
187             } else {
188                 children = getChildren().iterator();
189             }
190         }
191         while (children.hasNext()) {
192             UIComponent child = (UIComponent) children.next();
193             saveChildState(facesContext, child);
194         }
195     }
196
197     public int getRowId() {
198         if (getParent() != null &&
199             ((HtmlDataTable) getParent()).getRowIndex() >= 0) {
200             return ((HtmlDataTable) getParent()).getRowIndex();
201         } else {
202             return 0;
203         }
204     }
205
206     public String JavaDoc getClientId(FacesContext context) {
207         if (context == null) {
208             throw new NullPointerException JavaDoc();
209         }
210         String JavaDoc baseClientId = super.getClientId(context);
211         if (getRowIndex() >= 0) {
212             return (baseClientId + NamingContainer.SEPARATOR_CHAR +
213                     getRowIndex() + getRowId());
214         } else {
215             return (baseClientId);
216         }
217
218     }
219
220     public boolean isHeaderFacet() {
221         return (((HtmlDataTable) getParent()).getRowIndex() < 0) ? true : false;
222     }
223
224     public void processDecodes(FacesContext context) {
225
226         if (context == null) {
227             throw new NullPointerException JavaDoc();
228         }
229         if (!isRendered()) {
230             return;
231         }
232
233         dataModel = null; // Re-evaluate even with server-side state saving
234
if (null == savedChildren) {
235             savedChildren = new HashMap JavaDoc();
236         }
237         iterate(context, PhaseId.APPLY_REQUEST_VALUES);
238         decode(context);
239     }
240 }
Popular Tags