KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > datapaginator > DataPaginator


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33 /* Original Copyright
34  * Copyright 2004 The Apache Software Foundation.
35  *
36  * Licensed under the Apache License, Version 2.0 (the "License");
37  * you may not use this file except in compliance with the License.
38  * You may obtain a copy of the License at
39  *
40  * http://www.apache.org/licenses/LICENSE-2.0
41  *
42  * Unless required by applicable law or agreed to in writing, software
43  * distributed under the License is distributed on an "AS IS" BASIS,
44  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45  * See the License for the specific language governing permissions and
46  * limitations under the License.
47  */

48 package com.icesoft.faces.component.datapaginator;
49
50 import com.icesoft.faces.component.CSS_DEFAULT;
51 import com.icesoft.faces.component.ext.taglib.Util;
52 import com.icesoft.faces.application.D2DViewHandler;
53 import org.apache.commons.logging.Log;
54 import org.apache.commons.logging.LogFactory;
55
56 import javax.faces.component.ActionSource;
57 import javax.faces.component.UIComponent;
58 import javax.faces.component.UIData;
59 import javax.faces.component.html.HtmlPanelGroup;
60 import javax.faces.context.FacesContext;
61 import javax.faces.el.EvaluationException;
62 import javax.faces.el.MethodBinding;
63 import javax.faces.el.ValueBinding;
64 import javax.faces.event.AbortProcessingException;
65 import javax.faces.event.ActionEvent;
66 import javax.faces.event.ActionListener;
67 import javax.faces.event.FacesEvent;
68 import javax.faces.event.PhaseId;
69 import java.sql.ResultSet JavaDoc;
70
71
72 /**
73  *
74  */

