1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.app.pager;
17
18 import java.io.Serializable;
19 import java.util.List;
20
21 import org.codelibs.fess.util.ComponentUtil;
22
23 /**
24 * Pager for data configuration management with standard paging functionality.
25 * This class provides pagination support for data configuration listings in the admin interface,
26 * including navigation controls and search/filter parameters.
27 */
28 public class DataConfigPager implements Serializable {
29
30 private static final long serialVersionUID = 1L;
31
32 /** Default page size for pagination. */
33 public static final int DEFAULT_PAGE_SIZE = 20;
34
35 /** Default current page number (first page). */
36 public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
37
38 /** Total number of records across all pages. */
39 private int allRecordCount;
40
41 /** Total number of pages. */
42 private int allPageCount;
43
44 /** Flag indicating if there is a previous page. */
45 private boolean existPrePage;
46
47 /** Flag indicating if there is a next page. */
48 private boolean existNextPage;
49
50 /** List of page numbers for pagination navigation. */
51 private List<Integer> pageNumberList;
52
53 /** Number of records to display per page. */
54 private int pageSize;
55
56 /** Current page number being displayed. */
57 private int currentPageNumber;
58
59 /** Search/filter parameter for data configuration ID. */
60 public String id;
61
62 /** Search/filter parameter for data configuration name. */
63 public String name;
64
65 /** Search/filter parameter for data configuration handler name. */
66 public String handlerName;
67
68 /** Search/filter parameter for data configuration boost value. */
69 public String boost;
70
71 /** Search/filter parameter for data configuration availability status. */
72 public String available;
73
74 /** Search/filter parameter for data configuration sort order. */
75 public String sortOrder;
76
77 /** Search/filter parameter for data configuration creator. */
78 public String createdBy;
79
80 /** Search/filter parameter for data configuration creation time. */
81 public String createdTime;
82
83 /** Search/filter parameter for data configuration version number. */
84 public String versionNo;
85
86 /** Search/filter parameter for data configuration description. */
87 public String description;
88
89 /**
90 * Creates a new DataConfigPager with default values.
91 * Initializes pagination settings and clears all search parameters.
92 */
93 public DataConfigPager() {
94 // Default constructor with explicit documentation
95 }
96
97 /**
98 * Clears all paging state and search/filter parameters.
99 * Resets the pager to its initial state with default values.
100 */
101 public void clear() {
102 allRecordCount = 0;
103 allPageCount = 0;
104 existPrePage = false;
105 existNextPage = false;
106 pageSize = getDefaultPageSize();
107 currentPageNumber = getDefaultCurrentPageNumber();
108
109 id = null;
110 name = null;
111 handlerName = null;
112 boost = null;
113 available = null;
114 sortOrder = null;
115 createdBy = null;
116 createdTime = null;
117 versionNo = null;
118 description = null;
119
120 }
121
122 /**
123 * Returns the default current page number.
124 *
125 * @return the default current page number (1)
126 */
127 protected int getDefaultCurrentPageNumber() {
128 return DEFAULT_CURRENT_PAGE_NUMBER;
129 }
130
131 /**
132 * Gets the total number of records across all pages.
133 *
134 * @return the total record count
135 */
136 public int getAllRecordCount() {
137 return allRecordCount;
138 }
139
140 /**
141 * Sets the total number of records across all pages.
142 *
143 * @param allRecordCount the total record count
144 */
145 public void setAllRecordCount(final int allRecordCount) {
146 this.allRecordCount = allRecordCount;
147 }
148
149 /**
150 * Gets the total number of pages.
151 *
152 * @return the total page count
153 */
154 public int getAllPageCount() {
155 return allPageCount;
156 }
157
158 /**
159 * Sets the total number of pages.
160 *
161 * @param allPageCount the total page count
162 */
163 public void setAllPageCount(final int allPageCount) {
164 this.allPageCount = allPageCount;
165 }
166
167 /**
168 * Checks if there is a previous page available.
169 *
170 * @return true if there is a previous page, false otherwise
171 */
172 public boolean isExistPrePage() {
173 return existPrePage;
174 }
175
176 /**
177 * Sets whether there is a previous page available.
178 *
179 * @param existPrePage true if there is a previous page, false otherwise
180 */
181 public void setExistPrePage(final boolean existPrePage) {
182 this.existPrePage = existPrePage;
183 }
184
185 /**
186 * Checks if there is a next page available.
187 *
188 * @return true if there is a next page, false otherwise
189 */
190 public boolean isExistNextPage() {
191 return existNextPage;
192 }
193
194 /**
195 * Sets whether there is a next page available.
196 *
197 * @param existNextPage true if there is a next page, false otherwise
198 */
199 public void setExistNextPage(final boolean existNextPage) {
200 this.existNextPage = existNextPage;
201 }
202
203 /**
204 * Gets the number of records to display per page.
205 * If the page size is not set or is invalid, returns the default page size.
206 *
207 * @return the page size
208 */
209 public int getPageSize() {
210 if (pageSize <= 0) {
211 pageSize = getDefaultPageSize();
212 }
213 return pageSize;
214 }
215
216 /**
217 * Sets the number of records to display per page.
218 *
219 * @param pageSize the page size
220 */
221 public void setPageSize(final int pageSize) {
222 this.pageSize = pageSize;
223 }
224
225 /**
226 * Gets the current page number being displayed.
227 * If the current page number is not set or is invalid, returns the default page number.
228 *
229 * @return the current page number
230 */
231 public int getCurrentPageNumber() {
232 if (currentPageNumber <= 0) {
233 currentPageNumber = getDefaultCurrentPageNumber();
234 }
235 return currentPageNumber;
236 }
237
238 /**
239 * Sets the current page number being displayed.
240 *
241 * @param currentPageNumber the current page number
242 */
243 public void setCurrentPageNumber(final int currentPageNumber) {
244 this.currentPageNumber = currentPageNumber;
245 }
246
247 /**
248 * Gets the list of page numbers for pagination navigation.
249 *
250 * @return the list of page numbers
251 */
252 public List<Integer> getPageNumberList() {
253 return pageNumberList;
254 }
255
256 /**
257 * Sets the list of page numbers for pagination navigation.
258 *
259 * @param pageNumberList the list of page numbers
260 */
261 public void setPageNumberList(final List<Integer> pageNumberList) {
262 this.pageNumberList = pageNumberList;
263 }
264
265 /**
266 * Returns the default page size from the system configuration.
267 *
268 * @return the default page size configured in the system
269 */
270 protected int getDefaultPageSize() {
271 return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
272 }
273
274 }