KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > model > Row


1 /**
2  * Licensed under the Artistic License; you may not use this file
3  * except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://displaytag.sourceforge.net/license.html
7  *
8  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */

12 package org.displaytag.model;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.commons.lang.builder.ToStringBuilder;
20 import org.apache.commons.lang.builder.ToStringStyle;
21 import org.displaytag.util.HtmlAttributeMap;
22 import org.displaytag.util.MultipleHtmlAttribute;
23 import org.displaytag.util.TagConstants;
24
25
26 /**
27  * Holds informations for a table row.
28  * @author Fabrizio Giustina
29  * @version $Revision: 956 $ ($Author: fgiust $)
30  */

31 public class Row
32 {
33
34     /**
35      * Object holding values for the current row.
36      */

37     private Object JavaDoc rowObject;
38
39     /**
40      * List of cell objects.
41      */

42     private List JavaDoc staticCells;
43
44     /**
45      * Row number.
46      */

47     private int rowNumber;
48
49     /**
50      * TableModel which the row belongs to.
51      */

52     private TableModel tableModel;
53
54     /**
55      * Constructor for Row.
56      * @param object Object
57      * @param number int
58      */

59     public Row(Object JavaDoc object, int number)
60     {
61         this.rowObject = object;
62         this.rowNumber = number;
63         this.staticCells = new ArrayList JavaDoc();
64     }
65
66     /**
67      * Setter for the row number.
68      * @param number row number
69      */

70     public void setRowNumber(int number)
71     {
72         this.rowNumber = number;
73     }
74
75     /**
76      * Getter for the row number.
77      * @return row number
78      */

79     public int getRowNumber()
80     {
81         return this.rowNumber;
82     }
83
84     /**
85      * Adds a cell to the row.
86      * @param cell Cell
87      */

88     public void addCell(Cell cell)
89     {
90         this.staticCells.add(cell);
91     }
92
93     /**
94      * getter for the list of Cell object.
95      * @return List containing Cell objects
96      */

97     public List JavaDoc getCellList()
98     {
99         return this.staticCells;
100     }
101
102     /**
103      * getter for the object holding values for the current row.
104      * @return Object object holding values for the current row
105      */

106     public Object JavaDoc getObject()
107     {
108         return this.rowObject;
109     }
110
111     /**
112      * Iterates on columns.
113      * @param columns List
114      * @return ColumnIterator
115      */

116     public ColumnIterator getColumnIterator(List JavaDoc columns)
117     {
118         return new ColumnIterator(columns, this);
119     }
120
121     /**
122      * Setter for the table model the row belongs to.
123      * @param table TableModel
124      */

125     protected void setParentTable(TableModel table)
126     {
127         this.tableModel = table;
128     }
129
130     /**
131      * Getter for the table model the row belongs to.
132      * @return TableModel
133      */

134     protected TableModel getParentTable()
135     {
136         return this.tableModel;
137     }
138
139     /**
140      * Writes the open <tr> tag.
141      * @return String <tr> tag with the appropriate css class attribute
142      */

143     public String JavaDoc getOpenTag()
144     {
145         Map JavaDoc rowAttributes = new HtmlAttributeMap();
146         MultipleHtmlAttribute cssAttribute = new MultipleHtmlAttribute(this.tableModel.getProperties().getCssRow(
147             this.rowNumber));
148
149         if (this.tableModel.getTableDecorator() != null)
150         {
151             try
152             {
153                 String JavaDoc addStyle = this.tableModel.getTableDecorator().addRowClass();
154
155                 if (StringUtils.isNotBlank(addStyle))
156                 {
157                     cssAttribute.addAttributeValue(addStyle);
158                 }
159
160                 String JavaDoc id = this.tableModel.getTableDecorator().addRowId();
161                 if (StringUtils.isNotBlank(id))
162                 {
163                     rowAttributes.put(TagConstants.ATTRIBUTE_ID, id);
164                 }
165             }
166             catch (NoSuchMethodError JavaDoc e)
167             {
168                 // this catch is here to allow decorators compiled with displaytag 1.0 work with 1.1
169
// since the addRowClass() and addRowId() are new in displaytag 1.1 earlier decorators could throw
170
// a NoSuchMethodError... be nice with them till a next major release
171
}
172         }
173
174         rowAttributes.put(TagConstants.ATTRIBUTE_CLASS, cssAttribute);
175
176         StringBuffer JavaDoc tag = new StringBuffer JavaDoc();
177         tag.append(TagConstants.TAG_OPEN);
178         tag.append(TagConstants.TAGNAME_ROW);
179
180         tag.append(rowAttributes.toString());
181
182         tag.append(TagConstants.TAG_CLOSE);
183
184         return tag.toString();
185     }
186
187     /**
188      * writes the </tr> tag.
189      * @return String </tr> tag
190      */

191     public String JavaDoc getCloseTag()
192     {
193         return TagConstants.TAG_TR_CLOSE;
194     }
195
196     /**
197      * @see java.lang.Object#toString()
198      */

199     public String JavaDoc toString()
200     {
201         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) //
202
.append("rowNumber", this.rowNumber) //$NON-NLS-1$
203
.append("rowObject", this.rowObject) //$NON-NLS-1$
204
.toString();
205     }
206 }
Popular Tags