75 public class DataPaginator extends HtmlPanelGroup implements ActionSource {
76     private final Log log = LogFactory.getLog(DataPaginator.class);
77
78     private static final String JavaDoc FIRST_FACET_NAME = "first";
79     private static final String JavaDoc LAST_FACET_NAME = "last";
80     private static final String JavaDoc NEXT_FACET_NAME = "next";
81     private static final String JavaDoc PREVIOUS_FACET_NAME = "previous";
82     private static final String JavaDoc FAST_FORWARD_FACET_NAME = "fastforward";
83     private static final String JavaDoc FAST_REWIND_FACET_NAME = "fastrewind";
84
85     // just for caching the associated uidata
86
private transient UIData _UIData;
87
88     private MethodBinding _actionListener;
89     private Boolean JavaDoc disabled = null;
90
91     /**
92      * @return COMPONENT_TYPE
93      */

94     public String JavaDoc getComponentType() {
95         return COMPONENT_TYPE;
96     }
97
98     /**
99      * @return DEFAULT_RENDERER_TYPE
100      * @see javax.faces.component.UIComponent#getRendererType()
101      */

102     public String JavaDoc getRendererType() {
103         return DEFAULT_RENDERER_TYPE;
104     }
105
106     /**
107      * <p>Set the value of the <code>disabled</code> property.</p>
108      */

109     public void setDisabled(boolean disabled) {
110         this.disabled = new Boolean JavaDoc(disabled);
111         ValueBinding vb = getValueBinding("disabled");
112         if (vb != null) {
113             vb.setValue(getFacesContext(), this.disabled);
114             this.disabled = null;
115         }
116     }
117
118     /**
119      * <p>Return the value of the <code>disabled</code> property.</p>
120      */

121     public boolean isDisabled() {
122         if (!Util.isEnabledOnUserRole(this)) {
123             return true;
124         }
125         if (disabled != null) {
126             return disabled.booleanValue();
127         }
128         ValueBinding vb = getValueBinding("disabled");
129         Boolean JavaDoc v =
130                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
131         return v != null ? v.booleanValue() : false;
132     }
133
134     /**
135      * @see javax.faces.component.UIComponentBase#queueEvent(javax.faces.event.FacesEvent)
136      */

137     public void queueEvent(FacesEvent event) {
138         if (event != null && event instanceof ActionEvent) {
139             if (isImmediate()) {
140                 event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
141             } else {
142                 event.setPhaseId(PhaseId.INVOKE_APPLICATION);
143             }
144         }
145         super.queueEvent(event);
146     }
147
148     /**
149      * @see javax.faces.component.UIComponentBase#broadcast(javax.faces.event.FacesEvent)
150      */

151     public void broadcast(FacesEvent event) throws AbortProcessingException {
152         super.broadcast(event);
153
154         if (event instanceof PaginatorActionEvent) {
155             PaginatorActionEvent scrollerEvent = (PaginatorActionEvent) event;
156             broadcastToActionListener(scrollerEvent);
157             UIData uiData = getUIData();
158             if (uiData == null) {
159                 return;
160             }
161
162             int pageindex = scrollerEvent.getPageIndex();
163             if (pageindex == -1) {
164                 String JavaDoc facet = scrollerEvent.getScrollerfacet();
165                 if (FACET_FIRST.equals(facet)) {
166                     gotoFirstPage();
167                 } else if (FACET_PREVIOUS.equals(facet)) {
168                     gotoPreviousPage();
169                 } else if (FACET_NEXT.equals(facet)) {
170                     gotoNextPage();
171                 } else if (FACET_FAST_FORWARD.equals(facet)) {
172                     gotoFastForward();
173                 } else if (FACET_FAST_REWIND.equals(facet)) {
174                     gotoFastRewind();
175                 } else if (FACET_LAST.equals(facet)) {
176                     gotoLastPage();
177                 }
178             } else {
179                 int pageCount = getPageCount();
180                 if (pageindex > pageCount) {
181                     pageindex = pageCount;
182                 } else if (pageindex <= 0) {
183                     pageindex = 1;
184                 }
185                 uiData.setFirst(uiData.getRows() * (pageindex - 1));
186             }
187         }
188     }
189
190     protected void broadcastToActionListener(PaginatorActionEvent event) {
191         FacesContext context = getFacesContext();
192
193         try {
194             MethodBinding actionListenerBinding = getActionListener();
195             if (actionListenerBinding != null) {
196                 actionListenerBinding.invoke(context, new Object JavaDoc[]{event});
197             }
198             // super.broadcast(event) does this itself
199
//ActionListener[] actionListeners = getActionListeners();
200
//if(actionListeners != null) {
201
// for(int i = 0; i < actionListeners.length; i++) {
202
// actionListeners[i].processAction(event);
203
// }
204
//}
205
} catch (EvaluationException e) {
206             Throwable JavaDoc cause = e.getCause();
207             if (cause != null &&
208                 cause instanceof AbortProcessingException) {
209                 throw(AbortProcessingException) cause;
210             }
211             throw e;
212         }
213     }
214
215     /**
216      * <p>Return the instance of the <code>UIData</code> associated to this
217      * component.</p>
218      */

219     public UIData getUIData() {
220         if (_UIData == null) {
221             _UIData = findUIData();
222         }
223         return _UIData;
224     }
225
226     public void setUIData(UIData uiData) {
227         _UIData = uiData;
228     }
229
230
231     /**
232      * <p>Return the value of the <code>pageIndex</code> property.</p>
233      */

234     public int getPageIndex() {
235         UIData uiData = getUIData();
236         int rows = uiData.getRows();
237         int pageCount = getPageCount();
238         int pageIndex = 0;
239         if (rows > 0) {
240             pageIndex = uiData.getFirst() / rows + 1;
241             // if the page index > pageCount then some rows may have been removed
242
// so we need to show the last page which may be a partial or full page
243
// worth of data
244
if (pageIndex > pageCount) {
245                 pageIndex = pageCount;
246                 int rowCount = uiData.getRowCount();
247                 int countOfRecordsOnFinalPage = rowCount % rows;
248                 if (countOfRecordsOnFinalPage == 0) {
249                     // full page of data
250
if (rowCount - rows >= 0) {
251                         uiData.setFirst(rowCount - rows);
252                     } else {
253                         uiData.setFirst(0);
254                     }
255                 } else {
256                     // partial page of data
257
uiData.setFirst(rowCount - countOfRecordsOnFinalPage);
258                 }
259             }
260         } else {
261             log.warn("DataTable " +
262                      uiData.getClientId(FacesContext.getCurrentInstance())
263                      + " has invalid rows attribute.");
264             pageIndex = 0;
265         }
266
267         if (uiData.getFirst() % rows > 0) {
268             pageIndex++;
269         }
270         return pageIndex;
271     }
272
273     /**
274      * <p>Return the value of the <code>pageCount</code> property.</p>
275      */

276     public int getPageCount() {
277         UIData uiData = getUIData();
278         int rows = uiData.getRows();
279
280         int pageCount;
281         if (rows > 0) {
282             pageCount = rows <= 0 ? 1 : uiData.getRowCount() / rows;
283             if (uiData.getRowCount() % rows > 0) {
284                 pageCount++;
285             }
286         } else {
287             rows = 1;
288             pageCount = 1;
289         }
290         return pageCount;
291     }
292
293     /**
294      * <p>Return the value of the <code>rowCount</code> property.</p>
295      */

296     public int getRowCount() {
297         return getUIData().getRowCount();
298     }
299
300     /**
301      * <p>Return the value of the <code>rows</code> property.</p>
302      */

303     public int getRows() {
304         return getUIData().getRows();
305     }
306
307     /**
308      * <p>Return the value of the <code>first</code> property.</p>
309      */

310     public int getFirstRow() {
311         return getUIData().getFirst();
312     }
313
314     /**
315      * <p>Return the instance of <code>UIData</code> associated to this
316      * component.</p>
317      */

318     protected UIData findUIData() {
319         String JavaDoc forStr = getFor();
320         UIComponent forComp;
321         if (forStr == null) {
322             // DataPaginator may be a child of uiData
323
forComp = getParent();
324         } else {
325
326             //forComp = findComponent(forStr);
327

328             forComp = D2DViewHandler.findComponent(forStr, this);
329         }
330         if (forComp == null) {
331             throw new IllegalArgumentException JavaDoc(
332                     "could not find UIData referenced by attribute dataScroller@for = '"
333                     + forStr + "'");
334         } else if (!(forComp instanceof UIData)) {
335             throw new IllegalArgumentException JavaDoc(
336                     "uiComponent referenced by attribute dataScroller@for = '" +
337                     forStr + "' must be of type "
338                     + UIData.class.getName() + ", not type " +
339                     forComp.getClass().getName());
340         }
341         return (UIData) forComp;
342     }
343
344     /**
345      * <p>Set the value of the <code>first</code> facet for this component.</p>
346      */

347     public void setFirst(UIComponent first) {
348         getFacets().put(FIRST_FACET_NAME, first);
349     }
350
351     /**
352      * <p>Return the value of the <code>first</code> facet of this
353      * component.</p>
354      */

355     public UIComponent getFirst() {
356         return (UIComponent) getFacets().get(FIRST_FACET_NAME);
357     }
358
359     /**
360      * <p>Set the value of the <code>last</code> facet for this component.</p>
361      */

362     public void setLast(UIComponent last) {
363         getFacets().put(LAST_FACET_NAME, last);
364     }
365
366     /**
367      * <p>Return the value of the <code>last</code> facet of this
368      * component.</p>
369      */

370     public UIComponent getLast() {
371         return (UIComponent) getFacets().get(LAST_FACET_NAME);
372     }
373
374     /**
375      * <p>Set the value of the <code>next</code> facet for this component.</p>
376      */

377     public void setNext(UIComponent next) {
378         getFacets().put(NEXT_FACET_NAME, next);
379     }
380
381     /**
382      * <p>Return the value of the <code>next</code> facet of this
383      * component.</p>
384      */

385     public UIComponent getNext() {
386         return (UIComponent) getFacets().get(NEXT_FACET_NAME);
387     }
388
389     /**
390      * <p>Set the value of the <code>fast forward</code> facet for this
391      * component.</p>
392      */

393     public void setFastForward(UIComponent previous) {
394         getFacets().put(FAST_FORWARD_FACET_NAME, previous);
395     }
396
397     /**
398      * <p>Return the value of the <code>fast forward</code> facet of this
399      * component.</p>
400      */

401     public UIComponent getFastForward() {
402         return (UIComponent) getFacets().get(FAST_FORWARD_FACET_NAME);
403     }
404
405     /**
406      * <p>Set the value of the <code>fast rewind</code> facet for this
407      * component.</p>
408      */

409     public void setFastRewind(UIComponent previous) {
410         getFacets().put(FAST_REWIND_FACET_NAME, previous);
411     }
412
413     /**
414      * <p>Return the value of the <code>fast rewind</code> facet of this
415      * component.</p>
416      */

417     public UIComponent getFastRewind() {
418         return (UIComponent) getFacets().get(FAST_REWIND_FACET_NAME);
419     }
420
421     /**
422      * <p>Set the value of the <code>previous</code> facet for this
423      * component.</p>
424      */

425     public void setPrevious(UIComponent previous) {
426         getFacets().put(PREVIOUS_FACET_NAME, previous);
427     }
428
429     /**
430      * <p>Return the value of the <code>previous</code> facet of this
431      * component.</p>
432      */

433     public UIComponent getPrevious() {
434         return (UIComponent) getFacets().get(PREVIOUS_FACET_NAME);
435     }
436
437     /**
438      * <p>Return a flag indicating whether this component is responsible for
439      * rendering its child components.</p>
440      */

441     public boolean getRendersChildren() {
442         return true;
443     }
444
445     /**
446      * @see javax.faces.component.ActionSource#getAction()
447      */

448     public MethodBinding getAction() {
449         // not used
450
return null;
451     }
452
453     /**
454      * @see javax.faces.component.ActionSource#setAction(javax.faces.el.MethodBinding)
455      */

456     public void setAction(MethodBinding action) {
457         throw new UnsupportedOperationException JavaDoc(
458                 "Defining an action is not supported. Use an actionListener");
459     }
460
461     /**
462      * @see javax.faces.component.ActionSource#setActionListener(javax.faces.el.MethodBinding)
463      */

464     public void setActionListener(MethodBinding actionListener) {
465         _actionListener = actionListener;
466     }
467
468     /**
469      * @see javax.faces.component.ActionSource#getActionListener()
470      */

471     public MethodBinding getActionListener() {
472         return _actionListener;
473     }
474
475     /**
476      * @see javax.faces.component.ActionSource#addActionListener(javax.faces.event.ActionListener)
477      */

478     public void addActionListener(ActionListener listener) {
479         addFacesListener(listener);
480     }
481
482     /**
483      * @see javax.faces.component.ActionSource#getActionListeners()
484      */

485     public ActionListener[] getActionListeners() {
486         return (ActionListener[]) getFacesListeners(ActionListener.class);
487     }
488
489     /**
490      * @see javax.faces.component.ActionSource#removeActionListener(javax.faces.event.ActionListener)
491      */

492     public void removeActionListener(ActionListener listener) {
493         removeFacesListener(listener);
494     }
495
496     public static final String JavaDoc COMPONENT_TYPE =
497             "com.icesoft.faces.DataScroller";
498     public static final String JavaDoc COMPONENT_FAMILY = "javax.faces.Panel";
499     private static final String JavaDoc DEFAULT_RENDERER_TYPE =
500             "com.icesoft.faces.DataScroller";
501     private static final boolean DEFAULT_IMMEDIATE = false;
502     private static final boolean DEFAULT_VERTICAL = false;
503     private String JavaDoc _for = null;
504     private Integer JavaDoc _fastStep = null;
505     private String JavaDoc _pageIndexVar = null;
506     private String JavaDoc _pageCountVar = null;
507     private String JavaDoc _rowsCountVar = null;
508     private String JavaDoc _displayedRowsCountVar = null;
509     private String JavaDoc _firstRowIndexVar = null;
510     private String JavaDoc _lastRowIndexVar = null;
511     private String JavaDoc _style = null;
512     private String JavaDoc _styleClass = null;
513     private String JavaDoc _columnClasses = null;
514     private Boolean JavaDoc _paginator = null;
515     private Integer JavaDoc _paginatorMaxPages = null;
516     private Boolean JavaDoc _renderFacetsIfSinglePage = null;
517     private Boolean JavaDoc _immediate;
518     private Boolean JavaDoc _vertical;
519     public static final String JavaDoc FACET_FIRST = "first".intern();
520     public static final String JavaDoc FACET_PREVIOUS = "previous".intern();
521     public static final String JavaDoc FACET_NEXT = "next".intern();
522     public static final String JavaDoc FACET_LAST = "last".intern();
523     public static final String JavaDoc FACET_FAST_FORWARD = "fastf".intern();
524     public static final String JavaDoc FACET_FAST_REWIND = "fastr".intern();
525
526     public DataPaginator() {
527         setRendererType(DEFAULT_RENDERER_TYPE);
528     }
529
530     /* (non-Javadoc)
531       * @see javax.faces.component.UIComponent#getFamily()
532       */

533     public String JavaDoc getFamily() {
534         return COMPONENT_FAMILY;
535     }
536
537     /**
538      * <p>Set the value of the <code>for</code> property.</p>
539      */

540     public void setFor(String JavaDoc forValue) {
541         _for = forValue;
542     }
543
544     /**
545      * <p>Return the value of the <code>for</code> property.</p>
546      */

547     public String JavaDoc getFor() {
548         if (_for != null) {
549             return _for;
550         }
551         ValueBinding vb = getValueBinding("for");
552         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
553     }
554
555     /**
556      * <p>Set the value of the <code>fastStep</code> property.</p>
557      */

558     public void setFastStep(int fastStep) {
559         _fastStep = new Integer JavaDoc(fastStep);
560     }
561
562     /**
563      * <p>Return the value of the <code>fastStep</code> property.</p>
564      */

565     public int getFastStep() {
566         if (_fastStep != null) {
567             return _fastStep.intValue();
568         }
569         ValueBinding vb = getValueBinding("fastStep");
570         Integer JavaDoc v =
571                 vb != null ? (Integer JavaDoc) vb.getValue(getFacesContext()) : null;
572         return v != null ? v.intValue() : Integer.MIN_VALUE;
573     }
574
575     /**
576      * <p>Set the value of the <code>pageIndexVar</code> property.</p>
577      */

578     public void setPageIndexVar(String JavaDoc pageIndexVar) {
579         _pageIndexVar = pageIndexVar;
580     }
581
582     /**
583      * <p>Return the value of the <code>pageIndexVar</code> property.</p>
584      */

585     public String JavaDoc getPageIndexVar() {
586         if (_pageIndexVar != null) {
587             return _pageIndexVar;
588         }
589         ValueBinding vb = getValueBinding("pageIndexVar");
590         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
591     }
592
593     /**
594      * <p>Set the value of the <code>pageCountVar</code> property.</p>
595      */

596     public void setPageCountVar(String JavaDoc pageCountVar) {
597         _pageCountVar = pageCountVar;
598     }
599
600     /**
601      * <p>Return the value of the <code>pageCountVar</code> property.</p>
602      */

603     public String JavaDoc getPageCountVar() {
604         if (_pageCountVar != null) {
605             return _pageCountVar;
606         }
607         ValueBinding vb = getValueBinding("pageCountVar");
608         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
609     }
610
611     /**
612      * <p>Set the value of the <code>rowsCountVar</code> property.</p>
613      */

614     public void setRowsCountVar(String JavaDoc rowsCountVar) {
615         _rowsCountVar = rowsCountVar;
616     }
617
618     /**
619      * <p>Return the value of the <code>rowsCountVar</code> property.</p>
620      */

621     public String JavaDoc getRowsCountVar() {
622         if (_rowsCountVar != null) {
623             return _rowsCountVar;
624         }
625         ValueBinding vb = getValueBinding("rowsCountVar");
626         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
627     }
628
629     /**
630      * <p>Set the value of the <code>displayedRowsCountVar</code> property.</p>
631      */

632     public void setDisplayedRowsCountVar(String JavaDoc displayedRowsCountVar) {
633         _displayedRowsCountVar = displayedRowsCountVar;
634     }
635
636     /**
637      * <p>Return the value of the <code>displayedRowsCountVar</code>
638      * property.</p>
639      */

640     public String JavaDoc getDisplayedRowsCountVar() {
641         if (_displayedRowsCountVar != null) {
642             return _displayedRowsCountVar;
643         }
644         ValueBinding vb = getValueBinding("displayedRowsCountVar");
645         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
646     }
647
648     /**
649      * <p>Set the value of the <code>firstRowIndexVar</code> property.</p>
650      */

651     public void setFirstRowIndexVar(String JavaDoc firstRowIndexVar) {
652         _firstRowIndexVar = firstRowIndexVar;
653     }
654
655     /**
656      * <p>Return the value of the <code>firstRowIndexVar</code> property.</p>
657      */

658     public String JavaDoc getFirstRowIndexVar() {
659         if (_firstRowIndexVar != null) {
660             return _firstRowIndexVar;
661         }
662         ValueBinding vb = getValueBinding("firstRowIndexVar");
663         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
664     }
665
666     /**
667      * <p>Set the value of the <code>lastRowIndexVar</code> property.</p>
668      */

669     public void setLastRowIndexVar(String JavaDoc lastRowIndexVar) {
670         _lastRowIndexVar = lastRowIndexVar;
671     }
672
673     /**
674      * <p>Return the value of the <code>lastRowIndexVar</code> property.</p>
675      */

676     public String JavaDoc getLastRowIndexVar() {
677         if (_lastRowIndexVar != null) {
678             return _lastRowIndexVar;
679         }
680         ValueBinding vb = getValueBinding("lastRowIndexVar");
681         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
682     }
683
684     /**
685      * <p>Set the value of the <code>style</code> property.</p>
686      */

687     public void setStyle(String JavaDoc style) {
688         _style = style;
689     }
690
691
692     /**
693      * <p>Return the value of the <code>style</code> property.</p>
694      */

695     public String JavaDoc getStyle() {
696         if (_style != null) {
697             return _style;
698         }
699         ValueBinding vb = getValueBinding("style");
700         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
701     }
702
703     /**
704      * <p>Set the value of the <code>styleClass</code> property.</p>
705      */

706     public void setStyleClass(String JavaDoc styleClass) {
707         _styleClass = styleClass;
708     }
709
710     /**
711      * <p>Return the value of the <code>styleClass</code> property.</p>
712      */

713     public String JavaDoc getStyleClass() {
714         return Util.getQualifiedStyleClass(this,
715                                     _styleClass,
716                                     CSS_DEFAULT.DATA_PAGINATOR_BASE,
717                                     "styleClass",
718                                     isDisabled());
719     }
720
721     public String JavaDoc getBaseStyleClass() {
722         return CSS_DEFAULT.DATA_PAGINATOR_BASE;
723     }
724
725     /**
726      * <p>Set the value of the <code>paginator</code> property.</p>
727      */

728     public void setPaginator(boolean paginator) {
729         _paginator = Boolean.valueOf(paginator);
730     }
731
732     /**
733      * <p>Return the value of the <code>paginator</code> property.</p>
734      */

735     public boolean isPaginator() {
736         if (_paginator != null) {
737             return _paginator.booleanValue();
738         }
739         ValueBinding vb = getValueBinding("paginator");
740         Boolean JavaDoc v =
741                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
742         return v != null ? v.booleanValue() : false;
743     }
744
745     /**
746      * <p>Set the value of the <code>paginatorMaxPages</code> property.</p>
747      */

748     public void setPaginatorMaxPages(int paginatorMaxPages) {
749         _paginatorMaxPages = new Integer JavaDoc(paginatorMaxPages);
750     }
751
752     /**
753      * <p>Return the value of the <code>paginatorMaxPages</code> property.</p>
754      */

755     public int getPaginatorMaxPages() {
756         if (_paginatorMaxPages != null) {
757             return _paginatorMaxPages.intValue();
758         }
759         ValueBinding vb = getValueBinding("paginatorMaxPages");
760         Integer JavaDoc v =
761                 vb != null ? (Integer JavaDoc) vb.getValue(getFacesContext()) : null;
762         return v != null ? v.intValue() : Integer.MIN_VALUE;
763     }
764
765
766     /**
767      * <p>Return the value of the <code>paginatorTableClass</code>
768      * property.</p>
769      */

770     public String JavaDoc getPaginatorTableClass() {
771         return Util.getQualifiedStyleClass(this,CSS_DEFAULT.PAGINATOR_TABLE_CLASS, isDisabled());
772
773     }
774
775     /**
776      * <p>Return the value of the <code>paginatorColumnClass</code>
777      * property.</p>
778      */

779     public String JavaDoc getPaginatorColumnClass() {
780         return Util.getQualifiedStyleClass(this,CSS_DEFAULT.PAGINATOR_COLUMN_CLASS, isDisabled());
781     }
782
783     /**
784      * <p>Return the value of the <code>scrollButtonCellClass</code>
785      * property.</p>
786      */

787     public String JavaDoc getscrollButtonCellClass() {
788         return Util.getQualifiedStyleClass(this,CSS_DEFAULT.DATA_PAGINATOR_SCROLL_BUTTON_CELL_CLASS, isDisabled());
789     }
790
791
792     /**
793      * <p>Return the value of the <code>paginatorActiveColumnClass</code>
794      * property.</p>
795      */

796     public String JavaDoc getPaginatorActiveColumnClass() {
797         return Util.getQualifiedStyleClass(this, CSS_DEFAULT.PAGINATOR_ACTIVE_COLUMN_CLASS, isDisabled());
798     }
799
800     /**
801      * <p>Set the value of the <code>renderFacetsIfSinglePage</code>
802      * property.</p>
803      */

804     public void setRenderFacetsIfSinglePage(boolean renderFacetsIfSinglePage) {
805         _renderFacetsIfSinglePage = Boolean.valueOf(renderFacetsIfSinglePage);
806     }
807
808     /**
809      * <p>Return the value of the <code>renderFacetsIfSinglePage</code>
810      * property.</p>
811      */

812     public boolean isRenderFacetsIfSinglePage() {
813         if (_renderFacetsIfSinglePage != null) {
814             return _renderFacetsIfSinglePage.booleanValue();
815         }
816         ValueBinding vb = getValueBinding("renderFacetsIfSinglePage");
817         Boolean JavaDoc v =
818                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
819         return v != null ? v.booleanValue() : true;
820     }
821
822     /**
823      * <p>Set the value of the <code>immediate</code> property.</p>
824      */

825     public void setImmediate(boolean immediate) {
826         _immediate = Boolean.valueOf(immediate);
827     }
828
829     /**
830      * <p>Return the value of the <code>immediate</code> property.</p>
831      */

832     public boolean isImmediate() {
833         if (_immediate != null) {
834             return _immediate.booleanValue();
835         }
836         ValueBinding vb = getValueBinding("immediate");
837         Boolean JavaDoc v =
838                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
839         return v != null ? v.booleanValue() : DEFAULT_IMMEDIATE;
840     }
841
842     /**
843      * <p>Set the value of the <code>vertical</code> property.</p>
844      */

845     public void setVertical(boolean vertical) {
846         _vertical = Boolean.valueOf(vertical);
847     }
848
849     /**
850      * <p>Return the value of the <code>vertical</code> property.</p>
851      */

852     public boolean isVertical() {
853         if (_vertical != null) {
854             return _vertical.booleanValue();
855         }
856         ValueBinding vb = getValueBinding("vertical");
857         Boolean JavaDoc v =
858                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
859         return v != null ? v.booleanValue() : DEFAULT_VERTICAL;
860     }
861
862     /**
863      * <p>Return the value of the <code>rendered</code> property.</p>
864      */

865     public boolean isRendered() {
866         if (!Util.isRenderedOnUserRole(this)) {
867             return false;
868         }
869         return super.isRendered();
870     }
871
872     /**
873      * <p>Gets the state of the instance as a <code>Serializable</code>
874      * Object.</p>
875      */

876     public Object JavaDoc saveState(FacesContext context) {
877         Object JavaDoc values[] = new Object JavaDoc[18];
878         values[0] = super.saveState(context);
879         values[1] = _for;
880         values[2] = _fastStep;
881         values[3] = _pageIndexVar;
882         values[4] = _pageCountVar;
883         values[5] = _rowsCountVar;
884         values[6] = _displayedRowsCountVar;
885         values[7] = _firstRowIndexVar;
886         values[8] = _lastRowIndexVar;
887         values[9] = _style;
888         values[10] = _styleClass;
889         values[11] = _columnClasses;
890         values[12] = _paginator;
891         values[13] = _paginatorMaxPages;
892         values[14] = _renderFacetsIfSinglePage;
893         values[15] = _immediate;
894         values[16] = saveAttachedState(context, _actionListener);
895         values[17] = _vertical;
896         return values;
897     }
898
899     /**
900      * <p>Perform any processing required to restore the state from the entries
901      * in the state Object.</p>
902      */

903     public void restoreState(FacesContext context, Object JavaDoc state) {
904         Object JavaDoc values[] = (Object JavaDoc[]) state;
905         super.restoreState(context, values[0]);
906         _for = (String JavaDoc) values[1];
907         _fastStep = (Integer JavaDoc) values[2];
908         _pageIndexVar = (String JavaDoc) values[3];
909         _pageCountVar = (String JavaDoc) values[4];
910         _rowsCountVar = (String JavaDoc) values[5];
911         _displayedRowsCountVar = (String JavaDoc) values[6];
912         _firstRowIndexVar = (String JavaDoc) values[7];
913         _lastRowIndexVar = (String JavaDoc) values[8];
914         _style = (String JavaDoc) values[9];
915         _styleClass = (String JavaDoc) values[10];
916         _columnClasses = (String JavaDoc) values[11];
917         _paginator = (Boolean JavaDoc) values[12];
918         _paginatorMaxPages = (Integer JavaDoc) values[13];
919         _renderFacetsIfSinglePage = (Boolean JavaDoc) values[14];
920         _immediate = (Boolean JavaDoc) values[15];
921         _actionListener =
922                 (MethodBinding) restoreAttachedState(context, values[16]);
923         _vertical = (Boolean JavaDoc) values[17];
924     }
925
926     /**
927      * Sets the dataPaginator to the first page
928      */

929     public void gotoFirstPage() {
930         getUIData().setFirst(0);
931     }
932
933     /**
934      * Sets the dataPaginator to the previous page
935      */

936     public void gotoPreviousPage() {
937         if (isModelResultSet()) {
938             int first = getUIData().getFirst() - getUIData().getRows();
939             if (first < 0) {
940                 first = 0;
941             }
942             getUIData().setFirst(first);
943         } else {
944             int previous = getUIData().getFirst() - getUIData().getRows();
945             int rowCount = getRowCount();
946             if (previous >= 0) {
947                 if (previous > rowCount) {
948                     previous = rowCount;
949                 }
950                 getUIData().setFirst(previous);
951             }
952         }
953     }
954
955     /**
956      * Sets the dataPaginator to the next page
957      */

958     public void gotoNextPage() {
959         int next = getUIData().getFirst() + getUIData().getRows();
960         if (isModelResultSet()) {
961             getUIData().setRowIndex(next);
962             if (getUIData().isRowAvailable()) {
963                 getUIData().setFirst(next);
964             }
965         } else {
966             if (next < getUIData().getRowCount()) {
967                 getUIData().setFirst(next);
968             }
969         }
970     }
971
972     /**
973      * Sets the dataPaginator to the (n) number of pages forward, defined by the
974      * fastStep property
975      */

976     public void gotoFastForward() {
977         int fastStep = getFastStep();
978         if (fastStep <= 0) {
979             fastStep = 1;
980         }
981         int next = getUIData().getFirst() + getUIData().getRows() * fastStep;
982         int rowcount = getUIData().getRowCount();
983         if (next >= rowcount) {
984             next = (rowcount - 1) - ((rowcount - 1) % getUIData().getRows());
985         }
986         getUIData().setFirst(next);
987     }
988
989     /**
990      * Sets the dataPaginator to the (n) number of pages back, defined by the
991      * fastStep property
992      */

993     public void gotoFastRewind() {
994         int fastStep = getFastStep();
995         if (fastStep <= 0) {
996             fastStep = 1;
997         }
998         int previous =
999                 getUIData().getFirst() - getUIData().getRows() * fastStep;
1000        if (previous < 0) {
1001            previous = 0;
1002        }
1003        getUIData().setFirst(previous);
1004    }
1005
1006    /**
1007     * Sets the dataPaginator to the last page
1008     */

1009    public void gotoLastPage() {
1010        if (isModelResultSet()) {
1011            int first = getUIData().getFirst();
1012            while (true) {
1013                getUIData().setRowIndex(first + 1);
1014                if (getUIData().isRowAvailable()) {
1015                    first++;
1016                } else {
1017                    break;
1018                }
1019            }
1020            getUIData().setFirst(first - (first % getUIData().getRows()));
1021        } else {
1022            int rowcount = getUIData().getRowCount();
1023            int rows = getUIData().getRows();
1024            int delta = rowcount % rows;
1025            int first = delta > 0 && delta < rows ? rowcount - delta :
1026                        rowcount - rows;
1027            if (first >= 0) {
1028                getUIData().setFirst(first);
1029            } else {
1030                getUIData().setFirst(0);
1031            }
1032        }
1033    }
1034
1035    /**
1036     * Return a boolean value, whether current page is the last page
1037     */

1038    public boolean isLastPage() {
1039        return (getPageIndex() >= getPageCount()) ? true : false;
1040    }
1041
1042    private String JavaDoc enabledOnUserRole = null;
1043    private String JavaDoc renderedOnUserRole = null;
1044
1045    /**
1046     * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
1047     */

1048    public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole) {
1049        this.enabledOnUserRole = enabledOnUserRole;
1050    }
1051
1052    /**
1053     * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
1054     */

