KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > webcontainer > syncpeer > TablePeer


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.webcontainer.syncpeer;
31
32 import org.w3c.dom.Document JavaDoc;
33 import org.w3c.dom.DocumentFragment JavaDoc;
34 import org.w3c.dom.Element JavaDoc;
35 import org.w3c.dom.Node JavaDoc;
36 import org.w3c.dom.NodeList JavaDoc;
37
38 import nextapp.echo2.app.Border;
39 import nextapp.echo2.app.Color;
40 import nextapp.echo2.app.Component;
41 import nextapp.echo2.app.Extent;
42 import nextapp.echo2.app.FillImage;
43 import nextapp.echo2.app.Font;
44 import nextapp.echo2.app.ImageReference;
45 import nextapp.echo2.app.Insets;
46 import nextapp.echo2.app.LayoutData;
47 import nextapp.echo2.app.Table;
48 import nextapp.echo2.app.layout.TableLayoutData;
49 import nextapp.echo2.app.list.ListSelectionModel;
50 import nextapp.echo2.app.table.TableColumnModel;
51 import nextapp.echo2.app.update.ServerComponentUpdate;
52 import nextapp.echo2.webcontainer.ActionProcessor;
53 import nextapp.echo2.webcontainer.ContainerInstance;
54 import nextapp.echo2.webcontainer.DomUpdateSupport;
55 import nextapp.echo2.webcontainer.PartialUpdateManager;
56 import nextapp.echo2.webcontainer.PropertyUpdateProcessor;
57 import nextapp.echo2.webcontainer.RenderContext;
58 import nextapp.echo2.webcontainer.ComponentSynchronizePeer;
59 import nextapp.echo2.webcontainer.SynchronizePeerFactory;
60 import nextapp.echo2.webcontainer.image.ImageRenderSupport;
61 import nextapp.echo2.webcontainer.propertyrender.BorderRender;
62 import nextapp.echo2.webcontainer.propertyrender.CellLayoutDataRender;
63 import nextapp.echo2.webcontainer.propertyrender.ColorRender;
64 import nextapp.echo2.webcontainer.propertyrender.ExtentRender;
65 import nextapp.echo2.webcontainer.propertyrender.FillImageRender;
66 import nextapp.echo2.webcontainer.propertyrender.FontRender;
67 import nextapp.echo2.webcontainer.propertyrender.InsetsRender;
68 import nextapp.echo2.webrender.ClientProperties;
69 import nextapp.echo2.webrender.ServerMessage;
70 import nextapp.echo2.webrender.Service;
71 import nextapp.echo2.webrender.WebRenderServlet;
72 import nextapp.echo2.webrender.output.CssStyle;
73 import nextapp.echo2.webrender.servermessage.DomUpdate;
74 import nextapp.echo2.webrender.service.JavaScriptService;
75 import nextapp.echo2.webrender.util.DomUtil;
76
77 /**
78  * Synchronization peer for <code>nextapp.echo2.app.Table</code> components.
79  * <p>
80  * This class should not be extended or used by classes outside of the
81  * Echo framework.
82  */

