Source Code Cross Referenced for TablePeer.java in  » Ajax » NextApp-Echo2 » nextapp » echo2 » webcontainer » syncpeer » 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 » Ajax » NextApp Echo2 » nextapp.echo2.webcontainer.syncpeer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003:         * Copyright (C) 2002-2005 NextApp, Inc.
004:         *
005:         * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006:         *
007:         * The contents of this file are subject to the Mozilla Public License Version
008:         * 1.1 (the "License"); you may not use this file except in compliance with
009:         * the License. You may obtain a copy of the License at
010:         * http://www.mozilla.org/MPL/
011:         *
012:         * Software distributed under the License is distributed on an "AS IS" basis,
013:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014:         * for the specific language governing rights and limitations under the
015:         * License.
016:         *
017:         * Alternatively, the contents of this file may be used under the terms of
018:         * either the GNU General Public License Version 2 or later (the "GPL"), or
019:         * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020:         * in which case the provisions of the GPL or the LGPL are applicable instead
021:         * of those above. If you wish to allow use of your version of this file only
022:         * under the terms of either the GPL or the LGPL, and not to allow others to
023:         * use your version of this file under the terms of the MPL, indicate your
024:         * decision by deleting the provisions above and replace them with the notice
025:         * and other provisions required by the GPL or the LGPL. If you do not delete
026:         * the provisions above, a recipient may use your version of this file under
027:         * the terms of any one of the MPL, the GPL or the LGPL.
028:         */
029:
030:        package nextapp.echo2.webcontainer.syncpeer;
031:
032:        import org.w3c.dom.Document;
033:        import org.w3c.dom.DocumentFragment;
034:        import org.w3c.dom.Element;
035:        import org.w3c.dom.Node;
036:        import org.w3c.dom.NodeList;
037:
038:        import nextapp.echo2.app.Border;
039:        import nextapp.echo2.app.Color;
040:        import nextapp.echo2.app.Component;
041:        import nextapp.echo2.app.Extent;
042:        import nextapp.echo2.app.FillImage;
043:        import nextapp.echo2.app.Font;
044:        import nextapp.echo2.app.ImageReference;
045:        import nextapp.echo2.app.Insets;
046:        import nextapp.echo2.app.LayoutData;
047:        import nextapp.echo2.app.Table;
048:        import nextapp.echo2.app.layout.TableLayoutData;
049:        import nextapp.echo2.app.list.ListSelectionModel;
050:        import nextapp.echo2.app.table.TableColumnModel;
051:        import nextapp.echo2.app.update.ServerComponentUpdate;
052:        import nextapp.echo2.webcontainer.ActionProcessor;
053:        import nextapp.echo2.webcontainer.ContainerInstance;
054:        import nextapp.echo2.webcontainer.DomUpdateSupport;
055:        import nextapp.echo2.webcontainer.PartialUpdateManager;
056:        import nextapp.echo2.webcontainer.PropertyUpdateProcessor;
057:        import nextapp.echo2.webcontainer.RenderContext;
058:        import nextapp.echo2.webcontainer.ComponentSynchronizePeer;
059:        import nextapp.echo2.webcontainer.SynchronizePeerFactory;
060:        import nextapp.echo2.webcontainer.image.ImageRenderSupport;
061:        import nextapp.echo2.webcontainer.propertyrender.BorderRender;
062:        import nextapp.echo2.webcontainer.propertyrender.CellLayoutDataRender;
063:        import nextapp.echo2.webcontainer.propertyrender.ColorRender;
064:        import nextapp.echo2.webcontainer.propertyrender.ExtentRender;
065:        import nextapp.echo2.webcontainer.propertyrender.FillImageRender;
066:        import nextapp.echo2.webcontainer.propertyrender.FontRender;
067:        import nextapp.echo2.webcontainer.propertyrender.InsetsRender;
068:        import nextapp.echo2.webrender.ClientProperties;
069:        import nextapp.echo2.webrender.ServerMessage;
070:        import nextapp.echo2.webrender.Service;
071:        import nextapp.echo2.webrender.WebRenderServlet;
072:        import nextapp.echo2.webrender.output.CssStyle;
073:        import nextapp.echo2.webrender.servermessage.DomUpdate;
074:        import nextapp.echo2.webrender.service.JavaScriptService;
075:        import nextapp.echo2.webrender.util.DomUtil;
076:
077:        /**
078:         * Synchronization peer for <code>nextapp.echo2.app.Table</code> components.
079:         * <p>
080:         * This class should not be extended or used by classes outside of the
081:         * Echo framework.
082:         */
083:        public class TablePeer implements  ActionProcessor,
084:                ComponentSynchronizePeer, ImageRenderSupport,
085:                PropertyUpdateProcessor {
086:
087:            //TODO: Add full support for partial rendering on row insertions/deletions.
088:
089:            /**
090:             * A string of periods used for the IE 100% Table Width workaround.
091:             */
092:            private static final String SIZING_DOTS = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
093:                    + ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ";
094:
095:            private static final String[] TABLE_INIT_KEYS = new String[] {
096:                    "rollover-style", "selection-style" };
097:
098:            private static final String PROPERTY_SELECTION = "selection";
099:
100:            private static final String IMAGE_ID_ROLLOVER_BACKGROUND = "rolloverBackground";
101:            private static final String IMAGE_ID_SELECTION_BACKGROUND = "selectionBackground";
102:
103:            /**
104:             * Service to provide supporting JavaScript library.
105:             */
106:            private static final Service TABLE_SERVICE = JavaScriptService
107:                    .forResource("Echo.Table",
108:                            "/nextapp/echo2/webcontainer/resource/js/Table.js");
109:
110:            static {
111:                WebRenderServlet.getServiceRegistry().add(TABLE_SERVICE);
112:            }
113:
114:            protected PartialUpdateManager propertyRenderRegistry;
115:
116:            /**
117:             * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#getContainerId(nextapp.echo2.app.Component)
118:             */
119:            public String getContainerId(Component child) {
120:                return ContainerInstance.getElementId(child.getParent())
121:                        + "_cell_" + child.getRenderId();
122:            }
123:
124:            /**
125:             * @see nextapp.echo2.webcontainer.image.ImageRenderSupport#getImage(nextapp.echo2.app.Component, java.lang.String)
126:             */
127:            public ImageReference getImage(Component component, String imageId) {
128:                if (IMAGE_ID_ROLLOVER_BACKGROUND.equals(imageId)) {
129:                    FillImage backgroundImage = (FillImage) component
130:                            .getRenderProperty(Table.PROPERTY_ROLLOVER_BACKGROUND_IMAGE);
131:                    if (backgroundImage == null) {
132:                        return null;
133:                    } else {
134:                        return backgroundImage.getImage();
135:                    }
136:                } else if (IMAGE_ID_SELECTION_BACKGROUND.equals(imageId)) {
137:                    FillImage backgroundImage = (FillImage) component
138:                            .getRenderProperty(Table.PROPERTY_SELECTION_BACKGROUND_IMAGE);
139:                    if (backgroundImage == null) {
140:                        return null;
141:                    } else {
142:                        return backgroundImage.getImage();
143:                    }
144:                } else {
145:                    // Retrieve CellLayoutData background image if applicable.
146:                    return CellLayoutDataRender
147:                            .getCellLayoutDataBackgroundImage(component,
148:                                    imageId);
149:                }
150:            }
151:
152:            /**
153:             * Returns the <code>TableLayoutData</code> of the given child,
154:             * or null if it does not provide layout data.
155:             *
156:             * @param child the child component
157:             * @return the layout data
158:             * @throws java.lang.RuntimeException if the the provided
159:             *         <code>LayoutData</code> is not a <code>TableLayoutData</code>
160:             */
161:            private TableLayoutData getLayoutData(Component child) {
162:                LayoutData layoutData = (LayoutData) child
163:                        .getRenderProperty(Component.PROPERTY_LAYOUT_DATA);
164:                if (layoutData == null) {
165:                    return null;
166:                } else if (layoutData instanceof  TableLayoutData) {
167:                    return (TableLayoutData) layoutData;
168:                } else {
169:                    throw new RuntimeException(
170:                            "Invalid LayoutData for Table Child: "
171:                                    + layoutData.getClass().getName());
172:                }
173:            }
174:
175:            /**
176:             * @see nextapp.echo2.webcontainer.ActionProcessor#processAction(nextapp.echo2.webcontainer.ContainerInstance, 
177:             *      nextapp.echo2.app.Component, org.w3c.dom.Element)
178:             */
179:            public void processAction(ContainerInstance ci,
180:                    Component component, Element actionElement) {
181:                ci
182:                        .getUpdateManager()
183:                        .getClientUpdateManager()
184:                        .setComponentAction(component, Table.INPUT_ACTION, null);
185:            }
186:
187:            /**
188:             * @see nextapp.echo2.webcontainer.PropertyUpdateProcessor#processPropertyUpdate(
189:             *      nextapp.echo2.webcontainer.ContainerInstance, nextapp.echo2.app.Component, org.w3c.dom.Element)
190:             */
191:            public void processPropertyUpdate(ContainerInstance ci,
192:                    Component component, Element propertyElement) {
193:                String propertyName = propertyElement
194:                        .getAttribute(PropertyUpdateProcessor.PROPERTY_NAME);
195:                if (PROPERTY_SELECTION.equals(propertyName)) {
196:                    Element[] optionElements = DomUtil
197:                            .getChildElementsByTagName(propertyElement, "row");
198:                    int[] selectedIndices = new int[optionElements.length];
199:                    for (int i = 0; i < optionElements.length; ++i) {
200:                        selectedIndices[i] = Integer.parseInt(optionElements[i]
201:                                .getAttribute("index"));
202:                    }
203:                    ci.getUpdateManager().getClientUpdateManager()
204:                            .setComponentProperty(component,
205:                                    Table.SELECTION_CHANGED_PROPERTY,
206:                                    selectedIndices);
207:                }
208:            }
209:
210:            /**
211:             * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderAdd(nextapp.echo2.webcontainer.RenderContext, 
212:             *      nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String, nextapp.echo2.app.Component)
213:             */
214:            public void renderAdd(RenderContext rc,
215:                    ServerComponentUpdate update, String targetId,
216:                    Component component) {
217:                Table table = (Table) component;
218:                Border border = (Border) table
219:                        .getRenderProperty(Table.PROPERTY_BORDER);
220:                Insets tableInsets = (Insets) table
221:                        .getRenderProperty(Table.PROPERTY_INSETS);
222:                String defaultInsetsAttributeValue = tableInsets == null ? "0px"
223:                        : InsetsRender.renderCssAttributeValue(tableInsets);
224:                CssStyle styleCss = new CssStyle();
225:                styleCss.setAttribute("padding", defaultInsetsAttributeValue);
226:                BorderRender.renderToStyle(styleCss, border);
227:                DomUpdate.renderStyleSheetAddRule(rc.getServerMessage(),
228:                        "TD.c-" + component.getRenderId(), styleCss
229:                                .renderInline());
230:
231:                Element domAddTableElement = DomUpdate.renderElementAdd(rc
232:                        .getServerMessage());
233:                DocumentFragment htmlFragment = rc.getServerMessage()
234:                        .getDocument().createDocumentFragment();
235:                renderHtml(rc, update, htmlFragment, component);
236:                DomUpdate.renderElementAddContent(rc.getServerMessage(),
237:                        domAddTableElement, targetId, htmlFragment);
238:            }
239:
240:            /**
241:             * Renders a child component.
242:             * 
243:             * @param rc the relevant <code>RenderContext</code>
244:             * @param update the update
245:             * @param parentElement the HTML element which should contain the child
246:             * @param child the child component to render
247:             */
248:            private void renderAddChild(RenderContext rc,
249:                    ServerComponentUpdate update, Element parentElement,
250:                    Component child) {
251:                if (!child.isVisible()) {
252:                    // Do nothing.
253:                    return;
254:                }
255:                ComponentSynchronizePeer syncPeer = SynchronizePeerFactory
256:                        .getPeerForComponent(child.getClass());
257:                if (syncPeer instanceof  DomUpdateSupport) {
258:                    ((DomUpdateSupport) syncPeer).renderHtml(rc, update,
259:                            parentElement, child);
260:                } else {
261:                    syncPeer
262:                            .renderAdd(rc, update, getContainerId(child), child);
263:                }
264:            }
265:
266:            /**
267:             * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderDispose(nextapp.echo2.webcontainer.RenderContext, 
268:             *      nextapp.echo2.app.update.ServerComponentUpdate, nextapp.echo2.app.Component)
269:             */
270:            public void renderDispose(RenderContext rc,
271:                    ServerComponentUpdate update, Component component) {
272:                rc.getServerMessage().addLibrary(TABLE_SERVICE.getId());
273:                renderDisposeDirective(rc, (Table) component);
274:            }
275:
276:            /**
277:             * Renders a directive to the outgoing <code>ServerMessage</code> to 
278:             * dispose the state of a table, performing tasks such as unregistering
279:             * event listeners on the client.
280:             * 
281:             * @param rc the relevant <code>RenderContext</code>
282:             * @param table the table
283:             */
284:            private void renderDisposeDirective(RenderContext rc, Table table) {
285:                //       DomUpdate.renderElementRemove(rc.getServerMessage(), ContainerInstance.getElementId(table) + "_style");
286:                DomUpdate.renderStyleSheetRemoveRule(rc.getServerMessage(),
287:                        "TD.c-" + table.getRenderId());
288:
289:                ServerMessage serverMessage = rc.getServerMessage();
290:                Element itemizedUpdateElement = serverMessage
291:                        .getItemizedDirective(ServerMessage.GROUP_ID_PREREMOVE,
292:                                "EchoTable.MessageProcessor", "dispose",
293:                                new String[0], new String[0]);
294:                Element itemElement = serverMessage.getDocument()
295:                        .createElement("item");
296:                itemElement.setAttribute("eid", ContainerInstance
297:                        .getElementId(table));
298:                itemizedUpdateElement.appendChild(itemElement);
299:            }
300:
301:            /**
302:             * @see nextapp.echo2.webcontainer.DomUpdateSupport#renderHtml(nextapp.echo2.webcontainer.RenderContext, 
303:             *      nextapp.echo2.app.update.ServerComponentUpdate, org.w3c.dom.Node, nextapp.echo2.app.Component)
304:             */
305:            public void renderHtml(RenderContext rc,
306:                    ServerComponentUpdate update, Node parentNode,
307:                    Component component) {
308:                ServerMessage serverMessage = rc.getServerMessage();
309:                serverMessage.addLibrary(TABLE_SERVICE.getId());
310:                Table table = (Table) component;
311:
312:                renderInitDirective(rc, table);
313:
314:                Border border = (Border) table
315:                        .getRenderProperty(Table.PROPERTY_BORDER);
316:                Extent borderSize = border == null ? null : border.getSize();
317:
318:                String elementId = ContainerInstance.getElementId(table);
319:
320:                Document document = parentNode.getOwnerDocument();
321:                Element tableElement = document.createElement("table");
322:                tableElement.setAttribute("id", elementId);
323:
324:                CssStyle tableCssStyle = new CssStyle();
325:                tableCssStyle.setAttribute("border-collapse", "collapse");
326:
327:                if (((Boolean) table.getRenderProperty(
328:                        Table.PROPERTY_SELECTION_ENABLED, Boolean.FALSE))
329:                        .booleanValue()) {
330:                    tableCssStyle.setAttribute("cursor", "pointer");
331:                }
332:
333:                Insets tableInsets = (Insets) table
334:                        .getRenderProperty(Table.PROPERTY_INSETS);
335:
336:                String defaultInsetsAttributeValue = tableInsets == null ? "0px"
337:                        : InsetsRender.renderCssAttributeValue(tableInsets);
338:
339:                ColorRender.renderToStyle(tableCssStyle, component);
340:                FontRender.renderToStyle(tableCssStyle, component);
341:                BorderRender.renderToStyle(tableCssStyle, border);
342:                if (borderSize != null) {
343:                    if (!rc
344:                            .getContainerInstance()
345:                            .getClientProperties()
346:                            .getBoolean(
347:                                    ClientProperties.QUIRK_CSS_BORDER_COLLAPSE_INSIDE)) {
348:                        tableCssStyle.setAttribute("margin", ExtentRender
349:                                .renderCssAttributeValueHalf(borderSize));
350:                    }
351:                }
352:
353:                Extent width = (Extent) table
354:                        .getRenderProperty(Table.PROPERTY_WIDTH);
355:                boolean render100PercentWidthWorkaround = false;
356:                if (rc
357:                        .getContainerInstance()
358:                        .getClientProperties()
359:                        .getBoolean(
360:                                ClientProperties.QUIRK_IE_TABLE_PERCENT_WIDTH_SCROLLBAR_ERROR)) {
361:                    if (width != null && width.getUnits() == Extent.PERCENT
362:                            && width.getValue() == 100) {
363:                        width = null;
364:                        render100PercentWidthWorkaround = true;
365:                    }
366:                }
367:                ExtentRender.renderToStyle(tableCssStyle, "width", width);
368:
369:                tableElement
370:                        .setAttribute("style", tableCssStyle.renderInline());
371:
372:                parentNode.appendChild(tableElement);
373:
374:                TableColumnModel columnModel = table.getColumnModel();
375:                int columnCount = columnModel.getColumnCount();
376:
377:                boolean someColumnsHaveWidths = false;
378:                for (int i = 0; i < columnCount; ++i) {
379:                    if (columnModel.getColumn(i).getWidth() != null) {
380:                        someColumnsHaveWidths = true;
381:                    }
382:                }
383:                if (someColumnsHaveWidths) {
384:                    Element colGroupElement = document
385:                            .createElement("colgroup");
386:                    tableElement.appendChild(colGroupElement);
387:
388:                    for (int i = 0; i < columnCount; ++i) {
389:                        Element colElement = document.createElement("col");
390:                        Extent columnWidth = columnModel.getColumn(i)
391:                                .getWidth();
392:                        if (columnWidth != null) {
393:                            colElement.setAttribute("width", ExtentRender
394:                                    .renderCssAttributeValue(columnWidth));
395:                        }
396:                        colGroupElement.appendChild(colElement);
397:                    }
398:                }
399:
400:                Element tbodyElement = document.createElement("tbody");
401:                tbodyElement.setAttribute("id", elementId + "_tbody");
402:                tableElement.appendChild(tbodyElement);
403:
404:                Element firstTrElement = null;
405:
406:                if (table.isHeaderVisible()) {
407:                    firstTrElement = renderRow(rc, update, tbodyElement, table,
408:                            Table.HEADER_ROW, defaultInsetsAttributeValue);
409:                }
410:
411:                int rows = table.getModel().getRowCount();
412:                for (int rowIndex = 0; rowIndex < rows; ++rowIndex) {
413:                    if (firstTrElement == null && rowIndex == 0) {
414:                        firstTrElement = renderRow(rc, update, tbodyElement,
415:                                table, rowIndex, defaultInsetsAttributeValue);
416:                    } else {
417:                        renderRow(rc, update, tbodyElement, table, rowIndex,
418:                                defaultInsetsAttributeValue);
419:                    }
420:                }
421:
422:                if (render100PercentWidthWorkaround && firstTrElement != null) {
423:                    // Render string of "sizing dots" in first row of cells.
424:                    NodeList childNodes = firstTrElement.getChildNodes();
425:                    int length = childNodes.getLength();
426:                    for (int i = 0; i < length; ++i) {
427:                        if (!"td".equals(childNodes.item(i).getNodeName())) {
428:                            continue;
429:                        }
430:                        Element tdElement = (Element) childNodes.item(i);
431:                        Element sizingDivElement = document
432:                                .createElement("div");
433:                        sizingDivElement.setAttribute("style",
434:                                "font-size:50px;height:0px;overflow:hidden;");
435:                        sizingDivElement.appendChild(document
436:                                .createTextNode(SIZING_DOTS));
437:                        tdElement.appendChild(sizingDivElement);
438:                    }
439:                }
440:            }
441:
442:            /**
443:             * Renders a directive to the outgoing <code>ServerMessage</code> to 
444:             * initialize the state of a <code>Table</code>, performing tasks such as 
445:             * registering event listeners on the client.
446:             * 
447:             * @param rc the relevant <code>RenderContext</code>
448:             * @param table the table
449:             */
450:            private void renderInitDirective(RenderContext rc, Table table) {
451:                String elementId = ContainerInstance.getElementId(table);
452:                ServerMessage serverMessage = rc.getServerMessage();
453:                Document document = serverMessage.getDocument();
454:
455:                boolean rolloverEnabled = ((Boolean) table.getRenderProperty(
456:                        Table.PROPERTY_ROLLOVER_ENABLED, Boolean.FALSE))
457:                        .booleanValue();
458:                boolean selectionEnabled = ((Boolean) table.getRenderProperty(
459:                        Table.PROPERTY_SELECTION_ENABLED, Boolean.FALSE))
460:                        .booleanValue();
461:
462:                String rolloverStyle = "";
463:                if (rolloverEnabled) {
464:                    CssStyle rolloverCssStyle = new CssStyle();
465:                    ColorRender
466:                            .renderToStyle(
467:                                    rolloverCssStyle,
468:                                    (Color) table
469:                                            .getRenderProperty(Table.PROPERTY_ROLLOVER_FOREGROUND),
470:                                    (Color) table
471:                                            .getRenderProperty(Table.PROPERTY_ROLLOVER_BACKGROUND));
472:                    FontRender.renderToStyle(rolloverCssStyle, (Font) table
473:                            .getRenderProperty(Table.PROPERTY_ROLLOVER_FONT));
474:                    FillImageRender
475:                            .renderToStyle(
476:                                    rolloverCssStyle,
477:                                    rc,
478:                                    this ,
479:                                    table,
480:                                    IMAGE_ID_ROLLOVER_BACKGROUND,
481:                                    (FillImage) table
482:                                            .getRenderProperty(Table.PROPERTY_ROLLOVER_BACKGROUND_IMAGE),
483:                                    FillImageRender.FLAG_DISABLE_FIXED_MODE);
484:                    if (rolloverCssStyle.hasAttributes()) {
485:                        rolloverStyle = rolloverCssStyle.renderInline();
486:                    }
487:                }
488:
489:                String selectionStyle = "";
490:                if (selectionEnabled) {
491:                    CssStyle selectionCssStyle = new CssStyle();
492:                    ColorRender
493:                            .renderToStyle(
494:                                    selectionCssStyle,
495:                                    (Color) table
496:                                            .getRenderProperty(Table.PROPERTY_SELECTION_FOREGROUND),
497:                                    (Color) table
498:                                            .getRenderProperty(Table.PROPERTY_SELECTION_BACKGROUND));
499:                    FontRender.renderToStyle(selectionCssStyle, (Font) table
500:                            .getRenderProperty(Table.PROPERTY_SELECTION_FONT));
501:                    FillImageRender
502:                            .renderToStyle(
503:                                    selectionCssStyle,
504:                                    rc,
505:                                    this ,
506:                                    table,
507:                                    IMAGE_ID_SELECTION_BACKGROUND,
508:                                    (FillImage) table
509:                                            .getRenderProperty(Table.PROPERTY_SELECTION_BACKGROUND_IMAGE),
510:                                    FillImageRender.FLAG_DISABLE_FIXED_MODE);
511:                    if (selectionCssStyle.hasAttributes()) {
512:                        selectionStyle = selectionCssStyle.renderInline();
513:                    }
514:                }
515:
516:                Element itemizedUpdateElement = serverMessage
517:                        .getItemizedDirective(
518:                                ServerMessage.GROUP_ID_POSTUPDATE,
519:                                "EchoTable.MessageProcessor", "init",
520:                                TABLE_INIT_KEYS, new String[] { rolloverStyle,
521:                                        selectionStyle });
522:                Element itemElement = document.createElement("item");
523:                itemElement.setAttribute("eid", elementId);
524:                if (table.isHeaderVisible()) {
525:                    itemElement.setAttribute("header-visible", "true");
526:                }
527:
528:                if (table.hasActionListeners()) {
529:                    itemElement.setAttribute("server-notify", "true");
530:                }
531:
532:                if (rolloverEnabled) {
533:                    itemElement.setAttribute("rollover-enabled", "true");
534:                }
535:
536:                if (selectionEnabled) {
537:                    itemElement.setAttribute("selection-enabled", "true");
538:                    ListSelectionModel selectionModel = table
539:                            .getSelectionModel();
540:                    if (selectionModel.getSelectionMode() == ListSelectionModel.MULTIPLE_SELECTION) {
541:                        itemElement.setAttribute("selection-mode", "multiple");
542:                    }
543:                    if (selectionModel.getMinSelectedIndex() != -1) {
544:                        Element selectionElement = document
545:                                .createElement("selection");
546:                        int minimumIndex = selectionModel.getMinSelectedIndex();
547:                        int maximumIndex = selectionModel.getMaxSelectedIndex();
548:                        if (maximumIndex > table.getModel().getRowCount() - 1) {
549:                            maximumIndex = table.getModel().getRowCount() - 1;
550:                        }
551:                        for (int i = minimumIndex; i <= maximumIndex; ++i) {
552:                            if (selectionModel.isSelectedIndex(i)) {
553:                                Element rowElement = document
554:                                        .createElement("row");
555:                                rowElement.setAttribute("index", Integer
556:                                        .toString(i));
557:                                selectionElement.appendChild(rowElement);
558:                            }
559:                        }
560:                        itemElement.appendChild(selectionElement);
561:                    }
562:                }
563:
564:                if (!table.isRenderEnabled()) {
565:                    itemElement.setAttribute("enabled", "false");
566:                }
567:
568:                itemizedUpdateElement.appendChild(itemElement);
569:            }
570:
571:            /**
572:             * Renders a single row of a table.
573:             * 
574:             * @param rc the relevant <code>RenderContext</code>
575:             * @param update the <code>ServerComponentUpdate</code> being processed
576:             * @param tbodyElement the <code>tbody</code> element to which to append 
577:             *        the rendered content
578:             * @param table the <code>Table</code> being rendered
579:             * @param rowIndex the row to render
580:             * @param defaultInsetsAttributeValue the default CSS padding attribute value
581:             * @return the rendered TR element
582:             */
583:            private Element renderRow(RenderContext rc,
584:                    ServerComponentUpdate update, Element tbodyElement,
585:                    Table table, int rowIndex,
586:                    String defaultInsetsAttributeValue) {
587:                Document document = tbodyElement.getOwnerDocument();
588:                String elementId = ContainerInstance.getElementId(table);
589:
590:                Element trElement = document.createElement("tr");
591:                if (rowIndex == Table.HEADER_ROW) {
592:                    trElement.setAttribute("id", elementId + "_tr_header");
593:                } else {
594:                    trElement.setAttribute("id", elementId + "_tr_" + rowIndex);
595:                }
596:                tbodyElement.appendChild(trElement);
597:
598:                String className = "c-" + table.getRenderId();
599:
600:                boolean inlineStyleRequired = rc
601:                        .getContainerInstance()
602:                        .getClientProperties()
603:                        .getBoolean(
604:                                ClientProperties.NOT_SUPPORTED_CSS_MANIPULATION);
605:                Border border = null;
606:                if (inlineStyleRequired) {
607:                    border = (Border) table
608:                            .getRenderProperty(Table.PROPERTY_BORDER);
609:                }
610:
611:                int columns = table.getColumnModel().getColumnCount();
612:                for (int columnIndex = 0; columnIndex < columns; ++columnIndex) {
613:                    Component childComponent = table.getCellComponent(
614:                            columnIndex, rowIndex);
615:                    Element tdElement = document.createElement("td");
616:                    tdElement.setAttribute("id", elementId + "_cell_"
617:                            + childComponent.getRenderId());
618:
619:                    CssStyle tdCssStyle = new CssStyle();
620:
621:                    if (inlineStyleRequired) {
622:                        BorderRender.renderToStyle(tdCssStyle, border);
623:                        CellLayoutDataRender.renderToElementAndStyle(tdElement,
624:                                tdCssStyle, childComponent,
625:                                getLayoutData(childComponent),
626:                                defaultInsetsAttributeValue);
627:                    } else {
628:                        tdElement.setAttribute("class", className);
629:                        CellLayoutDataRender.renderToElementAndStyle(tdElement,
630:                                tdCssStyle, childComponent,
631:                                getLayoutData(childComponent), null);
632:                    }
633:
634:                    CellLayoutDataRender.renderBackgroundImageToStyle(
635:                            tdCssStyle, rc, this , table, childComponent);
636:                    if (tdCssStyle.hasAttributes()) {
637:                        tdElement.setAttribute("style", tdCssStyle
638:                                .renderInline());
639:                    }
640:
641:                    trElement.appendChild(tdElement);
642:
643:                    renderAddChild(rc, update, tdElement, childComponent);
644:                }
645:
646:                return trElement;
647:            }
648:
649:            /**
650:             * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderUpdate(nextapp.echo2.webcontainer.RenderContext, 
651:             *      nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String)
652:             */
653:            public boolean renderUpdate(RenderContext rc,
654:                    ServerComponentUpdate update, String targetId) {
655:                Table table = (Table) update.getParent();
656:                renderDisposeDirective(rc, table);
657:                DomUpdate.renderElementRemove(rc.getServerMessage(),
658:                        ContainerInstance.getElementId(table));
659:                renderAdd(rc, update, targetId, table);
660:                return true;
661:            }
662:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.