Source Code Cross Referenced for TableCG.java in  » Swing-Library » wings3 » org » wings » plaf » css » 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 » Swing Library » wings3 » org.wings.plaf.css 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000,2005 wingS development team.
003:         *
004:         * This file is part of wingS (http://wingsframework.org).
005:         *
006:         * wingS is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1
009:         * of the License, or (at your option) any later version.
010:         *
011:         * Please see COPYING for the complete licence.
012:         */
013:        package org.wings.plaf.css;
014:
015:        import org.wings.*;
016:        import org.wings.io.Device;
017:        import org.wings.io.StringBuilderDevice;
018:        import org.wings.plaf.CGManager;
019:        import org.wings.plaf.Update;
020:        import org.wings.session.SessionManager;
021:        import org.wings.table.*;
022:        import org.wings.util.SStringBuilder;
023:
024:        import java.awt.*;
025:        import java.io.IOException;
026:        import java.util.ArrayList;
027:        import java.util.List;
028:
029:        // Please do NOT reformat this class!
030:        public final class TableCG extends AbstractComponentCG implements 
031:                org.wings.plaf.TableCG {
032:            private static final long serialVersionUID = 1L;
033:            protected String fixedTableBorderWidth;
034:            protected SIcon editIcon;
035:            protected String selectionColumnWidth = "30";
036:
037:            int horizontalOversize = 4;
038:
039:            /**
040:             * Initialize properties from config
041:             */
042:            public TableCG() {
043:                final CGManager manager = SessionManager.getSession()
044:                        .getCGManager();
045:                setFixedTableBorderWidth((String) manager.getObject(
046:                        "TableCG.fixedTableBorderWidth", String.class));
047:                setEditIcon(manager.getIcon("TableCG.editIcon"));
048:                selectionColumnWidth = (String) manager.getObject(
049:                        "TableCG.selectionColumnWidth", String.class);
050:            }
051:
052:            public int getHorizontalOversize() {
053:                return horizontalOversize;
054:            }
055:
056:            public void setHorizontalOversize(int horizontalOversize) {
057:                this .horizontalOversize = horizontalOversize;
058:            }
059:
060:            /**
061:             * Tweak property. Declares a deprecated BORDER=xxx attribute on the HTML TABLE element.
062:             */
063:            public String getFixedTableBorderWidth() {
064:                return fixedTableBorderWidth;
065:            }
066:
067:            /**
068:             * Tweak property. Declares a deprecated BORDER=xxx attribute on the HTML TABLE element.
069:             */
070:            public void setFixedTableBorderWidth(String fixedTableBorderWidth) {
071:                this .fixedTableBorderWidth = fixedTableBorderWidth;
072:            }
073:
074:            /**
075:             * Sets the icon used to indicated an editable cell (if content is not direct clickable).
076:             */
077:            public void setEditIcon(SIcon editIcon) {
078:                this .editIcon = editIcon;
079:            }
080:
081:            /**
082:             * @return Returns the icon used to indicated an editable cell (if content is not direct clickable).
083:             */
084:            public SIcon getEditIcon() {
085:                return editIcon;
086:            }
087:
088:            /**
089:             * @return The width of the (optional) row selection column in px
090:             */
091:            public String getSelectionColumnWidth() {
092:                return selectionColumnWidth;
093:            }
094:
095:            /**
096:             * The width of the (optional) row selection column in px
097:             *
098:             * @param selectionColumnWidth The width of the (optional) row selection column with unit
099:             */
100:            public void setSelectionColumnWidth(String selectionColumnWidth) {
101:                this .selectionColumnWidth = selectionColumnWidth;
102:            }
103:
104:            public void installCG(final SComponent comp) {
105:                super .installCG(comp);
106:
107:                final STable table = (STable) comp;
108:                final CGManager manager = table.getSession().getCGManager();
109:                Object value;
110:
111:                value = manager.getObject("STable.defaultRenderer",
112:                        STableCellRenderer.class);
113:                if (value != null) {
114:                    table.setDefaultRenderer((STableCellRenderer) value);
115:                    if (value instanceof  SDefaultTableCellRenderer) {
116:                        SDefaultTableCellRenderer cellRenderer = (SDefaultTableCellRenderer) value;
117:                        cellRenderer.setEditIcon(editIcon);
118:                    }
119:                }
120:
121:                value = manager.getObject("STable.headerRenderer",
122:                        STableCellRenderer.class);
123:                if (value != null) {
124:                    table.setHeaderRenderer((STableCellRenderer) value);
125:                }
126:
127:                value = manager.getObject("STable.rowSelectionRenderer",
128:                        org.wings.table.STableCellRenderer.class);
129:                if (value != null) {
130:                    table
131:                            .setRowSelectionRenderer((org.wings.table.STableCellRenderer) value);
132:                }
133:
134:                if (isMSIE(table))
135:                    table.putClientProperty("horizontalOversize", new Integer(
136:                            horizontalOversize));
137:            }
138:
139:            public void uninstallCG(SComponent component) {
140:                super .uninstallCG(component);
141:                final STable table = (STable) component;
142:                table.setHeaderRenderer(null);
143:                table.setDefaultRenderer(null);
144:                table.setRowSelectionRenderer(null);
145:            }
146:
147:            /**
148:             * write a specific cell to the device
149:             */
150:            protected void renderCellContent(final Device device,
151:                    final STable table, final SCellRendererPane rendererPane,
152:                    final int row, final int col) throws IOException {
153:                final boolean isEditingCell = table.isEditing()
154:                        && row == table.getEditingRow()
155:                        && col == table.getEditingColumn();
156:                final boolean editableCell = table.isCellEditable(row, col);
157:                final boolean selectableCell = table.getSelectionMode() != SListSelectionModel.NO_SELECTION
158:                        && !table.isEditable() && table.isSelectable();
159:
160:                final SComponent component;
161:                if (isEditingCell) {
162:                    component = table.getEditorComponent();
163:                } else {
164:                    component = table.prepareRenderer(table.getCellRenderer(
165:                            row, col), row, col);
166:                }
167:
168:                final boolean isClickable = component instanceof  SClickable;
169:
170:                device.print("<td col=\"");
171:                device.print(col);
172:                device.print("\"");
173:
174:                if (component == null) {
175:                    device.print("></td>");
176:                    return;
177:                }
178:                Utils.printTableCellAlignment(device, component,
179:                        SConstants.LEFT, SConstants.TOP);
180:                Utils.optAttribute(device, "oversize", horizontalOversize);
181:
182:                String parameter = null;
183:                if (table.isEditable() && editableCell)
184:                    parameter = table.getEditParameter(row, col);
185:                else if (selectableCell)
186:                    parameter = table.getToggleSelectionParameter(row, col);
187:
188:                if (parameter != null && (selectableCell || editableCell)
189:                        && !isClickable) {
190:                    printClickability(device, table, parameter, table
191:                            .getShowAsFormComponent());
192:                    device.print(isEditingCell ? " editing=\"true\""
193:                            : " editing=\"false\"");
194:                    device.print(isEditingCell ? " class=\"cell\""
195:                            : " class=\"cell clickable\"");
196:                } else
197:                    device.print(" class=\"cell\"");
198:                device.print(">");
199:
200:                rendererPane.writeComponent(device, component, table);
201:
202:                device.print("</td>");
203:                Utils.printNewline(device, component);
204:            }
205:
206:            protected void writeHeaderCell(final Device device,
207:                    final STable table, final SCellRendererPane rendererPane,
208:                    final int col) throws IOException {
209:                final SComponent comp = table.prepareHeaderRenderer(table
210:                        .getHeaderRenderer(col), col);
211:
212:                device.print("<th col=\"");
213:                device.print(col);
214:                device.print("\" class=\"head\"");
215:
216:                Utils.printTableCellAlignment(device, comp, SConstants.CENTER,
217:                        SConstants.CENTER);
218:                device.print(">");
219:
220:                rendererPane.writeComponent(device, comp, table);
221:
222:                device.print("</th>");
223:                Utils.printNewline(device, comp);
224:            }
225:
226:            public final void writeInternal(final Device device,
227:                    final SComponent _c) throws IOException {
228:                final STable table = (STable) _c;
229:
230:                device.print("<table");
231:                Utils.writeAllAttributes(device, table);
232:                writeTableAttributes(device, table);
233:                device.print("><thead>");
234:                Utils.printNewline(device, table);
235:
236:                Rectangle currentViewport = table.getViewportSize();
237:                Rectangle maximalViewport = table.getScrollableViewportSize();
238:                int startX = 0;
239:                int endX = table.getVisibleColumnCount();
240:                int startY = 0;
241:                int endY = table.getRowCount();
242:                int emptyIndex = maximalViewport != null ? maximalViewport.height
243:                        : endY;
244:
245:                if (currentViewport != null) {
246:                    startX = currentViewport.x;
247:                    endX = startX + currentViewport.width;
248:                    startY = currentViewport.y;
249:                    endY = startY + currentViewport.height;
250:                }
251:
252:                writeColumnWidths(device, table, startX, endX);
253:                writeHeader(device, table, startX, endX);
254:
255:                device.print("</thead>");
256:                Utils.printNewline(device, table);
257:                device.print("<tbody>");
258:
259:                writeBody(device, table, startX, endX, startY, endY, emptyIndex);
260:
261:                device.print("</tbody></table>");
262:            }
263:
264:            private void writeTableAttributes(Device device, STable table)
265:                    throws IOException {
266:                final SDimension intercellPadding = table.getIntercellPadding();
267:                final SDimension intercellSpacing = table.getIntercellSpacing();
268:                Utils.writeEvents(device, table, null);
269:
270:                // TODO: border="" should be obsolete
271:                // TODO: cellspacing and cellpadding may be in conflict with border-collapse
272:                /* Tweaking: CG configured to have a fixed border="xy" width */
273:                Utils.optAttribute(device, "border", fixedTableBorderWidth);
274:                Utils.optAttribute(device, "cellspacing",
275:                        ((intercellSpacing != null) ? ""
276:                                + intercellSpacing.getWidthInt() : null));
277:                Utils.optAttribute(device, "cellpadding",
278:                        ((intercellPadding != null) ? ""
279:                                + intercellPadding.getHeightInt() : null));
280:            }
281:
282:            private void writeColumnWidths(Device device, STable table,
283:                    int startX, int endX) throws IOException {
284:                STableColumnModel columnModel = table.getColumnModel();
285:                if (columnModel != null
286:                        && atLeastOneColumnWidthIsNotNull(columnModel)) {
287:                    device.print("<colgroup>");
288:                    if (isSelectionColumnVisible(table))
289:                        writeCol(device, selectionColumnWidth);
290:
291:                    for (int i = startX; i < endX; ++i) {
292:                        STableColumn column = columnModel.getColumn(i);
293:                        if (!column.isHidden())
294:                            writeCol(device, column.getWidth());
295:                        else
296:                            ++endX;
297:                    }
298:                    device.print("</colgroup>");
299:                    Utils.printNewline(device, table);
300:                }
301:            }
302:
303:            private void writeHeader(Device device, STable table, int startX,
304:                    int endX) throws IOException {
305:                if (!table.isHeaderVisible())
306:                    return;
307:
308:                final SCellRendererPane rendererPane = table
309:                        .getCellRendererPane();
310:                STableColumnModel columnModel = table.getColumnModel();
311:
312:                SStringBuilder headerArea = Utils.inlineStyles(table
313:                        .getDynamicStyle(STable.SELECTOR_HEADER));
314:                device.print("<tr class=\"header\"");
315:                Utils.optAttribute(device, "style", headerArea);
316:                device.print(">");
317:
318:                Utils.printNewline(device, table, 1);
319:                writeSelectionHeader(device, table);
320:
321:                for (int i = startX; i < endX; ++i) {
322:                    STableColumn column = columnModel.getColumn(i);
323:                    if (!column.isHidden())
324:                        writeHeaderCell(device, table, rendererPane, i);
325:                    else
326:                        ++endX;
327:                }
328:                device.print("</tr>");
329:                Utils.printNewline(device, table);
330:            }
331:
332:            protected void writeBody(Device device, STable table, int startX,
333:                    int endX, int startY, int endY, int emptyIndex)
334:                    throws IOException {
335:                final SListSelectionModel selectionModel = table
336:                        .getSelectionModel();
337:
338:                SStringBuilder selectedArea = Utils.inlineStyles(table
339:                        .getDynamicStyle(STable.SELECTOR_SELECTED));
340:                SStringBuilder evenArea = Utils.inlineStyles(table
341:                        .getDynamicStyle(STable.SELECTOR_EVEN_ROWS));
342:                SStringBuilder oddArea = Utils.inlineStyles(table
343:                        .getDynamicStyle(STable.SELECTOR_ODD_ROWS));
344:                final SCellRendererPane rendererPane = table
345:                        .getCellRendererPane();
346:                STableColumnModel columnModel = table.getColumnModel();
347:
348:                for (int r = startY; r < endY; ++r) {
349:                    writeTableRow(device, table, columnModel, selectionModel,
350:                            rendererPane, r, startX, endX, emptyIndex,
351:                            selectedArea, oddArea, evenArea);
352:                }
353:            }
354:
355:            protected void writeTableRow(Device device, STable table,
356:                    STableColumnModel columnModel,
357:                    SListSelectionModel selectionModel,
358:                    SCellRendererPane rendererPane, final int rowIndex,
359:                    int startX, int endX, int emptyIndex,
360:                    SStringBuilder selectedArea, SStringBuilder oddArea,
361:                    SStringBuilder evenArea) throws IOException {
362:                if (rowIndex >= emptyIndex) {
363:                    int colspan = endX - startX;
364:                    device.print("<tr>\n");
365:                    if (isSelectionColumnVisible(table)) {
366:                        device.print("  <td></td>\n");
367:                    }
368:                    device.print("  <td class=\"empty\" colspan=\"" + colspan
369:                            + "\">&nbsp;</td>\n");
370:                    device.print("</tr>\n");
371:                    return;
372:                }
373:
374:                String rowStyle = table.getRowStyle(rowIndex);
375:                SStringBuilder rowClass = new SStringBuilder(
376:                        rowStyle != null ? rowStyle + " " : "");
377:                device.print("<tr");
378:                if (selectionModel.isSelectedIndex(rowIndex)) {
379:                    Utils.optAttribute(device, "style", selectedArea);
380:                    rowClass.append("selected ");
381:                } else if (rowIndex % 2 != 0)
382:                    Utils.optAttribute(device, "style", oddArea);
383:                else
384:                    Utils.optAttribute(device, "style", evenArea);
385:
386:                rowClass.append(rowIndex % 2 != 0 ? "odd" : "even");
387:                Utils.optAttribute(device, "class", rowClass);
388:                device.print(">");
389:
390:                writeSelectionBody(device, table, rendererPane, rowIndex);
391:
392:                for (int c = startX; c < endX; ++c) {
393:                    STableColumn column = columnModel.getColumn(c);
394:                    if (!column.isHidden())
395:                        renderCellContent(device, table, rendererPane,
396:                                rowIndex, c);
397:                    else
398:                        ++endX;
399:                }
400:
401:                device.print("</tr>");
402:                Utils.printNewline(device, table);
403:            }
404:
405:            protected void writeSelectionHeader(Device device, STable table)
406:                    throws IOException {
407:                if (isSelectionColumnVisible(table)) {
408:                    device.print("<th valign=\"middle\" class=\"num\"");
409:                    Utils.optAttribute(device, "width", selectionColumnWidth);
410:                    device.print("></th>");
411:                }
412:            }
413:
414:            private boolean atLeastOneColumnWidthIsNotNull(
415:                    STableColumnModel columnModel) {
416:                int columnCount = columnModel.getColumnCount();
417:                for (int i = 0; i < columnCount; i++)
418:                    if (columnModel.getColumn(i).getWidth() != null)
419:                        return true;
420:                return false;
421:            }
422:
423:            private void writeCol(Device device, String width)
424:                    throws IOException {
425:                device.print("<col");
426:                Utils.optAttribute(device, "width", width);
427:                device.print("/>");
428:            }
429:
430:            /**
431:             * Renders the row sometimes needed to allow row selection.
432:             */
433:            protected void writeSelectionBody(final Device device,
434:                    final STable table, final SCellRendererPane rendererPane,
435:                    final int row) throws IOException {
436:                final STableCellRenderer rowSelectionRenderer = table
437:                        .getRowSelectionRenderer();
438:                if (isSelectionColumnVisible(table)) {
439:                    final SComponent comp = rowSelectionRenderer
440:                            .getTableCellRendererComponent(table, table
441:                                    .getToggleSelectionParameter(row, -1),
442:                                    table.isRowSelected(row), row, -1);
443:                    final String columnStyle = Utils.joinStyles(comp, "num");
444:
445:                    device.print("<td valign=\"top\" align=\"right\"");
446:                    Utils.optAttribute(device, "width", selectionColumnWidth);
447:
448:                    String value = table.getToggleSelectionParameter(row, -1);
449:                    if (table.getSelectionMode() != SListSelectionModel.NO_SELECTION) {
450:                        printClickability(device, table, value, table
451:                                .getShowAsFormComponent());
452:                        device.print(" class=\"clickable ");
453:                        device.print(columnStyle);
454:                        device.print("\"");
455:                    } else {
456:                        device.print(" class=\"");
457:                        device.print(columnStyle);
458:                        device.print("\"");
459:                    }
460:                    device.print(">");
461:
462:                    // Renders the content of the row selection row
463:                    rendererPane.writeComponent(device, comp, table);
464:
465:                    device.print("</td>");
466:                }
467:            }
468:
469:            public static void printClickability(final Device device,
470:                    final SComponent component, final String eventValue,
471:                    final boolean formComponent) throws IOException {
472:                device.print(" onclick=\"return wingS.table.cellClick(");
473:                device.print("event,this,");
474:                device.print(formComponent + ",");
475:                device.print(!component.isReloadForced() + ",'");
476:                device.print(Utils.event(component));
477:                device.print("','");
478:                device.print(eventValue == null ? "" : eventValue);
479:                device.print("'");
480:                device.print(");\"");
481:            }
482:
483:            private boolean isSelectionColumnVisible(STable table) {
484:                if (table.getRowSelectionRenderer() != null
485:                        && table.getSelectionModel().getSelectionMode() != SListSelectionModel.NO_SELECTION)
486:                    return true;
487:                return false;
488:            }
489:
490:            public Update getTableScrollUpdate(STable table,
491:                    Rectangle newViewport, Rectangle oldViewport) {
492:                //return new TableScrollUpdate(table);
493:                return new ComponentUpdate(this , table);
494:            }
495:
496:            public Update getSelectionUpdate(STable table,
497:                    List deselectedIndices, List selectedIndices) {
498:                return new SelectionUpdate(table, deselectedIndices,
499:                        selectedIndices);
500:            }
501:
502:            public Update getEditCellUpdate(STable table, int row, int column) {
503:                return new EditCellUpdate(table, row, column);
504:            }
505:
506:            public Update getRenderCellUpdate(STable table, int row, int column) {
507:                return new RenderCellUpdate(table, row, column);
508:            }
509:
510:            protected class TableScrollUpdate extends AbstractUpdate {
511:
512:                public TableScrollUpdate(SComponent component) {
513:                    super (component);
514:                }
515:
516:                public Handler getHandler() {
517:                    STable table = (STable) component;
518:
519:                    Rectangle currentViewport = table.getViewportSize();
520:                    Rectangle maximalViewport = table
521:                            .getScrollableViewportSize();
522:                    int startX = 0;
523:                    int endX = table.getVisibleColumnCount();
524:                    int startY = 0;
525:                    int endY = table.getRowCount();
526:                    int emptyIndex = maximalViewport != null ? maximalViewport.height
527:                            : endY;
528:
529:                    if (currentViewport != null) {
530:                        startX = currentViewport.x;
531:                        endX = startX + currentViewport.width;
532:                        startY = currentViewport.y;
533:                        endY = startY + currentViewport.height;
534:                    }
535:
536:                    String htmlCode = "";
537:                    String exception = null;
538:
539:                    try {
540:                        StringBuilderDevice htmlDevice = new StringBuilderDevice();
541:                        writeBody(htmlDevice, table, startX, endX, startY,
542:                                endY, emptyIndex);
543:                        htmlCode = htmlDevice.toString();
544:                    } catch (Throwable t) {
545:                        exception = t.getClass().getName();
546:                    }
547:
548:                    UpdateHandler handler = new UpdateHandler("tableScroll");
549:                    handler.addParameter(table.getName());
550:                    handler.addParameter(htmlCode);
551:                    if (exception != null) {
552:                        handler.addParameter(exception);
553:                    }
554:                    return handler;
555:                }
556:            }
557:
558:            protected class SelectionUpdate extends AbstractUpdate<STable> {
559:                private List<Integer> deselectedIndices;
560:                private List<Integer> selectedIndices;
561:
562:                public SelectionUpdate(STable component,
563:                        List<Integer> deselectedIndices,
564:                        List<Integer> selectedIndices) {
565:                    super (component);
566:                    this .deselectedIndices = deselectedIndices;
567:                    this .selectedIndices = selectedIndices;
568:                }
569:
570:                public Handler getHandler() {
571:                    int indexOffset = 0;
572:                    if (component.isHeaderVisible()) {
573:                        ++indexOffset;
574:                    }
575:
576:                    UpdateHandler handler = new UpdateHandler("selectionTable");
577:                    handler.addParameter(component.getName());
578:                    handler.addParameter(new Integer(indexOffset));
579:                    handler
580:                            .addParameter(Utils
581:                                    .listToJsArray(deselectedIndices));
582:                    handler.addParameter(Utils.listToJsArray(selectedIndices));
583:                    if (isSelectionColumnVisible(component)) {
584:                        String exception = null;
585:                        List<String> deselectedBodies = new ArrayList<String>();
586:                        List<String> selectedBodies = new ArrayList<String>();
587:                        exception = writeSelectionBodies(deselectedIndices,
588:                                deselectedBodies);
589:                        exception = writeSelectionBodies(selectedIndices,
590:                                selectedBodies);
591:                        handler.addParameter(Utils
592:                                .listToJsArray(deselectedBodies));
593:                        handler.addParameter(Utils
594:                                .listToJsArray(selectedBodies));
595:                        if (exception != null) {
596:                            handler.addParameter(exception);
597:                        }
598:                    }
599:                    return handler;
600:                }
601:
602:                private String writeSelectionBodies(List<Integer> indices,
603:                        List<String> bodies) {
604:                    try {
605:                        final StringBuilderDevice htmlDevice = new StringBuilderDevice(
606:                                512);
607:                        final SCellRendererPane rendererPane = component
608:                                .getCellRendererPane();
609:                        for (Integer index : indices) {
610:                            writeSelectionBody(htmlDevice, component,
611:                                    rendererPane, index);
612:                            bodies.add(htmlDevice.toString());
613:                            htmlDevice.reset();
614:                        }
615:                    } catch (Throwable t) {
616:                        return t.getClass().getName();
617:                    }
618:                    return null;
619:                }
620:            }
621:
622:            private class EditCellUpdate extends AbstractUpdate<STable> {
623:                private int row;
624:                private int column;
625:
626:                public EditCellUpdate(STable table, int row, int column) {
627:                    super (table);
628:                    this .row = row;
629:                    this .column = column;
630:                }
631:
632:                public Handler getHandler() {
633:                    STable table = this .component;
634:
635:                    String htmlCode = "";
636:                    String exception = null;
637:
638:                    try {
639:                        StringBuilderDevice device = new StringBuilderDevice();
640:                        /*
641:                        Utils.printTableCellAlignment(device, component, SConstants.LEFT, SConstants.TOP);
642:                        Utils.optAttribute(device, "oversize", horizontalOversize);
643:                        device.print(" class=\"cell\">");
644:                         */
645:                        SComponent component = table.getEditorComponent();
646:                        table.getCellRendererPane().writeComponent(device,
647:                                component, table);
648:                        htmlCode = device.toString();
649:                    } catch (Throwable t) {
650:                        exception = t.getClass().getName();
651:                    }
652:
653:                    row = table.isHeaderVisible() ? this .row + 1 : this .row;
654:                    column = columnInView(table, column);
655:                    column = isSelectionColumnVisible(table) ? column + 1
656:                            : column;
657:
658:                    Rectangle currentViewport = table.getViewportSize();
659:                    if (currentViewport != null) {
660:                        row -= currentViewport.y;
661:                        column -= currentViewport.x;
662:                    }
663:
664:                    UpdateHandler handler = new UpdateHandler("tableCell");
665:                    handler.addParameter(table.getName());
666:                    handler.addParameter(row);
667:                    handler.addParameter(column);
668:                    handler.addParameter(true);
669:                    handler.addParameter(htmlCode);
670:                    if (exception != null) {
671:                        handler.addParameter(exception);
672:                    }
673:                    return handler;
674:                }
675:            }
676:
677:            private class RenderCellUpdate extends AbstractUpdate<STable> {
678:                private int row;
679:                private int column;
680:
681:                public RenderCellUpdate(STable table, int row, int column) {
682:                    super (table);
683:                    this .row = row;
684:                    this .column = column;
685:                }
686:
687:                public Handler getHandler() {
688:                    STable table = this .component;
689:
690:                    String htmlCode = "";
691:                    String exception = null;
692:
693:                    try {
694:                        StringBuilderDevice device = new StringBuilderDevice(
695:                                256);
696:                        /*
697:                        Utils.printTableCellAlignment(device, component, SConstants.LEFT, SConstants.TOP);
698:                        Utils.optAttribute(device, "oversize", horizontalOversize);
699:                        device.print(" class=\"cell\">");
700:                         */
701:                        SComponent component = table.prepareRenderer(table
702:                                .getCellRenderer(row, column), row, column);
703:                        table.getCellRendererPane().writeComponent(device,
704:                                component, table);
705:                        htmlCode = device.toString();
706:                    } catch (Throwable t) {
707:                        exception = t.getClass().getName();
708:                    }
709:
710:                    row = table.isHeaderVisible() ? this .row + 1 : this .row;
711:                    column = columnInView(table, column);
712:                    column = isSelectionColumnVisible(table) ? column + 1
713:                            : column;
714:
715:                    Rectangle currentViewport = table.getViewportSize();
716:                    if (currentViewport != null) {
717:                        row -= currentViewport.y;
718:                        column -= currentViewport.x;
719:                    }
720:
721:                    UpdateHandler handler = new UpdateHandler("tableCell");
722:                    handler.addParameter(table.getName());
723:                    handler.addParameter(row);
724:                    handler.addParameter(column);
725:                    handler.addParameter(false);
726:                    handler.addParameter(htmlCode);
727:                    if (exception != null) {
728:                        handler.addParameter(exception);
729:                    }
730:                    return handler;
731:                }
732:
733:                public boolean equals(Object object) {
734:                    if (!super .equals(object))
735:                        return false;
736:
737:                    RenderCellUpdate other = (RenderCellUpdate) object;
738:
739:                    if (this .row != other.row)
740:                        return false;
741:                    if (this .column != other.column)
742:                        return false;
743:
744:                    return true;
745:                }
746:
747:                public int hashCode() {
748:                    int hashCode = super .hashCode();
749:                    int dispersionFactor = 37;
750:
751:                    hashCode = hashCode * dispersionFactor + row;
752:                    hashCode = hashCode * dispersionFactor + column;
753:
754:                    return hashCode;
755:                }
756:            }
757:
758:            private int columnInView(STable table, int column) {
759:                int viewColumn = 0;
760:                for (int i = 0; i < column; i++) {
761:                    STableColumn tableColumn = table.getColumnModel()
762:                            .getColumn(i);
763:                    if (!tableColumn.isHidden())
764:                        viewColumn++;
765:                }
766:                return viewColumn;
767:            }
768:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.