01: /*
02: * $Id: ListViewWithAlternatingRowStyle.java 5244 2006-04-03 06:17:05Z
03: * jdonnerstag $ $Revision: 460265 $ $Date: 2006-04-03 08:17:05 +0200 (Mo, 03 Apr
04: * 2006) $
05: *
06: * ==================================================================== Licensed
07: * under the Apache License, Version 2.0 (the "License"); you may not use this
08: * file except in compliance with the License. You may obtain a copy of the
09: * License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16: * License for the specific language governing permissions and limitations under
17: * the License.
18: */
19: package wicket.examples.displaytag.utils;
20:
21: import java.util.List;
22:
23: import wicket.markup.ComponentTag;
24: import wicket.markup.html.list.ListItem;
25: import wicket.markup.html.list.ListView;
26: import wicket.model.IModel;
27:
28: /**
29: * This is a simple ListView extension providing alternate row styles (colours).
30: * The styles are named "even" and "odd".
31: *
32: * @author Juergen Donnerstag
33: */
34: public abstract class ListViewWithAlternatingRowStyle extends ListView {
35: /**
36: * Constructor
37: *
38: * @param id
39: * @param data
40: */
41: public ListViewWithAlternatingRowStyle(final String id,
42: final List data) {
43: super (id, data);
44: }
45:
46: /**
47: * Constructor
48: *
49: * @param id
50: * @param model
51: */
52: public ListViewWithAlternatingRowStyle(final String id,
53: final IModel model) {
54: super (id, model);
55: }
56:
57: /**
58: * Subclass Table's newCell() and return a ListItem which will add/modify
59: * its class attribute and thus provide ListItems with alternating row
60: * colours.
61: *
62: * See wicket.markup.html.table.Table#newItem(int)
63: *
64: * @param index
65: * Index of item
66: * @return List item
67: */
68: protected ListItem newItem(final int index) {
69: return new ListItem(index, getListItemModel(getModel(), index)) {
70: protected void onComponentTag(final ComponentTag tag) {
71: // add/modify the attribute controlling the CSS style
72: tag
73: .put("class", (getIndex() % 2) == 0 ? "even"
74: : "odd");
75:
76: // continue with default behavior
77: super.onComponentTag(tag);
78: }
79: };
80: }
81: }
|