1055    public String JavaDoc getEnabledOnUserRole() {
1056        if (enabledOnUserRole != null) {
1057            return enabledOnUserRole;
1058        }
1059        ValueBinding vb = getValueBinding("enabledOnUserRole");
1060        return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
1061    }
1062
1063    /**
1064     * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
1065     */

1066    public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
1067        this.renderedOnUserRole = renderedOnUserRole;
1068    }
1069
1070    /**
1071     * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
1072     */

1073    public String JavaDoc getRenderedOnUserRole() {
1074        if (renderedOnUserRole != null) {
1075            return renderedOnUserRole;
1076        }
1077        ValueBinding vb = getValueBinding("renderedOnUserRole");
1078        return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
1079    }
1080
1081    private Boolean JavaDoc modelResultSet = null;
1082
1083    public boolean isModelResultSet() {
1084
1085        if (modelResultSet == null) {
1086            if (getUIData().getValue() instanceof ResultSet JavaDoc) {
1087                modelResultSet = Boolean.TRUE;
1088            } else {
1089                if (getUIData()
1090                        .getValue() instanceof javax.faces.model.DataModel) {
1091                    javax.faces.model.DataModel dataModel =
1092                            (javax.faces.model.DataModel) getUIData()
1093                                    .getValue();
1094                    if (dataModel.getRowCount() == -1) {
1095                        modelResultSet = Boolean.TRUE;
1096                        return modelResultSet.booleanValue();
1097                    }
1098                }
1099                modelResultSet = Boolean.FALSE;
1100            }
1101        }
1102        return modelResultSet.booleanValue();
1103    }
1104}
1105
Popular Tags