View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.element;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
19  import org.kuali.rice.krad.uif.element.ContentElementBase;
20  import org.kuali.rice.krad.uif.util.LifecycleElement;
21  
22  /**
23   * Pager widgets are used to page a set of information which has multiple pages.
24   *
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   * @see org.kuali.rice.krad.uif.layout.StackedLayoutManager
27   */
28  public abstract class Pager extends ContentElementBase {
29      private static final long serialVersionUID = 4581039429463422458L;
30  
31      private String linkScript;
32  
33      private int numberOfPages;
34      private int currentPage;
35  
36      private String prevText;
37      private String nextText;
38  
39      public Pager() {
40          super();
41      }
42  
43      /**
44       * performFinalize calculates the pagesStart and pagesEnd properties (using numberOfPages, currentPage, and
45       * maxNumberedLinksShown - these must be set) which determines pages shown by the widget
46       *
47       * @param model the current model
48       * @param parent parent container
49       */
50      @Override
51      public void performFinalize(Object model, LifecycleElement parent) {
52          super.performFinalize(model, parent);
53  
54          // if no pages or 1 page, do not render
55          if (numberOfPages == 0 || numberOfPages == 1) {
56              this.setRender(false);
57          }
58  
59          this.linkScript = "e.preventDefault();" + this.linkScript;
60      }
61  
62      /**
63       * The script to execute when a link is clicked (should probably use the "this" var in most cases, to determine
64       * page number selected - see retrieveStackedPage(linkElement, collectionId) js function)
65       *
66       * @return the script to execute when a link is clicked
67       */
68      @BeanTagAttribute
69      public String getLinkScript() {
70          return linkScript;
71      }
72  
73      /**
74       * Set the link js script
75       *
76       * @param linkScript the link js script
77       */
78      public void setLinkScript(String linkScript) {
79          this.linkScript = linkScript;
80      }
81  
82      /**
83       * Number of pages TOTAL that make up the component being paged (this must be set by the framework based on some
84       * list size)
85       *
86       * @return the number of pages used in this pager
87       */
88      public int getNumberOfPages() {
89          return numberOfPages;
90      }
91  
92      /**
93       * Set the TOTAL number of pages
94       *
95       * @param numberOfPages
96       */
97      public void setNumberOfPages(int numberOfPages) {
98          this.numberOfPages = numberOfPages;
99      }
100 
101     /**
102      * The current page being shown by this pager widget (this must be set when the page is changed)
103      *
104      * @return the current page being shown
105      */
106     public int getCurrentPage() {
107         return currentPage;
108     }
109 
110     /**
111      * Set the current page
112      *
113      * @param currentPage
114      */
115     public void setCurrentPage(int currentPage) {
116         this.currentPage = currentPage;
117     }
118 
119     /**
120      * The text to use on the previous link.
121      *
122      * @return the previous link text
123      */
124     @BeanTagAttribute
125     public String getPrevText() {
126         return prevText;
127     }
128 
129     /**
130      * @see Pager#getPrevText()
131      */
132     public void setPrevText(String prevText) {
133         this.prevText = prevText;
134     }
135 
136     /**
137      * The text to use on the next link.
138      *
139      * @return the next link text
140      */
141     @BeanTagAttribute
142     public String getNextText() {
143         return nextText;
144     }
145 
146     /**
147      * @see Pager#getNextText()
148      */
149     public void setNextText(String nextText) {
150         this.nextText = nextText;
151     }
152 }