Source code: er/extensions/ERXTable.java
1 /*
2 * Copyright (C) NetStruxr, Inc. All rights reserved.
3 *
4 * This software is published under the terms of the NetStruxr
5 * Public Software License version 0.5, a copy of which has been
6 * included with this distribution in the LICENSE.NPL file. */
7 package er.extensions;
8
9 import com.webobjects.foundation.*;
10 import com.webobjects.eocontrol.*;
11 import com.webobjects.eoaccess.*;
12 import com.webobjects.appserver.*;
13
14 /**
15 * Enhanced table component that adds the ability to have the
16 * table layed out in a vertical orientation and adds the
17 * ability to specify an array of header images that appear
18 * in the header cells of the table. Corrects a bug intorduced
19 * in WO 5.1 where OutOfBounds exceptions are thrown. Note that
20 * this component subclasses WOTable from this framework, not
21 * the WOTable in com.webobjects.woextensions. The reason for
22 * this is that all of the instance variables are private in
23 * JavaWOExtensions WOTable.<br/>
24 * <br/>
25 * Synopsis:<br/>
26 * list=<i>anArray</i>;item=<i>aSettableObject</i>;[col=<i>aSettableNumber</i>;][index=<i>aSettableNumber</i>;][row=<i>aSettableNumber</i>;]
27 * [maxColumns=<i>aNumber</i>;][tableBackgroundColor=<i>aString</i>;][border=<i>aNumber</i>;][cellpadding=<i>aNumber</i>;][cellspacing=<i>aNumber</i>;]
28 * [rowBackgroundColor=<i>aString</i>;][cellBackgroundColor=<i>aString</i>;][cellAlign=<i>aNumber</i>;][cellVAlign=<i>aNumber</i>;]
29 * [cellWidth=<i>aNumber</i>;][tableWidth=<i>aNumber</i>;]
30 * [goingVertically=<i>aBoolean</i>;][headerImages=<i>anArray</i>;][headerRowBackgroundColor=<i>aColor</i>;]
31 *
32 * @binding col pushed to the parent with the current
33 * column number
34 * @binding index pushed to the parent indicating
35 * the current index
36 * @binding list of objects to construct the table for
37 * @binding maxColumns maximum number of columns
38 * @binding row pushed to the parent with the current
39 * row number
40 * @binding item pushed to the parent with the
41 * current object from the list
42 * @binding tableBackgroundColor background color for table
43 * @binding border table border
44 * @binding cellpadding cell padding
45 * @binding cellspacing cell spacing
46 * @binding rowBackgroundColor background color to be
47 * used for the rows of the table
48 * @binding cellBackgroundColor background color for the cell
49 * @binding cellAlign cell's alignment
50 * @binding cellVAlign cell's vertical alignment
51 * @binding cellWidth cell's width
52 * @binding tableWidth table width
53 * @binding goingVertically boolean if the list should be
54 * layed out horizontally or vertically.
55 * @binding headerImages array of images to be displayed
56 * in the header cells of the table
57 * @binding headerRowBackgroundColor background color for the
58 * header row
59 */
60 public class ERXTable extends WOTable {
61
62 /** used in the repetition for header images */
63 protected String header;
64 /** caches the value from the binding goingVertical */
65 protected Boolean _goingVertically;
66
67 /**
68 * Public constructor
69 * @param context the context
70 */
71 public ERXTable(WOContext context) {
72 super(context);
73 }
74
75 /**
76 * Component is stateless.
77 * @return true
78 */
79 // CHECKME: This shouldn't be needed, although for some strange reason it was needed at one point.
80 public boolean isStateless() { return true; }
81
82 /**
83 * resets the cached variables
84 */
85 protected void _resetInternalCaches() {
86 super._resetInternalCaches();
87 _goingVertically = null;
88 }
89
90 /**
91 * Denotes if the list should be layed out vertically
92 * or horizontally. This is the boolean value from the
93 * binding: <b>goingVertically</b>
94 * @return if the list of items should be layed out
95 * vertically.
96 */
97 public boolean goingVertically() {
98 if (_goingVertically == null) {
99 _goingVertically=ERXUtilities.booleanValue(valueForBinding("goingVertically")) ?
100 Boolean.TRUE : Boolean.FALSE;
101 }
102 return _goingVertically.booleanValue();
103 }
104
105 /**
106 * Overridden to account for when goingVertical is
107 * enabled. Also corrects a bug from the WO 5.1
108 * release that would throw OutOfBoundsExceptions.
109 * This method pushs the current item up to the
110 * parent component.
111 */
112 public void pushItem() {
113 NSArray aList = list();
114 int index;
115 if (goingVertically()) {
116 int c=aList.count() % maxColumns();
117 index = currentRow+rowCount()*currentCol;
118 if (c!=0 && currentCol>c) index-=(currentCol-c);
119 } else {
120 index = currentCol+maxColumns()*currentRow;
121 }
122 // WO 5.1 guarding against OOB index
123 // WORepetition count=x seems to go to x+1 in 5.1, even though it is not displayed
124 Object item = index < aList.count() ? aList.objectAtIndex(index) : null;
125 setValueForBinding(item, "item");
126 if (canSetValueForBinding("row"))
127 setValueForBinding(ERXConstant.integerForInt(currentRow), "row");
128 if (canSetValueForBinding("col"))
129 setValueForBinding(ERXConstant.integerForInt(currentCol), "col");
130 if (canSetValueForBinding("index"))
131 setValueForBinding(ERXConstant.integerForInt(index), "index");
132 currentItemIndex++;
133 }
134
135 /**
136 * Conditional to determine if the binding: <b>headerImages</b>
137 * is present.
138 * @return if the component has the binding headerImages.
139 */
140 public boolean hasHeaders() { return hasBinding("headerImages"); }
141 }