1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.extremecomponents.table.cell;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.extremecomponents.table.bean.Column;
22 import org.extremecomponents.table.model.TableModel;
23 import org.extremecomponents.table.model.PageHandler;
24 import org.extremecomponents.table.model.ParameterRegistry;
25 import org.extremecomponents.util.HtmlBuilder;
26
27
28
29 /***
30 * A pagination cell.
31 *
32 * @author Jeff Johnston
33 */
34 public class PageCell extends BaseCell
35 {
36 private static Log logger = LogFactory.getLog(PageCell.class);
37 private String name;
38 private int page = -1;
39 private String additionalParameters;
40 private boolean selected = false;
41
42 /***
43 * Need to get the additional parameters that will be passed when paging through the pages.
44 */
45 public void init(TableModel model, Column column, Integer rowcount)
46 {
47 super.init(model, column, rowcount);
48 additionalParameters = model.getRegistry().getURLParameterString(true, true, false);
49 }
50
51 public void initCustom(String name, int page, boolean selected)
52 {
53 this.name = name;
54 this.page = page;
55 this.selected = selected;
56 }
57
58 public String html()
59 {
60 HtmlBuilder html = new HtmlBuilder();
61
62 html.td(4);
63 if (name.equals(PageHandler.FIRST))
64 {
65 html.styleClass("paginationFirst");
66 }
67 else if (name.equals(PageHandler.LAST))
68 {
69 html.styleClass("paginationLast");
70 }
71 html.close();
72
73 if (name.equals(PageHandler.FIRST))
74 {
75 String firstPage = model.getTable().getImage(PageHandler.FIRST_PAGE);
76 if (StringUtils.isNotEmpty(firstPage))
77 {
78 name = HtmlBuilder.getImage(firstPage, "First Page");
79 }
80 else
81 {
82 name = "|<< ";
83 }
84 }
85 if (name.equals(PageHandler.PREV))
86 {
87 String prevPage = model.getTable().getImage(PageHandler.PREV_PAGE);
88 if (StringUtils.isNotEmpty(prevPage))
89 {
90 name = HtmlBuilder.getImage(prevPage, "Previous Page");
91 }
92 else
93 {
94 name = " << ";
95 }
96 }
97
98 if (name.equals(PageHandler.NEXT))
99 {
100 String nextPage = model.getTable().getImage(PageHandler.NEXT_PAGE);
101 if (StringUtils.isNotEmpty(nextPage))
102 {
103 name = HtmlBuilder.getImage(nextPage, "Next Page");
104 }
105 else
106 {
107 name = " >> ";
108 }
109 }
110 if (name.equals(PageHandler.LAST))
111 {
112 String lastPage = model.getTable().getImage(PageHandler.LAST_PAGE);
113 if (StringUtils.isNotEmpty(lastPage))
114 {
115 name = HtmlBuilder.getImage(lastPage, "Last Page");
116 }
117 else
118 {
119 name = " >>|";
120 }
121 }
122
123
124 if (page == -1)
125 {
126 html.append(name);
127 }
128 else
129 {
130 html.a();
131 html.quote();
132
133 String action = model.getTable().getAction();
134
135 if (StringUtils.isNotEmpty(action))
136 {
137 html.append(action);
138 }
139
140 html.question().append(model.getTableKey()).append(ParameterRegistry.PAGE).equals().append(""+page);
141 html.append(additionalParameters);
142 html.quote().close();
143
144 if (selected)
145 {
146 html.bold().append("[").append(name).append("]").boldEnd();
147 }
148 else
149 {
150 html.append(name);
151 }
152
153 html.aEnd();
154 }
155
156 html.tdEnd();
157
158 return html.toString();
159 }
160
161 public String value()
162 {
163 return "";
164 }
165 }