83 public class TablePeer
84 implements ActionProcessor, ComponentSynchronizePeer, ImageRenderSupport, PropertyUpdateProcessor {
85
86     //TODO: Add full support for partial rendering on row insertions/deletions.
87

88     /**
89      * A string of periods used for the IE 100% Table Width workaround.
90      */

91     private static final String JavaDoc SIZING_DOTS = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
92             + ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ";
93     
94     private static final String JavaDoc[] TABLE_INIT_KEYS = new String JavaDoc[]{"rollover-style", "selection-style"};
95     
96     private static final String JavaDoc PROPERTY_SELECTION = "selection";
97     
98     private static final String JavaDoc IMAGE_ID_ROLLOVER_BACKGROUND = "rolloverBackground";
99     private static final String JavaDoc IMAGE_ID_SELECTION_BACKGROUND = "selectionBackground";
100     
101     /**
102      * Service to provide supporting JavaScript library.
103      */

104     private static final Service TABLE_SERVICE = JavaScriptService.forResource("Echo.Table",
105             "/nextapp/echo2/webcontainer/resource/js/Table.js");
106
107     static {
108         WebRenderServlet.getServiceRegistry().add(TABLE_SERVICE);
109     }
110
111     protected PartialUpdateManager propertyRenderRegistry;
112     
113     /**
114      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#getContainerId(nextapp.echo2.app.Component)
115      */

116     public String JavaDoc getContainerId(Component child) {
117         return ContainerInstance.getElementId(child.getParent()) + "_cell_" + child.getRenderId();
118     }
119     
120     /**
121      * @see nextapp.echo2.webcontainer.image.ImageRenderSupport#getImage(nextapp.echo2.app.Component, java.lang.String)
122      */

123     public ImageReference getImage(Component component, String JavaDoc imageId) {
124         if (IMAGE_ID_ROLLOVER_BACKGROUND.equals(imageId)) {
125             FillImage backgroundImage
126                     = (FillImage) component.getRenderProperty(Table.PROPERTY_ROLLOVER_BACKGROUND_IMAGE);
127             if (backgroundImage == null) {
128                 return null;
129             } else {
130                 return backgroundImage.getImage();
131             }
132         } else if (IMAGE_ID_SELECTION_BACKGROUND.equals(imageId)) {
133             FillImage backgroundImage
134                     = (FillImage) component.getRenderProperty(Table.PROPERTY_SELECTION_BACKGROUND_IMAGE);
135             if (backgroundImage == null) {
136                 return null;
137             } else {
138                 return backgroundImage.getImage();
139             }
140         } else {
141             // Retrieve CellLayoutData background image if applicable.
142
return CellLayoutDataRender.getCellLayoutDataBackgroundImage(component, imageId);
143         }
144     }
145
146     /**
147      * Returns the <code>TableLayoutData</code> of the given child,
148      * or null if it does not provide layout data.
149      *
150      * @param child the child component
151      * @return the layout data
152      * @throws java.lang.RuntimeException if the the provided
153      * <code>LayoutData</code> is not a <code>TableLayoutData</code>
154      */

155     private TableLayoutData getLayoutData(Component child) {
156         LayoutData layoutData = (LayoutData) child.getRenderProperty(Component.PROPERTY_LAYOUT_DATA);
157         if (layoutData == null) {
158             return null;
159         } else if (layoutData instanceof TableLayoutData) {
160             return (TableLayoutData) layoutData;
161         } else {
162             throw new RuntimeException JavaDoc("Invalid LayoutData for Table Child: " + layoutData.getClass().getName());
163         }
164     }
165     
166     /**
167      * @see nextapp.echo2.webcontainer.ActionProcessor#processAction(nextapp.echo2.webcontainer.ContainerInstance,
168      * nextapp.echo2.app.Component, org.w3c.dom.Element)
169      */

170     public void processAction(ContainerInstance ci, Component component, Element JavaDoc actionElement) {
171         ci.getUpdateManager().getClientUpdateManager().setComponentAction(component, Table.INPUT_ACTION, null);
172     }
173     
174     /**
175      * @see nextapp.echo2.webcontainer.PropertyUpdateProcessor#processPropertyUpdate(
176      * nextapp.echo2.webcontainer.ContainerInstance, nextapp.echo2.app.Component, org.w3c.dom.Element)
177      */

178     public void processPropertyUpdate(ContainerInstance ci, Component component, Element JavaDoc propertyElement) {
179         String JavaDoc propertyName = propertyElement.getAttribute(PropertyUpdateProcessor.PROPERTY_NAME);
180         if (PROPERTY_SELECTION.equals(propertyName)) {
181             Element JavaDoc[] optionElements = DomUtil.getChildElementsByTagName(propertyElement, "row");
182             int[] selectedIndices = new int[optionElements.length];
183             for (int i = 0; i < optionElements.length; ++i) {
184                 selectedIndices[i] = Integer.parseInt(optionElements[i].getAttribute("index"));
185             }
186             ci.getUpdateManager().getClientUpdateManager().setComponentProperty(component,
187                     Table.SELECTION_CHANGED_PROPERTY, selectedIndices);
188         }
189     }
190     
191     /**
192      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderAdd(nextapp.echo2.webcontainer.RenderContext,
193      * nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String, nextapp.echo2.app.Component)
194      */

195     public void renderAdd(RenderContext rc, ServerComponentUpdate update, String JavaDoc targetId, Component component) {
196         Table table = (Table) component;
197         Border border = (Border) table.getRenderProperty(Table.PROPERTY_BORDER);
198         Insets tableInsets = (Insets) table.getRenderProperty(Table.PROPERTY_INSETS);
199         String JavaDoc defaultInsetsAttributeValue = tableInsets == null
200                 ? "0px" : InsetsRender.renderCssAttributeValue(tableInsets);
201         CssStyle styleCss = new CssStyle();
202         styleCss.setAttribute("padding", defaultInsetsAttributeValue);
203         BorderRender.renderToStyle(styleCss, border);
204         DomUpdate.renderStyleSheetAddRule(rc.getServerMessage(), "TD.c-" + component.getRenderId(), styleCss.renderInline());
205         
206         Element JavaDoc domAddTableElement = DomUpdate.renderElementAdd(rc.getServerMessage());
207         DocumentFragment JavaDoc htmlFragment = rc.getServerMessage().getDocument().createDocumentFragment();
208         renderHtml(rc, update, htmlFragment, component);
209         DomUpdate.renderElementAddContent(rc.getServerMessage(), domAddTableElement, targetId, htmlFragment);
210     }
211     
212     /**
213      * Renders a child component.
214      *
215      * @param rc the relevant <code>RenderContext</code>
216      * @param update the update
217      * @param parentElement the HTML element which should contain the child
218      * @param child the child component to render
219      */

220     private void renderAddChild(RenderContext rc, ServerComponentUpdate update, Element JavaDoc parentElement, Component child) {
221         if (!child.isVisible()) {
222             // Do nothing.
223
return;
224         }
225         ComponentSynchronizePeer syncPeer = SynchronizePeerFactory.getPeerForComponent(child.getClass());
226         if (syncPeer instanceof DomUpdateSupport) {
227             ((DomUpdateSupport) syncPeer).renderHtml(rc, update, parentElement, child);
228         } else {
229             syncPeer.renderAdd(rc, update, getContainerId(child), child);
230         }
231     }
232     
233     /**
234      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderDispose(nextapp.echo2.webcontainer.RenderContext,
235      * nextapp.echo2.app.update.ServerComponentUpdate, nextapp.echo2.app.Component)
236      */

237     public void renderDispose(RenderContext rc, ServerComponentUpdate update, Component component) {
238         rc.getServerMessage().addLibrary(TABLE_SERVICE.getId());
239         renderDisposeDirective(rc, (Table) component);
240     }
241     
242     /**
243      * Renders a directive to the outgoing <code>ServerMessage</code> to
244      * dispose the state of a table, performing tasks such as unregistering
245      * event listeners on the client.
246      *
247      * @param rc the relevant <code>RenderContext</code>
248      * @param table the table
249      */

250     private void renderDisposeDirective(RenderContext rc, Table table) {
251  // DomUpdate.renderElementRemove(rc.getServerMessage(), ContainerInstance.getElementId(table) + "_style");
252
DomUpdate.renderStyleSheetRemoveRule(rc.getServerMessage(), "TD.c-" + table.getRenderId());
253  
254         ServerMessage serverMessage = rc.getServerMessage();
255         Element JavaDoc itemizedUpdateElement = serverMessage.getItemizedDirective(ServerMessage.GROUP_ID_PREREMOVE,
256                 "EchoTable.MessageProcessor", "dispose", new String JavaDoc[0], new String JavaDoc[0]);
257         Element JavaDoc itemElement = serverMessage.getDocument().createElement("item");
258         itemElement.setAttribute("eid", ContainerInstance.getElementId(table));
259         itemizedUpdateElement.appendChild(itemElement);
260     }
261
262     /**
263      * @see nextapp.echo2.webcontainer.DomUpdateSupport#renderHtml(nextapp.echo2.webcontainer.RenderContext,
264      * nextapp.echo2.app.update.ServerComponentUpdate, org.w3c.dom.Node, nextapp.echo2.app.Component)
265      */

266     public void renderHtml(RenderContext rc, ServerComponentUpdate update, Node JavaDoc parentNode, Component component) {
267         ServerMessage serverMessage = rc.getServerMessage();
268         serverMessage.addLibrary(TABLE_SERVICE.getId());
269         Table table = (Table) component;
270         
271         renderInitDirective(rc, table);
272         
273         Border border = (Border) table.getRenderProperty(Table.PROPERTY_BORDER);
274         Extent borderSize = border == null ? null : border.getSize();
275
276         String JavaDoc elementId = ContainerInstance.getElementId(table);
277         
278         Document JavaDoc document = parentNode.getOwnerDocument();
279         Element JavaDoc tableElement = document.createElement("table");
280         tableElement.setAttribute("id", elementId);
281
282         CssStyle tableCssStyle = new CssStyle();
283         tableCssStyle.setAttribute("border-collapse", "collapse");
284         
285         if (((Boolean JavaDoc) table.getRenderProperty(Table.PROPERTY_SELECTION_ENABLED, Boolean.FALSE)).booleanValue()) {
286             tableCssStyle.setAttribute("cursor", "pointer");
287         }
288         
289         Insets tableInsets = (Insets) table.getRenderProperty(Table.PROPERTY_INSETS);
290         
291         String JavaDoc defaultInsetsAttributeValue = tableInsets == null ? "0px" : InsetsRender.renderCssAttributeValue(tableInsets);
292         
293         ColorRender.renderToStyle(tableCssStyle, component);
294         FontRender.renderToStyle(tableCssStyle, component);
295         BorderRender.renderToStyle(tableCssStyle, border);
296         if (borderSize != null) {
297             if (!rc.getContainerInstance().getClientProperties().getBoolean(
298                     ClientProperties.QUIRK_CSS_BORDER_COLLAPSE_INSIDE)) {
299                 tableCssStyle.setAttribute("margin", ExtentRender.renderCssAttributeValueHalf(borderSize));
300             }
301         }
302         
303         Extent width = (Extent) table.getRenderProperty(Table.PROPERTY_WIDTH);
304         boolean render100PercentWidthWorkaround = false;
305         if (rc.getContainerInstance().getClientProperties().getBoolean(
306                 ClientProperties.QUIRK_IE_TABLE_PERCENT_WIDTH_SCROLLBAR_ERROR)) {
307             if (width != null && width.getUnits() == Extent.PERCENT && width.getValue() == 100) {
308                 width = null;
309                 render100PercentWidthWorkaround = true;
310             }
311         }
312         ExtentRender.renderToStyle(tableCssStyle, "width", width);
313         
314         tableElement.setAttribute("style", tableCssStyle.renderInline());
315         
316         parentNode.appendChild(tableElement);
317         
318         TableColumnModel columnModel = table.getColumnModel();
319         int columnCount = columnModel.getColumnCount();
320         
321         boolean someColumnsHaveWidths = false;
322         for (int i = 0; i < columnCount; ++i) {
323             if (columnModel.getColumn(i).getWidth() != null) {
324                 someColumnsHaveWidths = true;
325             }
326         }
327         if (someColumnsHaveWidths) {
328             Element JavaDoc colGroupElement = document.createElement("colgroup");
329             tableElement.appendChild(colGroupElement);
330             
331             for (int i = 0; i < columnCount; ++i) {
332                 Element JavaDoc colElement = document.createElement("col");
333                 Extent columnWidth = columnModel.getColumn(i).getWidth();
334                 if (columnWidth != null) {
335                     colElement.setAttribute("width", ExtentRender.renderCssAttributeValue(columnWidth));
336                 }
337                 colGroupElement.appendChild(colElement);
338             }
339         }
340         
341         Element JavaDoc tbodyElement = document.createElement("tbody");
342         tbodyElement.setAttribute("id", elementId + "_tbody");
343         tableElement.appendChild(tbodyElement);
344         
345         Element JavaDoc firstTrElement = null;
346         
347         if (table.isHeaderVisible()) {
348             firstTrElement = renderRow(rc, update, tbodyElement, table, Table.HEADER_ROW, defaultInsetsAttributeValue);
349         }
350         
351         int rows = table.getModel().getRowCount();
352         for (int rowIndex = 0; rowIndex < rows; ++rowIndex) {
353             if (firstTrElement == null && rowIndex == 0) {
354                 firstTrElement = renderRow(rc, update, tbodyElement, table, rowIndex, defaultInsetsAttributeValue);
355             } else {
356                 renderRow(rc, update, tbodyElement, table, rowIndex, defaultInsetsAttributeValue);
357             }
358         }
359         
360         if (render100PercentWidthWorkaround && firstTrElement != null) {
361             // Render string of "sizing dots" in first row of cells.
362
NodeList JavaDoc childNodes = firstTrElement.getChildNodes();
363             int length = childNodes.getLength();
364             for (int i = 0; i < length; ++i) {
365                 if (!"td".equals(childNodes.item(i).getNodeName())) {
366                     continue;
367                 }
368                 Element JavaDoc tdElement = (Element JavaDoc) childNodes.item(i);
369                 Element JavaDoc sizingDivElement = document.createElement("div");
370                 sizingDivElement.setAttribute("style", "font-size:50px;height:0px;overflow:hidden;");
371                 sizingDivElement.appendChild(document.createTextNode(SIZING_DOTS));
372                 tdElement.appendChild(sizingDivElement);
373             }
374         }
375     }
376     
377     /**
378      * Renders a directive to the outgoing <code>ServerMessage</code> to
379      * initialize the state of a <code>Table</code>, performing tasks such as
380      * registering event listeners on the client.
381      *
382      * @param rc the relevant <code>RenderContext</code>
383      * @param table the table
384      */

385     private void renderInitDirective(RenderContext rc, Table table) {
386         String JavaDoc elementId = ContainerInstance.getElementId(table);
387         ServerMessage serverMessage = rc.getServerMessage();
388         Document JavaDoc document = serverMessage.getDocument();
389         
390         boolean rolloverEnabled = ((Boolean JavaDoc) table.getRenderProperty(Table.PROPERTY_ROLLOVER_ENABLED,
391                 Boolean.FALSE)).booleanValue();
392         boolean selectionEnabled = ((Boolean JavaDoc) table.getRenderProperty(Table.PROPERTY_SELECTION_ENABLED,
393                 Boolean.FALSE)).booleanValue();
394         
395         String JavaDoc rolloverStyle = "";
396         if (rolloverEnabled) {
397             CssStyle rolloverCssStyle = new CssStyle();
398             ColorRender.renderToStyle(rolloverCssStyle,
399                     (Color) table.getRenderProperty(Table.PROPERTY_ROLLOVER_FOREGROUND),
400                     (Color) table.getRenderProperty(Table.PROPERTY_ROLLOVER_BACKGROUND));
401             FontRender.renderToStyle(rolloverCssStyle,
402                     (Font) table.getRenderProperty(Table.PROPERTY_ROLLOVER_FONT));
403             FillImageRender.renderToStyle(rolloverCssStyle, rc, this, table, IMAGE_ID_ROLLOVER_BACKGROUND,
404                     (FillImage) table.getRenderProperty(Table.PROPERTY_ROLLOVER_BACKGROUND_IMAGE),
405                     FillImageRender.FLAG_DISABLE_FIXED_MODE);
406             if (rolloverCssStyle.hasAttributes()) {
407                 rolloverStyle = rolloverCssStyle.renderInline();
408             }
409         }
410         
411         String JavaDoc selectionStyle = "";
412         if (selectionEnabled) {
413             CssStyle selectionCssStyle = new CssStyle();
414             ColorRender.renderToStyle(selectionCssStyle,
415                     (Color) table.getRenderProperty(Table.PROPERTY_SELECTION_FOREGROUND),
416                     (Color) table.getRenderProperty(Table.PROPERTY_SELECTION_BACKGROUND));
417             FontRender.renderToStyle(selectionCssStyle,
418                     (Font) table.getRenderProperty(Table.PROPERTY_SELECTION_FONT));
419             FillImageRender.renderToStyle(selectionCssStyle, rc, this, table, IMAGE_ID_SELECTION_BACKGROUND,
420                     (FillImage) table.getRenderProperty(Table.PROPERTY_SELECTION_BACKGROUND_IMAGE),
421                     FillImageRender.FLAG_DISABLE_FIXED_MODE);
422             if (selectionCssStyle.hasAttributes()) {
423                 selectionStyle = selectionCssStyle.renderInline();
424             }
425         }
426         
427         Element JavaDoc itemizedUpdateElement = serverMessage.getItemizedDirective(ServerMessage.GROUP_ID_POSTUPDATE,
428                 "EchoTable.MessageProcessor", "init", TABLE_INIT_KEYS,
429                 new String JavaDoc[]{rolloverStyle, selectionStyle});
430         Element JavaDoc itemElement = document.createElement("item");
431         itemElement.setAttribute("eid", elementId);
432         if (table.isHeaderVisible()) {
433             itemElement.setAttribute("header-visible", "true");
434         }
435         
436         if (table.hasActionListeners()) {
437             itemElement.setAttribute("server-notify", "true");
438         }
439         
440         if (rolloverEnabled) {
441             itemElement.setAttribute("rollover-enabled", "true");
442         }
443         
444         if (selectionEnabled) {
445             itemElement.setAttribute("selection-enabled", "true");
446             ListSelectionModel selectionModel = table.getSelectionModel();
447             if (selectionModel.getSelectionMode() == ListSelectionModel.MULTIPLE_SELECTION) {
448                 itemElement.setAttribute("selection-mode", "multiple");
449             }
450             if (selectionModel.getMinSelectedIndex() != -1) {
451                 Element JavaDoc selectionElement = document.createElement("selection");
452                 int minimumIndex = selectionModel.getMinSelectedIndex();
453                 int maximumIndex = selectionModel.getMaxSelectedIndex();
454                 if (maximumIndex > table.getModel().getRowCount() - 1) {
455                     maximumIndex = table.getModel().getRowCount() - 1;
456                 }
457                 for (int i = minimumIndex; i <= maximumIndex; ++i) {
458                     if (selectionModel.isSelectedIndex(i)) {
459                         Element JavaDoc rowElement = document.createElement("row");
460                         rowElement.setAttribute("index", Integer.toString(i));
461                         selectionElement.appendChild(rowElement);
462                     }
463                 }
464                 itemElement.appendChild(selectionElement);
465             }
466         }
467         
468         if (!table.isRenderEnabled()) {
469             itemElement.setAttribute("enabled", "false");
470         }
471
472         itemizedUpdateElement.appendChild(itemElement);
473     }
474     
475     /**
476      * Renders a single row of a table.
477      *
478      * @param rc the relevant <code>RenderContext</code>
479      * @param update the <code>ServerComponentUpdate</code> being processed
480      * @param tbodyElement the <code>tbody</code> element to which to append
481      * the rendered content
482      * @param table the <code>Table</code> being rendered
483      * @param rowIndex the row to render
484      * @param defaultInsetsAttributeValue the default CSS padding attribute value
485      * @return the rendered TR element
486      */

487     private Element JavaDoc renderRow(RenderContext rc, ServerComponentUpdate update, Element JavaDoc tbodyElement, Table table, int rowIndex,
488             String JavaDoc defaultInsetsAttributeValue) {
489         Document JavaDoc document = tbodyElement.getOwnerDocument();
490         String JavaDoc elementId = ContainerInstance.getElementId(table);
491         
492         Element JavaDoc trElement = document.createElement("tr");
493         if (rowIndex == Table.HEADER_ROW) {
494             trElement.setAttribute("id", elementId + "_tr_header");
495         } else {
496             trElement.setAttribute("id", elementId + "_tr_" + rowIndex);
497         }
498         tbodyElement.appendChild(trElement);
499         
500         String JavaDoc className = "c-" + table.getRenderId();
501         
502         boolean inlineStyleRequired = rc.getContainerInstance().getClientProperties().getBoolean(
503                 ClientProperties.NOT_SUPPORTED_CSS_MANIPULATION);
504         Border border = null;
505         if (inlineStyleRequired) {
506             border = (Border) table.getRenderProperty(Table.PROPERTY_BORDER);
507         }
508         
509         int columns = table.getColumnModel().getColumnCount();
510         for (int columnIndex = 0; columnIndex < columns; ++columnIndex) {
511             Component childComponent = table.getCellComponent(columnIndex, rowIndex);
512             Element JavaDoc tdElement = document.createElement("td");
513             tdElement.setAttribute("id", elementId + "_cell_" + childComponent.getRenderId());
514             
515             CssStyle tdCssStyle = new CssStyle();
516             
517             if (inlineStyleRequired) {
518                 BorderRender.renderToStyle(tdCssStyle, border);
519                 CellLayoutDataRender.renderToElementAndStyle(tdElement, tdCssStyle, childComponent, getLayoutData(childComponent),
520                         defaultInsetsAttributeValue);
521             } else {
522                 tdElement.setAttribute("class", className);
523                 CellLayoutDataRender.renderToElementAndStyle(tdElement, tdCssStyle, childComponent, getLayoutData(childComponent),
524                         null);
525             }
526             
527             CellLayoutDataRender.renderBackgroundImageToStyle(tdCssStyle, rc, this, table, childComponent);
528             if (tdCssStyle.hasAttributes()) {
529                 tdElement.setAttribute("style", tdCssStyle.renderInline());
530             }
531             
532             trElement.appendChild(tdElement);
533             
534             renderAddChild(rc, update, tdElement, childComponent);
535         }
536         
537         return trElement;
538     }
539     
540     /**
541      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderUpdate(nextapp.echo2.webcontainer.RenderContext,
542      * nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String)
543      */

544     public boolean renderUpdate(RenderContext rc, ServerComponentUpdate update, String JavaDoc targetId) {
545         Table table = (Table) update.getParent();
546         renderDisposeDirective(rc, table);
547         DomUpdate.renderElementRemove(rc.getServerMessage(), ContainerInstance.getElementId(table));
548         renderAdd(rc, update, targetId, table);
549         return true;
550     }
551 }
552
Popular Tags