View Javadoc
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.Constants;
22  import org.codelibs.fess.util.ComponentUtil;
23  
24  /**
25   * Pager for related content management that provides pagination functionality
26   * for displaying related content items in the admin interface.
27   * This class handles pagination state including current page number, page size,
28   * total record count, and navigation controls.
29   */
30  public class RelatedContentPager implements Serializable {
31  
32      /**
33       * Default constructor.
34       */
35      public RelatedContentPager() {
36          // Default constructor
37      }
38  
39      private static final long serialVersionUID = 1L;
40  
41      /** Default current page number constant. */
42      public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
43  
44      /** Total number of records across all pages. */
45      private int allRecordCount;
46  
47      /** Total number of pages calculated from record count and page size. */
48      private int allPageCount;
49  
50      /** Flag indicating whether a previous page exists. */
51      private boolean existPrePage;
52  
53      /** Flag indicating whether a next page exists. */
54      private boolean existNextPage;
55  
56      /** List of page numbers for pagination navigation. */
57      private List<Integer> pageNumberList;
58  
59      /** Number of records to display per page. */
60      private int pageSize;
61  
62      /** Current page number being displayed. */
63      private int currentPageNumber;
64  
65      /** Related content ID for filtering. */
66      public String id;
67  
68      /** Search term for filtering related content. */
69      public String term;
70  
71      /** Content text for filtering related content. */
72      public String content;
73  
74      /** User who created the related content. */
75      public String createdBy;
76  
77      /** Creation time of the related content. */
78      public String createdTime;
79  
80      /** Version number for optimistic locking. */
81      public String versionNo;
82  
83      /**
84       * Clears all pagination state and filter parameters.
85       * Resets pagination counters to default values and clears all filter fields.
86       */
87      public void clear() {
88          allRecordCount = 0;
89          allPageCount = 0;
90          existPrePage = false;
91          existNextPage = false;
92          pageSize = getDefaultPageSize();
93          currentPageNumber = getDefaultCurrentPageNumber();
94  
95          id = null;
96          term = null;
97          content = null;
98          createdBy = null;
99          createdTime = null;
100         versionNo = null;
101 
102     }
103 
104     /**
105      * Gets the total number of records across all pages.
106      *
107      * @return total record count
108      */
109     public int getAllRecordCount() {
110         return allRecordCount;
111     }
112 
113     /**
114      * Sets the total number of records across all pages.
115      *
116      * @param allRecordCount total record count
117      */
118     public void setAllRecordCount(final int allRecordCount) {
119         this.allRecordCount = allRecordCount;
120     }
121 
122     /**
123      * Gets the total number of pages calculated from record count and page size.
124      *
125      * @return total page count
126      */
127     public int getAllPageCount() {
128         return allPageCount;
129     }
130 
131     /**
132      * Sets the total number of pages.
133      *
134      * @param allPageCount total page count
135      */
136     public void setAllPageCount(final int allPageCount) {
137         this.allPageCount = allPageCount;
138     }
139 
140     /**
141      * Checks if a previous page exists.
142      *
143      * @return true if previous page exists, false otherwise
144      */
145     public boolean isExistPrePage() {
146         return existPrePage;
147     }
148 
149     /**
150      * Sets whether a previous page exists.
151      *
152      * @param existPrePage true if previous page exists, false otherwise
153      */
154     public void setExistPrePage(final boolean existPrePage) {
155         this.existPrePage = existPrePage;
156     }
157 
158     /**
159      * Checks if a next page exists.
160      *
161      * @return true if next page exists, false otherwise
162      */
163     public boolean isExistNextPage() {
164         return existNextPage;
165     }
166 
167     /**
168      * Sets whether a next page exists.
169      *
170      * @param existNextPage true if next page exists, false otherwise
171      */
172     public void setExistNextPage(final boolean existNextPage) {
173         this.existNextPage = existNextPage;
174     }
175 
176     /**
177      * Gets the number of records to display per page.
178      * If page size is not set or is invalid, returns the default page size.
179      *
180      * @return page size
181      */
182     public int getPageSize() {
183         if (pageSize <= 0) {
184             pageSize = getDefaultPageSize();
185         }
186         return pageSize;
187     }
188 
189     /**
190      * Sets the number of records to display per page.
191      *
192      * @param pageSize page size
193      */
194     public void setPageSize(final int pageSize) {
195         this.pageSize = pageSize;
196     }
197 
198     /**
199      * Gets the current page number being displayed.
200      * If current page number is not set or is invalid, returns the default current page number.
201      *
202      * @return current page number
203      */
204     public int getCurrentPageNumber() {
205         if (currentPageNumber <= 0) {
206             currentPageNumber = getDefaultCurrentPageNumber();
207         }
208         return currentPageNumber;
209     }
210 
211     /**
212      * Sets the current page number to display.
213      *
214      * @param currentPageNumber current page number
215      */
216     public void setCurrentPageNumber(final int currentPageNumber) {
217         this.currentPageNumber = currentPageNumber;
218     }
219 
220     /**
221      * Gets the list of page numbers for pagination navigation.
222      *
223      * @return list of page numbers
224      */
225     public List<Integer> getPageNumberList() {
226         return pageNumberList;
227     }
228 
229     /**
230      * Sets the list of page numbers for pagination navigation.
231      *
232      * @param pageNumberList list of page numbers
233      */
234     public void setPageNumberList(final List<Integer> pageNumberList) {
235         this.pageNumberList = pageNumberList;
236     }
237 
238     /**
239      * Gets the default current page number from system constants.
240      *
241      * @return default current page number
242      */
243     protected int getDefaultCurrentPageNumber() {
244         return Constants.DEFAULT_ADMIN_PAGE_NUMBER;
245     }
246 
247     /**
248      * Gets the default page size from system configuration.
249      *
250      * @return default page size
251      */
252     protected int getDefaultPageSize() {
253         return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
254     }
255 
256 }