Source Code Cross Referenced for TableRenderer.java in  » J2EE » ICEfaces-1.6.1 » com » icesoft » faces » component » ext » renderkit » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » ICEfaces 1.6.1 » com.icesoft.faces.component.ext.renderkit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.renderkit;
035:
036:        import com.icesoft.faces.component.CSS_DEFAULT;
037:        import com.icesoft.faces.component.ext.HtmlDataTable;
038:        import com.icesoft.faces.component.ext.RowSelector;
039:        import com.icesoft.faces.component.ext.UIColumns;
040:        import com.icesoft.faces.component.ext.taglib.Util;
041:        import com.icesoft.faces.component.panelseries.UISeries;
042:        import com.icesoft.faces.context.DOMContext;
043:        import com.icesoft.faces.context.effects.JavascriptContext;
044:        import com.icesoft.faces.renderkit.dom_html_basic.HTML;
045:        import org.w3c.dom.Element;
046:        import org.w3c.dom.Node;
047:
048:        import javax.faces.component.UIColumn;
049:        import javax.faces.component.UIComponent;
050:        import javax.faces.context.FacesContext;
051:        import java.io.IOException;
052:        import java.util.*;
053:
054:        public class TableRenderer extends
055:                com.icesoft.faces.renderkit.dom_html_basic.TableRenderer {
056:
057:            private static final String SELECTED_ROWS = "sel_rows";
058:
059:            public String getComponentStyleClass(UIComponent uiComponent) {
060:                return (String) uiComponent.getAttributes().get("styleClass");
061:
062:            }
063:
064:            public String getHeaderClass(UIComponent component) {
065:                return (String) component.getAttributes().get("headerClass");
066:            }
067:
068:            public String getFooterClass(UIComponent component) {
069:                return (String) component.getAttributes().get("footerClass");
070:            }
071:
072:            // row styles are returned by reference
073:            public String[] getRowStyles(UIComponent uiComponent) {
074:                if (((String[]) getRowStyleClasses(uiComponent)).length <= 0) {
075:                    String[] rowStyles = new String[2];
076:                    rowStyles[0] = Util.getQualifiedStyleClass(uiComponent,
077:                            CSS_DEFAULT.TABLE_ROW_CLASS1);
078:                    rowStyles[1] = Util.getQualifiedStyleClass(uiComponent,
079:                            CSS_DEFAULT.TABLE_ROW_CLASS2);
080:                    return rowStyles;
081:                } else {
082:                    return getRowStyleClasses(uiComponent);
083:                }
084:            }
085:
086:            public String[] getHeaderStyles(UIComponent uiComponent) {
087:                if (((String[]) getHeaderStyleClasses(uiComponent)).length <= 0) {
088:                    String[] headerStyles = new String[2];
089:                    headerStyles[0] = Util.getQualifiedStyleClass(uiComponent,
090:                            CSS_DEFAULT.TABLE_COLUMN_HEADER_CLASS1);
091:                    headerStyles[1] = Util.getQualifiedStyleClass(uiComponent,
092:                            CSS_DEFAULT.TABLE_COLUMN_HEADER_CLASS2);
093:                    return headerStyles;
094:                } else {
095:                    return getHeaderStyleClasses(uiComponent);
096:                }
097:            }
098:
099:            public void writeColStyles(String[] columnStyles,
100:                    int columnStylesMaxIndex, int columnStyleIndex, Element td,
101:                    int colNumber, UIComponent uiComponent) {
102:                if (columnStyles.length > 0) {
103:                    if (columnStylesMaxIndex >= 0) {
104:                        td
105:                                .setAttribute("class",
106:                                        columnStyles[columnStyleIndex]);
107:                    }
108:                }
109:            }
110:
111:            protected void renderFacet(FacesContext facesContext,
112:                    UIComponent uiComponent, DOMContext domContext,
113:                    boolean header) throws IOException {
114:                String facet, tag, element, facetClass;
115:                if (header) {
116:                    facet = "header";
117:                    tag = HTML.THEAD_ELEM;
118:                    element = HTML.TH_ELEM;
119:                    facetClass = getHeaderClass(uiComponent);
120:                } else {
121:                    facet = "footer";
122:                    tag = HTML.TFOOT_ELEM;
123:                    element = HTML.TD_ELEM;
124:                    facetClass = getFooterClass(uiComponent);
125:                }
126:                UISeries uiData = (UISeries) uiComponent;
127:                uiData.setRowIndex(-1);
128:                Element root = (Element) domContext.getRootNode();
129:                if (isScrollable(uiComponent)) {
130:
131:                    if (header) {
132:                        // First table in first div path : table/tr/td/div/div0/table
133:                        root = getScrollableHeaderTableElement(root);
134:
135:                    } else {
136:                        // First table in second div path table/tr/td/div/div1/table
137:                        root = getScrollableBodyTableElement(root);
138:                    }
139:                }
140:                UIComponent headerFacet = getFacetByName(uiData, facet);
141:                boolean childHeaderFacetExists = childColumnHasFacetWithName(
142:                        uiData, facet);
143:                Element thead = null;
144:                if (headerFacet != null || childHeaderFacetExists) {
145:                    thead = domContext.createElement(tag);
146:                    root.appendChild(thead);
147:
148:                    if (header) {
149:                        renderTableHeader(facesContext, uiComponent,
150:                                headerFacet, thead, facetClass, element);
151:                        renderColumnHeader(facesContext, uiComponent, thead,
152:                                facet, element, header);
153:                    } else {
154:                        renderColumnHeader(facesContext, uiComponent, thead,
155:                                facet, element, header);
156:                        renderTableHeader(facesContext, uiComponent,
157:                                headerFacet, thead, facetClass, element);
158:
159:                    }
160:                    domContext.setCursorParent(root);
161:                }
162:            }
163:
164:            private void renderColumnHeader(FacesContext facesContext,
165:                    UIComponent uiComponent, Element thead, String facet,
166:                    String element, boolean header) throws IOException {
167:                StringTokenizer columnWitdths = getColumnWidths(uiComponent);
168:                DOMContext domContext = DOMContext.getDOMContext(facesContext,
169:                        uiComponent);
170:                Element tr = domContext.createElement("tr");
171:                thead.appendChild(tr);
172:                List childList = getRenderedChildColumnsList(uiComponent);
173:                Iterator childColumns = childList.iterator();
174:                String width = null;
175:                int columnIndex = 1;
176:                int headerStyleLength = getHeaderStyles(uiComponent).length;
177:                int styleIndex = 0;
178:                while (childColumns.hasNext()) {
179:
180:                    UIComponent nextColumn = (UIComponent) childColumns.next();
181:                    if (columnWitdths != null && columnWitdths.hasMoreTokens()) {
182:                        width = columnWitdths.nextToken();
183:                    } else {
184:                        if (isScrollable(uiComponent)) {
185:                            width = "150px";
186:                        } else {
187:                            width = null;
188:                        }
189:
190:                    }
191:                    if (nextColumn instanceof  UIColumn) {
192:                        processUIColumnHeader(facesContext, uiComponent,
193:                                (UIColumn) nextColumn, tr, domContext, facet,
194:                                element, width, columnIndex, styleIndex);
195:                        columnIndex++;
196:                    } else if (nextColumn instanceof  UIColumns) {
197:                        columnIndex = processUIColumnsHeader(facesContext,
198:                                uiComponent, (UIColumns) nextColumn, tr,
199:                                domContext, facet, element, width, columnIndex,
200:                                styleIndex, headerStyleLength);
201:                    }
202:
203:                    if (styleIndex++ == (headerStyleLength - 1)) {
204:                        styleIndex = 0;
205:                    }
206:                }
207:                if (header && isScrollable(uiComponent)) {
208:                    tr.appendChild(scrollBarSpacer(domContext, facesContext));
209:                }
210:            }
211:
212:            private void renderTableHeader(FacesContext facesContext,
213:                    UIComponent uiComponent, UIComponent headerFacet,
214:                    Element thead, String facetClass, String element)
215:                    throws IOException {
216:                DOMContext domContext = DOMContext.getDOMContext(facesContext,
217:                        uiComponent);
218:                if (headerFacet != null && headerFacet.isRendered()) {
219:
220:                    resetFacetChildId(headerFacet);
221:                    Element tr = domContext.createElement("tr");
222:                    thead.appendChild(tr);
223:                    Element th = domContext.createElement(element);
224:                    tr.appendChild(th);
225:                    if (facetClass != null) {
226:                        th.setAttribute("class", facetClass);
227:                    }
228:                    th.setAttribute("colspan", String
229:                            .valueOf(getNumberOfChildColumns(uiComponent)));
230:                    th.setAttribute("scope", "colgroup");
231:                    domContext.setCursorParent(th);
232:                    domContext.streamWrite(facesContext, uiComponent,
233:                            domContext.getRootNode(), th);
234:                    encodeParentAndChildren(facesContext, headerFacet);
235:                    if (isScrollable(uiComponent)) {
236:                        tr
237:                                .appendChild(scrollBarSpacer(domContext,
238:                                        facesContext));
239:                    }
240:                }
241:            }
242:
243:            private void processUIColumnHeader(FacesContext facesContext,
244:                    UIComponent uiComponent, UIColumn nextColumn, Element tr,
245:                    DOMContext domContext, String facet, String element,
246:                    String width, int columnIndex, int styleIndex)
247:                    throws IOException {
248:                HtmlDataTable htmlDataTable = (HtmlDataTable) uiComponent;
249:                Element th = domContext.createElement(element);
250:                tr.appendChild(th);
251:                if ("header".equalsIgnoreCase(facet)) {
252:                    th.setAttribute("class",
253:                            getHeaderStyles(uiComponent)[styleIndex]);
254:                } else {
255:                    th.setAttribute("class", getFooterClass(htmlDataTable));
256:                }
257:
258:                if (width != null) {
259:                    th.setAttribute("style", "width:" + width
260:                            + ";overflow:hidden;");
261:                }
262:                th.setAttribute("colgroup", "col");
263:                UIComponent nextFacet = getFacetByName(nextColumn, facet);
264:
265:                if (nextFacet != null) {
266:                    resetFacetChildId(nextFacet);
267:                    domContext.setCursorParent(th);
268:                    domContext.streamWrite(facesContext, uiComponent,
269:                            domContext.getRootNode(), th);
270:                    encodeParentAndChildren(facesContext, nextFacet);
271:                }
272:            }
273:
274:            private int processUIColumnsHeader(FacesContext facesContext,
275:                    UIComponent uiComponent, UIColumns nextColumn, Element tr,
276:                    DOMContext domContext, String facet, String element,
277:                    String width, int columnIndex, int styleIndex,
278:                    int headerStyleLength) throws IOException {
279:                HtmlDataTable htmlDataTable = (HtmlDataTable) uiComponent;
280:                int rowIndex = nextColumn.getFirst();
281:                //syleIndex should be increment here
282:                nextColumn.encodeBegin(facesContext);
283:                nextColumn.setRowIndex(rowIndex);
284:                while (nextColumn.isRowAvailable()) {
285:                    UIComponent headerFacet = getFacetByName(nextColumn, facet);
286:
287:                    if (headerFacet != null) {
288:                        Node oldParent = domContext.getCursorParent();
289:                        Element th = domContext.createElement(element);
290:                        tr.appendChild(th);
291:                        th.setAttribute("class",
292:                                getHeaderStyles(uiComponent)[styleIndex]);
293:                        if (width != null) {
294:                            th.setAttribute("style", "width:" + width + ";");
295:                        }
296:                        th.setAttribute("colgroup", "col");
297:                        domContext.setCursorParent(th);
298:                        domContext.streamWrite(facesContext, uiComponent,
299:                                domContext.getRootNode(), th);
300:
301:                        encodeParentAndChildren(facesContext, headerFacet);
302:                        domContext.setCursorParent(oldParent);
303:                    }
304:                    if (styleIndex++ == (headerStyleLength - 1)) {
305:                        styleIndex = 0;
306:                    }
307:                    rowIndex++;
308:                    columnIndex++;
309:                    nextColumn.setRowIndex(rowIndex);
310:                }
311:                nextColumn.setRowIndex(-1);
312:                return columnIndex;
313:            }
314:
315:            public void encodeChildren(FacesContext facesContext,
316:                    UIComponent uiComponent) throws IOException {
317:                validateParameters(facesContext, uiComponent, null);
318:                DOMContext domContext = DOMContext.getDOMContext(facesContext,
319:                        uiComponent);
320:                Element root = (Element) domContext.getRootNode();
321:
322:                if (isScrollable(uiComponent)) {
323:                    root = getScrollableBodyTableElement(root);
324:                }
325:                DOMContext.removeChildrenByTagName(root, HTML.TBODY_ELEM);
326:                Element tBody = (Element) domContext
327:                        .createElement(HTML.TBODY_ELEM);
328:                root.appendChild(tBody);
329:
330:                HtmlDataTable uiData = (HtmlDataTable) uiComponent;
331:                int rowIndex = uiData.getFirst();
332:                if (uiData.getRowCount() >= 0
333:                        && uiData.getRowCount() <= rowIndex) {
334:                    domContext.stepOver();
335:                    return;
336:                }
337:                uiData.setRowIndex(rowIndex);
338:                int numberOfRowsToDisplay = uiData.getRows();
339:                int countOfRowsDisplayed = 0;
340:                String rowStyles[] = getRowStyles(uiComponent);
341:                int rowStyleIndex = 0;
342:                int rowStylesMaxIndex = rowStyles.length - 1;
343:
344:                RowSelector rowSelector = getRowSelector(uiComponent);
345:                boolean rowSelectorFound = rowSelector != null;
346:                boolean toggleOnClick = false;
347:                String rowSelectionFunctionName = null;
348:                boolean rowSelectorCodeAdded = false; // Row selector code needs to be added to the first TD, adding it to the table body breaks safari
349:                Element scriptNode = null;
350:                String paramId = getSelectedRowParameterName(uiComponent
351:                        .getClientId(facesContext));
352:                if (rowSelectorFound) {
353:                    toggleOnClick = rowSelector.getToggleOnClick()
354:                            .booleanValue();
355:                    Element rowSelectedField = domContext
356:                            .createElement(HTML.INPUT_ELEM);
357:
358:                    rowSelectedField.setAttribute(HTML.ID_ATTR, paramId);
359:                    rowSelectedField.setAttribute(HTML.NAME_ATTR, paramId);
360:                    rowSelectedField.setAttribute(HTML.TYPE_ATTR, "hidden");
361:                    root.appendChild(rowSelectedField);
362:                    rowSelectionFunctionName = "ice_tableRowClicked";
363:                }
364:
365:                String columnStyles[] = getColumnStyleClasses(uiComponent);
366:                int columnStyleIndex;
367:                int columnStylesMaxIndex = columnStyles.length - 1;
368:                while (uiData.isRowAvailable()) {
369:                    columnStyleIndex = 0;
370:                    String selectedClass = null;
371:                    if (rowStylesMaxIndex >= 0) {
372:                        selectedClass = rowStyles[rowStyleIndex];
373:                    }
374:
375:                    Iterator childs = uiData.getChildren().iterator();
376:                    Element tr = (Element) domContext
377:                            .createElement(HTML.TR_ELEM);
378:                    if (rowSelectorFound && toggleOnClick) {
379:                        tr.setAttribute("onclick", rowSelectionFunctionName
380:                                + "('" + uiData.getRowIndex() + "', '"
381:                                + paramId + "');");
382:                    }
383:                    String id = uiComponent.getClientId(facesContext);
384:                    tr.setAttribute(HTML.ID_ATTR, id);
385:                    if (rowSelectorFound) {
386:                        if (Boolean.TRUE.equals(rowSelector.getValue())) {
387:                            selectedClass += " "
388:                                    + rowSelector.getSelectedClass();
389:                            tr
390:                                    .setAttribute(
391:                                            HTML.ONMOUSEOVER_ATTR,
392:                                            "this.className='"
393:                                                    + rowSelector
394:                                                            .getSelectedMouseOverClass()
395:                                                    + "'");
396:                        } else {
397:                            selectedClass += " " + rowSelector.getStyleClass();
398:                            tr.setAttribute(HTML.ONMOUSEOVER_ATTR,
399:                                    "this.className='"
400:                                            + rowSelector.getMouseOverClass()
401:                                            + "'");
402:                        }
403:                        tr.setAttribute(HTML.ONMOUSEOUT_ATTR,
404:                                "this.className='" + selectedClass + "'");
405:                    }
406:                    domContext.setCursorParent(tBody);
407:                    tBody.appendChild(tr);
408:
409:                    tr.setAttribute(HTML.CLASS_ATTR, selectedClass);
410:
411:                    if (rowStylesMaxIndex >= 0) { // Thanks denis tsyplakov
412:                        if (++rowStyleIndex > rowStylesMaxIndex) {
413:                            rowStyleIndex = 0;
414:                        }
415:                    }
416:                    int colNumber = 1;
417:                    StringTokenizer columnWitdths = getColumnWidths(uiData);
418:                    while (childs.hasNext()) {
419:                        UIComponent nextChild = (UIComponent) childs.next();
420:                        if (nextChild.isRendered()) {
421:                            if (nextChild instanceof  UIColumn) {
422:                                Element td = domContext
423:                                        .createElement(HTML.TD_ELEM);
424:                                if (!rowSelectorCodeAdded && scriptNode != null) {
425:                                    td.appendChild(scriptNode);
426:                                }
427:                                writeColStyles(columnStyles,
428:                                        columnStylesMaxIndex, columnStyleIndex,
429:                                        td, colNumber++, uiComponent);
430:
431:                                if (isScrollable(uiComponent)) {
432:                                    String width = "150px";
433:                                    if (columnWitdths != null
434:                                            && columnWitdths.hasMoreTokens()) {
435:                                        width = columnWitdths.nextToken();
436:                                    }
437:                                    td.setAttribute("style", "width:" + width
438:                                            + ";overflow:hidden;");
439:                                }
440:
441:                                tr.appendChild(td);
442:                                // if column styles exist, then apply the appropriate one
443:
444:                                if (++columnStyleIndex > columnStylesMaxIndex) {
445:                                    columnStyleIndex = 0;
446:                                }
447:
448:                                Node oldCursorParent = domContext
449:                                        .getCursorParent();
450:                                domContext.setCursorParent(td);
451:                                domContext.streamWrite(facesContext,
452:                                        uiComponent, domContext.getRootNode(),
453:                                        td);
454:
455:                                encodeParentAndChildren(facesContext, nextChild);
456:                                domContext.setCursorParent(oldCursorParent);
457:
458:                            } else if (nextChild instanceof  UIColumns) {
459:                                String width = null;
460:                                if (isScrollable(uiComponent)
461:                                        && columnWitdths != null
462:                                        && columnWitdths.hasMoreTokens()) {
463:                                    width = columnWitdths.nextToken();
464:
465:                                }
466:                                nextChild.encodeBegin(facesContext);
467:                                encodeColumns(facesContext, nextChild,
468:                                        domContext, tr, columnStyles,
469:                                        columnStylesMaxIndex, columnStyleIndex,
470:                                        colNumber, width);
471:                                nextChild.encodeEnd(facesContext);
472:                                colNumber = uiData.getColNumber();
473:                            }
474:                        }
475:
476:                    }
477:                    rowIndex++;
478:                    countOfRowsDisplayed++;
479:                    if ((numberOfRowsToDisplay > 0 && countOfRowsDisplayed >= numberOfRowsToDisplay)
480:                            || (uiData.getRowCount() >= 0 && rowIndex >= uiData
481:                                    .getRowCount())) {
482:                        break;
483:                    }
484:
485:                    uiData.setRowIndex(rowIndex);
486:                }
487:                uiData.setRowIndex(-1);
488:                domContext.stepOver();
489:                domContext.streamWrite(facesContext, uiComponent);
490:            }
491:
492:            private void encodeColumns(FacesContext facesContext,
493:                    UIComponent columns, DOMContext domContext, Node tr,
494:                    String[] columnStyles, int columnStylesMaxIndex,
495:                    int columnStyleIndex, int colNumber, String width)
496:                    throws IOException {
497:                UIColumns uiList = (UIColumns) columns;
498:                int rowIndex = uiList.getFirst();
499:                uiList.setRowIndex(rowIndex);
500:                int numberOfRowsToDisplay = uiList.getRows();
501:                int countOfRowsDisplayed = 0;
502:                domContext.setCursorParent(tr);
503:                Node oldCursorParent = domContext.getCursorParent();
504:                while (uiList.isRowAvailable()) {
505:                    if ((numberOfRowsToDisplay > 0)
506:                            && (countOfRowsDisplayed >= numberOfRowsToDisplay)) {
507:                        break;
508:                    }
509:                    Iterator childs;
510:                    childs = columns.getChildren().iterator();
511:                    Element td = domContext.createElement(HTML.TD_ELEM);
512:                    if (width != null) {
513:
514:                        td.setAttribute("style", "width:" + width
515:                                + ";overflow:hidden;");
516:                    }
517:                    domContext.setCursorParent(oldCursorParent);
518:                    tr.appendChild(td);
519:                    while (childs.hasNext()) {
520:                        UIComponent nextChild = (UIComponent) childs.next();
521:                        if (nextChild.isRendered()) {
522:                            domContext.setCursorParent(td);
523:                            writeColStyles(columnStyles, columnStylesMaxIndex,
524:                                    columnStyleIndex, td, colNumber++, columns
525:                                            .getParent());
526:                            if (++columnStyleIndex > columnStylesMaxIndex) {
527:                                columnStyleIndex = 0;
528:                            }
529:                            encodeParentAndChildren(facesContext, nextChild);
530:                            domContext.setCursorParent(oldCursorParent);
531:                        }
532:                    }
533:                    rowIndex++;
534:                    countOfRowsDisplayed++;
535:                    uiList.setRowIndex(rowIndex);
536:                }
537:                ((HtmlDataTable) uiList.getParent()).setColNumber(colNumber);
538:                uiList.setRowIndex(-1);
539:            }
540:
541:            protected List getRenderedChildColumnsList(UIComponent component) {
542:                List results = new ArrayList();
543:                Iterator kids = component.getChildren().iterator();
544:                while (kids.hasNext()) {
545:                    UIComponent kid = (UIComponent) kids.next();
546:                    if (((kid instanceof  UIColumn) && kid.isRendered())
547:                            || kid instanceof  UIColumns) {
548:                        results.add(kid);
549:                    }
550:                }
551:                return results;
552:            }
553:
554:            protected boolean childColumnHasFacetWithName(
555:                    UIComponent component, String facetName) {
556:                Iterator childColumns = getRenderedChildColumnsIterator(component);
557:                while (childColumns.hasNext()) {
558:                    UIComponent nextChildColumn = (UIComponent) childColumns
559:                            .next();
560:                    if (getFacetByName(nextChildColumn, facetName) != null) {
561:                        return true;
562:                    }
563:                }
564:                return false;
565:            }
566:
567:            public static String getSelectedRowParameterName(String dataTableId) {
568:                // strip the last ':' because the Datatables client Id changes for each iterator
569:                int i = dataTableId.lastIndexOf(":");
570:                dataTableId = dataTableId.substring(0, i);
571:                return dataTableId + SELECTED_ROWS;
572:            }
573:
574:            public static RowSelector getRowSelector(UIComponent comp) {
575:                if (comp instanceof  RowSelector) {
576:                    return (RowSelector) comp;
577:                }
578:                Iterator iter = comp.getChildren().iterator();
579:                while (iter.hasNext()) {
580:                    UIComponent kid = (UIComponent) iter.next();
581:                    if (kid instanceof  HtmlDataTable) {
582:                        // Nested HtmlDataTable might be a peer of
583:                        //  a later, valid RowSelector, so don't
584:                        //  traverse in, but keep looking
585:                        continue;
586:                    }
587:                    RowSelector rs = getRowSelector(kid);
588:                    if (rs != null) {
589:                        return rs;
590:                    }
591:                }
592:                return null;
593:            }
594:
595:            private int rowSelectorNumber(FacesContext context) {
596:                Map m = context.getExternalContext().getRequestMap();
597:                String key = RowSelector.class.getName() + "-Selector";
598:                Integer I = (Integer) m.get(key);
599:                int i = 0;
600:                if (I != null) {
601:                    i = I.intValue();
602:                    i++;
603:                }
604:
605:                I = new Integer(i);
606:                m.put(key, I);
607:                return i;
608:            }
609:
610:            protected int getNumberOfChildColumns(UIComponent component) {
611:                int size = getRenderedChildColumnsList(component).size();
612:                Iterator it = getRenderedChildColumnsList(component).iterator();
613:                while (it.hasNext()) {
614:                    UIComponent uiComponent = (UIComponent) it.next();
615:                    if (uiComponent instanceof  UIColumns) {
616:                        size += ((UIColumns) uiComponent).getRowCount();
617:                    }
618:                }
619:                return size;
620:            }
621:
622:            protected String[] getColumnStyleClasses(UIComponent uiComponent) {
623:                String[] columnStyles = super 
624:                        .getColumnStyleClasses(uiComponent);
625:                if (columnStyles.length == 0) {
626:                    columnStyles = new String[2];
627:                    columnStyles[0] = Util.getQualifiedStyleClass(uiComponent,
628:                            CSS_DEFAULT.TABLE_COLUMN_CLASS1);
629:                    columnStyles[1] = Util.getQualifiedStyleClass(uiComponent,
630:                            CSS_DEFAULT.TABLE_COLUMN_CLASS2);
631:                } else {
632:                    for (int i = 0; i < columnStyles.length; i++) {
633:                        columnStyles[i] = Util
634:                                .getQualifiedStyleClass(uiComponent,
635:                                        columnStyles[i],
636:                                        CSS_DEFAULT.TABLE_COLUMN_CLASS,
637:                                        "columnClasses");
638:                    }
639:                }
640:                return columnStyles;
641:            }
642:
643:            public String[] getRowStyleClasses(UIComponent uiComponent) {
644:                String[] rowClasses = super .getRowStyleClasses(uiComponent);
645:                for (int i = 0; i < rowClasses.length; i++) {
646:                    rowClasses[i] = Util.getQualifiedStyleClass(uiComponent,
647:                            rowClasses[i], CSS_DEFAULT.TABLE_ROW_CLASS,
648:                            "rowClasses");
649:                }
650:                return rowClasses;
651:            }
652:
653:            public String[] getHeaderStyleClasses(UIComponent uiComponent) {
654:                String[] headerClasses = getStyleClasses(uiComponent,
655:                        "headerClasses");
656:                for (int i = 0; i < headerClasses.length; i++) {
657:                    headerClasses[i] = Util.getQualifiedStyleClass(uiComponent,
658:                            headerClasses[i],
659:                            CSS_DEFAULT.TABLE_COLUMN_HEADER_CLASS,
660:                            "headerClasses");
661:                }
662:                return headerClasses;
663:            }
664:
665:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.