001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.render.web;
029:
030: import java.util.Set;
031: import java.util.Map;
032: import java.util.List;
033: import java.util.HashSet;
034: import java.util.HashMap;
035:
036: import thinwire.ui.AlignTextComponent.AlignX;
037: import thinwire.ui.Application;
038: import thinwire.ui.GridBox;
039: import thinwire.ui.Component;
040: import thinwire.ui.DropDownGridBox.DefaultView;
041: import thinwire.ui.GridBox.Range;
042: import thinwire.ui.GridBox.Column;
043: import thinwire.ui.GridBox.Row;
044: import thinwire.ui.event.ItemChangeEvent;
045: import thinwire.ui.event.ItemChangeListener;
046: import thinwire.ui.event.PropertyChangeEvent;
047: import thinwire.ui.style.FX;
048:
049: /**
050: * @author Joshua J. Gertzen
051: */
052: final class GridBoxRenderer extends ComponentRenderer implements
053: ItemChangeListener {
054: private static final String GRIDBOX_CLASS = "tw_GridBox";
055: private static final String SET_VISIBLE_HEADER = "setVisibleHeader";
056: private static final String SET_VISIBLE_CHECK_BOXES = "setVisibleCheckBoxes";
057: private static final String SET_FULL_ROW_CHECK_BOX = "setFullRowCheckBox";
058: private static final String SET_ROW_INDEX_SELECTED = "setRowIndexSelected";
059: private static final String SET_ROW_INDEX_CHECK_STATE = "setRowIndexCheckState";
060: private static final String SET_COLUMN_NAME = "setColumnName";
061: private static final String SET_COLUMN_WIDTH = "setColumnWidth";
062: private static final String SET_COLUMN_ALIGN_X = "setColumnAlignX";
063: private static final String SET_COLUMN_SORT_ORDER = "setColumnSortOrder";
064: private static final String ADD_ROW = "addRow";
065: private static final String REMOVE_ROW = "removeRow";
066: private static final String SET_ROW = "setRow";
067: private static final String CLEAR_ROWS = "clearRows";
068: private static final String SET_CELL = "setCell";
069: private static final String ADD_COLUMN = "addColumn";
070: private static final String SET_COLUMN = "setColumn";
071: private static final String REMOVE_COLUMN = "removeColumn";
072: private static final String VIEW_STATE_COLUMN_SORT = "columnSort";
073: private static final String SET_SORT_ALLOWED = "setSortAllowed";
074:
075: private Set<Integer> rowState = new HashSet<Integer>();
076: private Set<Integer> columnState = new HashSet<Integer>();
077: private GridBox gb;
078: private Map<GridBox, GridBoxRenderer> childToRenderer;
079: private int autoColumnWidth;
080:
081: @Override
082: void init(String jsClass, WindowRenderer wr, Component comp,
083: ComponentRenderer container) {
084: super .init(jsClass, wr, comp, container);
085: rowState.clear();
086: columnState.clear();
087: }
088:
089: //TODO: Column indexes on the client side may differ if there is a hidden column between two visible columns
090: void render(WindowRenderer wr, Component c,
091: ComponentRenderer container) {
092: render(wr, c, container, null);
093: }
094:
095: private void render(WindowRenderer wr, Component c,
096: ComponentRenderer container, Integer parentIndex) {
097: init(GRIDBOX_CLASS, wr, c, container);
098: gb = (GridBox) c;
099:
100: this .wr = wr;
101: gb.addItemChangeListener(this );
102:
103: if (container instanceof GridBoxRenderer) {
104: //a gridbox for a dropdown does not support the focus, enabled, x or y properties
105: setPropertyChangeIgnored(Component.PROPERTY_FOCUS, true);
106: setPropertyChangeIgnored(Component.PROPERTY_ENABLED, true);
107: setPropertyChangeIgnored(Component.PROPERTY_VISIBLE, true);
108: setPropertyChangeIgnored(Component.PROPERTY_X, true);
109: setPropertyChangeIgnored(Component.PROPERTY_Y, true);
110: WebApplication app = (WebApplication) Application.current();
111: DefaultView v = (DefaultView) app.setPackagePrivateMember(
112: "initDDGBView", null, gb);
113: if (gb.getWidth() == 0)
114: gb.setWidth(v.getOptimalWidth());
115: if (gb.getHeight() == 0)
116: gb.setHeight(v.getOptimalHeight());
117: }
118:
119: StringBuilder checkedRows = new StringBuilder();
120: getCheckedRowIndices(checkedRows);
121: calcAutoColumnWidth();
122: StringBuilder colDefs = new StringBuilder();
123:
124: List<Column> columns = gb.getColumns();
125: colDefs.append('[');
126:
127: for (int i = 0, cnt = columns.size(); i < cnt; i++) {
128: Column col = (Column) columns.get(i);
129: columnState.add(System.identityHashCode(col));
130:
131: if (col.isVisible()) {
132: colDefs.append("{v:");
133: getValues(col, col.getDisplayFormat(), colDefs);
134: colDefs.append(",n:");
135: getValue(this , col.getHeader().getText(), null, colDefs);
136: int width = col.getWidth();
137: if (width == -1)
138: width = autoColumnWidth;
139: colDefs.append(",w:").append(width);
140: colDefs.append(",a:\"")
141: .append(
142: ((AlignX) col.getAlignX()).name()
143: .toLowerCase()).append('"');
144: colDefs.append(",s:").append(
145: getSortOrderId(col.getSortOrder()));
146: colDefs.append("},");
147: }
148: }
149:
150: int len = colDefs.length();
151:
152: if (len == 1)
153: colDefs.append(']');
154: else
155: colDefs.setCharAt(len - 1, ']');
156:
157: addClientSideProperty(GridBox.Row.PROPERTY_ROW_CHECKED);
158: addClientSideProperty(GridBox.Row.PROPERTY_ROW_SELECTED);
159: addClientSideProperty(GridBox.Column.PROPERTY_COLUMN_WIDTH);
160: addInitProperty(GridBox.PROPERTY_VISIBLE_HEADER, gb
161: .isVisibleHeader());
162: addInitProperty(GridBox.PROPERTY_VISIBLE_CHECK_BOXES, gb
163: .isVisibleCheckBoxes());
164: addInitProperty(GridBox.PROPERTY_FULL_ROW_CHECK_BOX, gb
165: .isFullRowCheckBox());
166: addInitProperty(GridBox.PROPERTY_SORT_ALLOWED, gb
167: .isSortAllowed());
168: addInitProperty("parentIndex", parentIndex);
169: Row sr = gb.getSelectedRow();
170: addInitProperty("selectedRow", sr == null
171: || colDefs.length() == 2 ? -1 : sr.getIndex());
172: addInitProperty("checkedRows", checkedRows.toString());
173: addInitProperty("columnData", colDefs);
174: super .render(wr, c, container);
175: List<Row> rows = gb.getRows();
176:
177: for (int i = 0, cnt = rows.size(); i < cnt; i++) {
178: Row r = rows.get(i);
179: rowState.add(new Integer(System.identityHashCode(r)));
180: GridBox child = r.getChild();
181: if (child != null)
182: renderChild(i, child);
183: }
184: }
185:
186: private void calcAutoColumnWidth() {
187: int totalFixedWidth = 0;
188: int countAutoSize = 0;
189:
190: for (GridBox.Column c : gb.getColumns()) {
191: if (c.isVisible()) {
192: int width = c.getWidth();
193:
194: if (width == -1) {
195: countAutoSize++;
196: } else {
197: totalFixedWidth += width;
198: }
199: }
200: }
201:
202: if (countAutoSize > 0) {
203: //TODO: 21 is the scroll bar width, ideally this shouldn't be hard coded like this
204: int childColumnWidth = gb.getRowsWithChildren().size() > 0 ? 12
205: : 0;
206: autoColumnWidth = (int) Math.floor((gb.getWidth()
207: - gb.getStyle().getBorder().getSize()
208: - totalFixedWidth - 21 - childColumnWidth)
209: / countAutoSize);
210: if (autoColumnWidth < 0)
211: autoColumnWidth = 0;
212: } else {
213: autoColumnWidth = 0;
214: }
215: }
216:
217: void destroy() {
218: super .destroy();
219: gb.removeItemChangeListener(this );
220: gb = null;
221: rowState.clear();
222: columnState.clear();
223: columnState = rowState = null;
224:
225: if (childToRenderer != null) {
226: for (GridBoxRenderer gbr : childToRenderer.values()) {
227: gbr.destroy();
228: }
229:
230: childToRenderer.clear();
231: childToRenderer = null;
232: }
233: }
234:
235: public void propertyChange(PropertyChangeEvent pce) {
236: String name = pce.getPropertyName();
237: Object source = pce.getSource();
238: Object oldValue = pce.getOldValue();
239: Object newValue = pce.getNewValue();
240:
241: if (source instanceof GridBox) {
242: if (isPropertyChangeIgnored(name))
243: return;
244:
245: if (name.equals(GridBox.PROPERTY_VISIBLE_HEADER)) {
246: postClientEvent(SET_VISIBLE_HEADER, newValue);
247: } else if (name
248: .equals(GridBox.PROPERTY_VISIBLE_CHECK_BOXES)) {
249: postClientEvent(
250: SET_VISIBLE_CHECK_BOXES,
251: newValue,
252: newValue == Boolean.TRUE ? getCheckedRowIndices(
253: null).toString()
254: : null);
255: } else if (name.equals(GridBox.PROPERTY_FULL_ROW_CHECK_BOX)) {
256: postClientEvent(SET_FULL_ROW_CHECK_BOX, newValue);
257: } else if (name.equals(Component.PROPERTY_WIDTH)) {
258: Integer width = (Integer) newValue;
259: setPropertyWithEffect(Component.PROPERTY_WIDTH, width,
260: pce.getOldValue(), SET_WIDTH,
261: FX.PROPERTY_FX_SIZE_CHANGE);
262: calcAutoColumnWidth();
263: sendAutoColumnWidths(null);
264: } else if (name.equals(Component.PROPERTY_HEIGHT)) {
265: Integer height = (Integer) newValue;
266: setPropertyWithEffect(Component.PROPERTY_HEIGHT,
267: height, pce.getOldValue(), SET_HEIGHT,
268: FX.PROPERTY_FX_SIZE_CHANGE);
269: } else if (name.equals(GridBox.PROPERTY_SORT_ALLOWED)) {
270: postClientEvent(SET_SORT_ALLOWED, newValue);
271: } else {
272: super .propertyChange(pce);
273: }
274: } else if (source instanceof Row) {
275: if (isPropertyChangeIgnored(name)
276: || !rowState.contains(new Integer(System
277: .identityHashCode(source))))
278: return;
279:
280: if (name.equals(GridBox.Row.PROPERTY_ROW_SELECTED)) {
281: if (newValue == Boolean.TRUE) {
282: postClientEvent(SET_ROW_INDEX_SELECTED,
283: ((Row) source).getIndex());
284: }
285: } else if (name.equals(GridBox.Row.PROPERTY_ROW_CHECKED)) {
286: postClientEvent(SET_ROW_INDEX_CHECK_STATE, new Integer(
287: ((Row) source).getIndex()), newValue);
288: } else if (name.equals(GridBox.Row.PROPERTY_ROW_CHILD)) {
289: if (newValue != null) {
290: if (oldValue != null)
291: ((GridBoxRenderer) childToRenderer
292: .remove(oldValue)).destroy();
293: renderChild(new Integer(((Row) source).getIndex()),
294: (GridBox) newValue);
295: } else if (oldValue != null) {
296: GridBoxRenderer gbrChild = (GridBoxRenderer) childToRenderer
297: .remove(oldValue);
298: gbrChild.postClientEvent(DESTROY);
299: gbrChild.destroy();
300: }
301: }
302: } else if (source instanceof Column) {
303: if (isPropertyChangeIgnored(name)
304: || !columnState.contains(new Integer(System
305: .identityHashCode(source))))
306: return;
307: Column column = (Column) source;
308: int index = column.getIndex();
309:
310: if (name.equals(GridBox.Column.PROPERTY_COLUMN_VISIBLE)) {
311: if (((Boolean) newValue).booleanValue()) {
312: sendColumn(ADD_COLUMN, column);
313: } else {
314: removeColumn(index);
315: }
316: } else if (column.isVisible()) {
317: if (name.equals(GridBox.Column.PROPERTY_COLUMN_NAME)
318: && ((String) newValue).equals(column
319: .getHeader().getText())) {
320: postClientEvent(SET_COLUMN_NAME,
321: getVisibleIndex(index), getValue(this ,
322: (String) newValue, null, null));
323: } else if (name
324: .equals(GridBox.Header.PROPERTY_HEADER_TEXT)) {
325: postClientEvent(SET_COLUMN_NAME,
326: getVisibleIndex(index), getValue(this ,
327: (String) newValue, null, null));
328: } else if (name
329: .equals(GridBox.Column.PROPERTY_COLUMN_WIDTH)) {
330: if ((Integer) newValue == -1) {
331: calcAutoColumnWidth();
332: newValue = autoColumnWidth;
333: }
334: postClientEvent(SET_COLUMN_WIDTH,
335: getVisibleIndex(index), newValue);
336: } else if (name
337: .equals(GridBox.Column.PROPERTY_COLUMN_ALIGN_X)) {
338: postClientEvent(SET_COLUMN_ALIGN_X,
339: getVisibleIndex(index), ((AlignX) newValue)
340: .name().toLowerCase());
341: } else if (name
342: .equals(GridBox.Column.PROPERTY_COLUMN_SORT_ORDER)) {
343: postClientEvent(SET_COLUMN_SORT_ORDER,
344: getVisibleIndex(index),
345: getSortOrderId((Column.SortOrder) newValue));
346: } else if (name
347: .equals(GridBox.Column.PROPERTY_COLUMN_DISPLAY_FORMAT)) {
348: sendColumn(SET_COLUMN, column);
349: }
350: }
351: } else {
352: super .propertyChange(pce);
353: }
354:
355: }
356:
357: int getSortOrderId(Column.SortOrder sort) {
358: int order = 0;
359: if (sort == Column.SortOrder.ASC)
360: order = 1;
361: else if (sort == Column.SortOrder.DESC)
362: order = 2;
363: return order;
364: }
365:
366: public void itemChange(ItemChangeEvent ice) {
367: ItemChangeEvent.Type type = ice.getType();
368: Range cp = (Range) ice.getPosition();
369: int rowIndex = cp.getRowIndex();
370: int columnIndex = cp.getColumnIndex();
371: Object oldValue = ice.getOldValue();
372: Object newValue = ice.getNewValue();
373:
374: if (rowIndex == -1) { // Column Change
375: GridBox.Column nco = (GridBox.Column) newValue;
376: GridBox.Column oco = (GridBox.Column) oldValue;
377:
378: if (type == ItemChangeEvent.Type.REMOVE) {
379: if (((Column) oldValue).isVisible())
380: removeColumn(columnIndex);
381: columnState.remove(new Integer(System
382: .identityHashCode(oco)));
383: } else if (type == ItemChangeEvent.Type.ADD) {
384: columnState.add(new Integer(System
385: .identityHashCode(nco)));
386: if (nco.isVisible())
387: sendColumn(ADD_COLUMN, nco);
388: } else {
389: columnState.remove(new Integer(System
390: .identityHashCode(oco)));
391: columnState.add(new Integer(System
392: .identityHashCode(nco)));
393: if (nco.isVisible())
394: sendColumn(SET_COLUMN, nco);
395: }
396: } else if (columnIndex == -1) { // Row Change
397: GridBox.Row nro = (GridBox.Row) newValue;
398: GridBox.Row oro = (GridBox.Row) oldValue;
399:
400: if (type == ItemChangeEvent.Type.ADD) {
401: rowState.add(new Integer(System.identityHashCode(nro)));
402:
403: if (nro.size() > 0) {
404: postClientEvent(ADD_ROW, rowIndex, getValues(nro,
405: gb.getColumns(), null).toString(), nro
406: .isChecked() ? 1 : 0, nro.isSelected() ? 1
407: : 0);
408: GridBox gbc = nro.getChild();
409: if (gbc != null)
410: renderChild(rowIndex, gbc);
411: }
412: } else if (type == ItemChangeEvent.Type.REMOVE) {
413: if (gb.getRows().size() == 0 && rowState.size() > 0) { //Clear was called
414: rowState.clear();
415: postClientEvent(CLEAR_ROWS);
416:
417: if (childToRenderer != null
418: && childToRenderer.size() > 0) {
419: GridBoxRenderer[] children = childToRenderer
420: .values()
421: .toArray(
422: new GridBoxRenderer[childToRenderer
423: .size()]);
424: childToRenderer.clear();
425:
426: for (GridBoxRenderer gbr : children) {
427: gbr.destroy();
428: }
429: }
430: } else if (rowState.size() > 0) { //Don't process residual clear() row removals.
431: rowState.remove(new Integer(System
432: .identityHashCode(oro)));
433: postClientEvent(REMOVE_ROW, rowIndex);
434: GridBox gbc = oro.getChild();
435: if (gbc != null)
436: ((GridBoxRenderer) childToRenderer.remove(gbc))
437: .destroy();
438: }
439: } else {
440: rowState.remove(new Integer(System
441: .identityHashCode(oro)));
442: GridBox gbc = oro.getChild();
443: if (gbc != null)
444: ((GridBoxRenderer) childToRenderer.remove(gbc))
445: .destroy();
446: rowState.add(new Integer(System.identityHashCode(nro)));
447: postClientEvent(SET_ROW, rowIndex, getValues(nro,
448: gb.getColumns(), null).toString(), nro
449: .isChecked() ? 1 : 0, nro.isSelected() ? 1 : 0);
450: gbc = nro.getChild();
451: if (gbc != null)
452: renderChild(rowIndex, gbc);
453: }
454: } else { // Cell Change
455: GridBox.Column col = gb.getColumns().get(columnIndex);
456:
457: if (col.isVisible()) {
458: //XXX Wrapping the outbound value in a StringBuilder is a hack to get around a second layer of back-slash escaping.
459: Object textValue = getValue(this , newValue, col
460: .getDisplayFormat(), null);
461:
462: if (textValue instanceof String) {
463: StringBuilder sb = new StringBuilder();
464: sb.append('"');
465: sb.append(textValue);
466: sb.append('"');
467: textValue = sb;
468: }
469:
470: postClientEvent(SET_CELL, getVisibleIndex(columnIndex),
471: rowIndex, textValue);
472: }
473: }
474: }
475:
476: public void componentChange(WebComponentEvent event) {
477: String name = event.getName();
478: String value = (String) event.getValue();
479:
480: if (name.equals(GridBox.Row.PROPERTY_ROW_SELECTED)) {
481: setPropertyChangeIgnored(name, true);
482: ((Row) gb.getRows().get(Integer.parseInt(value)))
483: .setSelected(true);
484: setPropertyChangeIgnored(name, false);
485: } else if (name.equals(GridBox.Row.PROPERTY_ROW_CHECKED)) {
486: setPropertyChangeIgnored(name, true);
487: boolean state = value.charAt(0) == 't';
488: int index = Integer.parseInt(value.substring(1));
489: ((Row) gb.getRows().get(index)).setChecked(state);
490: setPropertyChangeIgnored(name, false);
491: } else if (name.equals(VIEW_STATE_COLUMN_SORT)) {
492: Column col = gb.getColumns().get(
493: getRealIndex(Integer.parseInt(value)));
494: col
495: .setSortOrder(col.getSortOrder() == Column.SortOrder.ASC ? Column.SortOrder.DESC
496: : Column.SortOrder.ASC);
497: if (gb.getSelectedRow() != null)
498: postClientEvent(SET_ROW_INDEX_SELECTED, gb
499: .getSelectedRow().getIndex(), Boolean.FALSE);
500: } else if (name.equals(GridBox.Column.PROPERTY_COLUMN_WIDTH)) {
501: setPropertyChangeIgnored(
502: GridBox.Column.PROPERTY_COLUMN_WIDTH, true);
503: String[] values = value.split(",");
504: GridBox.Column col = gb.getColumns().get(
505: getRealIndex(Integer.parseInt(values[0])));
506: if (col.getWidth() != -1)
507: col.setWidth(Integer.parseInt(values[1]));
508: setPropertyChangeIgnored(
509: GridBox.Column.PROPERTY_COLUMN_WIDTH, false);
510: } else {
511: super .componentChange(event);
512: }
513: }
514:
515: private void renderChild(Integer rowIndex, GridBox gb) {
516: if (childToRenderer == null)
517: childToRenderer = new HashMap<GridBox, GridBoxRenderer>(5);
518: GridBoxRenderer gbr = childToRenderer.get(gb);
519: if (gbr == null)
520: childToRenderer.put(gb, gbr = new GridBoxRenderer());
521: gbr.render(wr, gb, this , rowIndex);
522: }
523:
524: private void sendColumn(String method, Column c) {
525: calcAutoColumnWidth();
526: int width = c.getWidth();
527: if (width == -1)
528: width = autoColumnWidth;
529:
530: postClientEvent(method, new Object[] {
531: getVisibleIndex(c.getIndex()),
532: getValues(c, c.getDisplayFormat(), null).toString(),
533: getValue(this , c.getHeader().getText(), null, null),
534: width, ((AlignX) c.getAlignX()).name().toLowerCase(),
535: getSortOrderId(c.getSortOrder()) });
536:
537: sendAutoColumnWidths(c);
538: }
539:
540: private void sendAutoColumnWidths(Column exclude) {
541: if (autoColumnWidth > 0) {
542: List<GridBox.Column> lst = gb.getColumns();
543:
544: for (int i = 0, cnt = lst.size(); i < cnt; i++) {
545: GridBox.Column c = lst.get(i);
546:
547: if (c != exclude && c.isVisible() && c.getWidth() == -1) {
548: postClientEvent(SET_COLUMN_WIDTH,
549: getVisibleIndex(i), autoColumnWidth);
550: }
551: }
552: }
553: }
554:
555: private void removeColumn(Integer index) {
556: postClientEvent(REMOVE_COLUMN, getVisibleIndex(index));
557: calcAutoColumnWidth();
558: sendAutoColumnWidths(null);
559: }
560:
561: private int getVisibleIndex(int index) {
562: int visibleIndex = -1;
563: List<GridBox.Column> cols = gb.getColumns();
564:
565: for (int i = 0; i <= index; i++) {
566: if (i == index || cols.get(i).isVisible())
567: visibleIndex++;
568: }
569:
570: return visibleIndex;
571: }
572:
573: private int getRealIndex(int index) {
574: int realIndex = index;
575: List<GridBox.Column> cols = gb.getColumns();
576: for (int i = 0; i < realIndex; i++)
577: if (!cols.get(i).isVisible())
578: realIndex++;
579: while (!cols.get(realIndex).isVisible())
580: realIndex++;
581: return realIndex;
582: }
583:
584: static Object getValue(ComponentRenderer cr, Object o,
585: GridBox.Column.Format format, StringBuilder sb) {
586: if (o == null)
587: o = "";
588: if (format != null)
589: o = format.format(o);
590: o = cr.parseRichText(o.toString());
591:
592: if (o instanceof String) {
593: o = getEscapedText((String) o, true);
594: if (sb != null)
595: sb.append('"').append((String) o).append('"');
596: return o;
597: } else {
598: if (sb != null)
599: sb.append(o);
600: return o;
601: }
602: }
603:
604: //TODO: I made this not static, is that okay?
605: private StringBuilder getValues(List<Object> l, Object formats,
606: StringBuilder sb) {
607: if (sb == null)
608: sb = new StringBuilder();
609:
610: sb.append('[');
611:
612: if (formats instanceof List) {
613: List<Column> formatList = (List) formats;
614:
615: for (int i = 0, cnt = l.size(); i < cnt; i++) {
616: Column.Format format;
617: boolean visible;
618:
619: if (formatList.size() > 0) {
620: Column column = formatList.get(i);
621: format = column.getDisplayFormat();
622: column.getIndex();
623: visible = column.isVisible();
624: } else {
625: format = null;
626: visible = false;
627: }
628:
629: if (visible) {
630: getValue(this , l.get(i), format, sb);
631: sb.append(',');
632: }
633: }
634: } else {
635: Column.Format format = (Column.Format) formats;
636:
637: for (int i = 0, cnt = l.size(); i < cnt; i++) {
638: getValue(this , l.get(i), format, sb);
639: sb.append(',');
640: }
641: }
642:
643: if (sb.charAt(sb.length() - 1) != '[')
644: sb.setCharAt(sb.length() - 1, ']');
645: else
646: sb.append(']');
647:
648: return sb;
649: }
650:
651: private StringBuilder getCheckedRowIndices(StringBuilder sb) {
652: if (sb == null)
653: sb = new StringBuilder();
654: sb.append(',');
655:
656: for (GridBox.Row r : gb.getCheckedRows()) {
657: sb.append(r.getIndex()).append(',');
658: }
659:
660: return sb;
661: }
662: }
|