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.decorator;
13
14 /***
15 * @author epesh
16 * @author Fabrizio Giustina
17 * @version $Revision: 1.11 $ ($Author: fgiust $)
18 */
19 public abstract class TableDecorator extends Decorator
20 {
21
22 /***
23 * object representing the current row.
24 */
25 private Object currentRowObject;
26
27 /***
28 * index in displayed list.
29 */
30 private int viewIndex = -1;
31
32 /***
33 * index in original list.
34 */
35 private int listIndex = -1;
36
37 /***
38 * return the index in the displayed list.
39 * @return int index in the displayed list
40 */
41 public final int getViewIndex()
42 {
43 return this.viewIndex;
44 }
45
46 /***
47 * return the index in the original list.
48 * @return int index in the original list
49 */
50 public final int getListIndex()
51 {
52 return this.listIndex;
53 }
54
55 /***
56 * Get the object representing the current row.
57 * @return Object
58 */
59 public final Object getCurrentRowObject()
60 {
61 return this.currentRowObject;
62 }
63
64 /***
65 * Initialize the current row. Note this method is also called when sorting a table using a property supplied by the
66 * table decorator, so the method could be called multiple times during rendering. When used to initialize sorting
67 * the method is always called with 0, 0 as currentViewIndex and currentListIndex.
68 * @param rowObject object representing the current row
69 * @param currentViewIndex int index in the displayed list
70 * @param currentListIndex int index in the original list
71 */
72 public final void initRow(Object rowObject, int currentViewIndex, int currentListIndex)
73 {
74 this.currentRowObject = rowObject;
75 this.viewIndex = currentViewIndex;
76 this.listIndex = currentListIndex;
77 }
78
79 /***
80 * Called at the beginning of a row. Can be subclassed to provide specific data at the beginning of a row
81 * @return null in the default implementation
82 */
83 public String startRow()
84 {
85 return null;
86 }
87
88 /***
89 * Called at the end of a row. Can be subclassed to provide specific data at the end of a row
90 * @return null in the default implementation
91 */
92 public String finishRow()
93 {
94 return null;
95 }
96
97 /***
98 * Called at the end of evaluation. Can be subclassed to eventully clean up data. Always remember to also call
99 * super.finish()!
100 */
101 public void finish()
102 {
103 this.currentRowObject = null;
104 super.finish();
105 }
106
107 }