KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > listdata > data > ListOptions


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ListOptions.java,v 1.23 2007/02/20 04:13:43 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.patterns.listdata.data;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.opensubsystems.core.data.DataConstant;
29 import org.opensubsystems.core.data.DataObject;
30 import org.opensubsystems.core.util.GlobalConstants;
31
32 /**
33  * This class collects various attributes describing list of data objects to
34  * load. It allows to specify what attributes of the data objects to load, what
35  * should be the order of data elements, etc. It also provides some placeholders
36  * for informations used by GUI to display this list that are not necessary used
37  * to load the list, but they needs to be propagated when the list is reloaded
38  * or to describe the initial status of the list.
39  *
40  * @version $Id: ListOptions.java,v 1.23 2007/02/20 04:13:43 bastafidli Exp $
41  * @author Julo Legeny
42  * @code.reviewer Miro Halas
43  * @code.reviewed 1.15 2006/03/14 23:55:38 jlegeny
44  */

45 public class ListOptions implements Serializable JavaDoc
46 {
47    // Constants ////////////////////////////////////////////////////////////////
48

49    /**
50     * Use this constant when you want to load all items.
51     * TODO: Improve: Change this to MAX_INT value so that we can distinguish
52     * when we really want all and when we just forgot to initialize variable.
53     */

54    public static final int PAGE_SIZE_ALL = 0;
55    
56    // Attributes ///////////////////////////////////////////////////////////////
57

58    /**
59     * Generated serial version UID.
60     */

61    private static final long serialVersionUID = 2460394574604943241L;
62
63    /**
64     * Class representing data factory that implements list factory interface to
65     * use to retrieve data for list of data objects
66     * TODO: Improve: Since this class is used at many levels it doesn't make much
67     * sense to specify data factory to use. It would make more sense to specify
68     * data object which should be result in this list and then from there internally
69     * determine what is the factory.
70     */

71    protected Class JavaDoc m_listFactoryClass;
72
73    /**
74     * String representation of a list definition which should be used to load
75     * the list of data objects. This can be string representation of an ID of a
76     * ListDefinition if the list definition should be loaded from a persistence
77     * store or a DataObject.NEW_ID if no list definition is specified. The other
78     * option is that this value can be a string representation of the entire list
79     * definition, which is then read and parsed from this variable.
80     */

81    protected String JavaDoc m_strDefinitionId;
82    
83    /**
84     * Code of the columns to order by, for each column at the same index is in
85     * m_bOrderDirections setup the direction of ordering.
86     */

87    protected int[] m_arrOrderColumnCodes;
88
89    /**
90     * Direction of the ordering ASC/DESC. See ORDER_XXX constants
91     * in the ListDefinition. The constant coresponds to the column code in
92     * m_iOrderColumnsCodes.
93     */

94    protected String JavaDoc[] m_arrOrderDirections;
95
96    /**
97     * Number of items per page defines how many items are loaded at once.
98     */

99    protected int m_iPageSize;
100
101    /**
102     * Position of the first requested/loaded item in list.
103     */

104    protected int m_iBeginPosition;
105
106    /**
107     * Position of the last requested/loaded item in list.
108     */

109    protected int m_iEndPosition;
110
111    /**
112     * 1 based actual page number, e.g 1st page of 10 pages.
113     */

114    protected int m_iActualPage;
115
116    /**
117     * Number of all items in the requested list regardless if only portion of
118     * the list is requested or sent. This is sent only from backend to GUI.
119     */

120    protected int m_iActualListSize;
121    
122    /**
123     * String of comma separated selected item IDs from the list. This is used by
124     * GUI to remember, which IDs were selected so if the reloaded list contains
125     * the same IDs it can select them again
126     */

127    protected String JavaDoc m_strSelectedItemIDs;
128
129    /**
130     * String of comma separated marked item IDs from the list. This is used by
131     * GUI to remember, which IDs were highlighted or otherwise flagged so if the
132     * reloaded list contains the same IDs it can select them again.
133     */

134    protected String JavaDoc m_strMarkedItemIDs;
135
136    /**
137     * Identification of first visible item on the GUI. This can be anything,
138     * pixels to scroll, index of the first element, it depends on how the GUI
139     * is constructed.
140     */

141    protected int m_iFirstVisibleItem;
142
143    /**
144     * Code of the client column to order the list by on the client. This
145     * provides the ability to sort the entire list on the server using some
146     * column and then on the client sort the page using different column
147     */

148    protected int m_iClientOrderCode;
149
150    /**
151     * Type of the client ordering ASC/DESC. See ORDER_XXX constants in ListDefinition.
152     */

153    protected String JavaDoc m_strClientOrderDirection;
154
155    /**
156     * Basic definition used for this list. All other attributes may override data
157     * in this definition.
158     */

159    protected ListDefinition m_definition;
160    
161    /**
162     * List of columns codes representing data object attributes, which are shown
163     * in the list in GUI.
164     * This is not necessary the list of fields which will be retrieved from
165     * the database since some fields such as IDs of the objects are never shown
166     * on the GUI but they are still needed to construct the page.
167     */

168    protected int[] m_arrShowColumnCodes;
169    
170    /**
171     * List of columns codes representing data object attributes, which are
172     * retrieved from the database.
173     * It is a superset of m_arrShowColumnCodes;
174     */

175    protected int[] m_arrRetrieveColumnCodes;
176
177    /**
178     * List of columns codes which could be used to sort data by the
179     * persistance store. This is needed due to the fact that some databases
180     * (e.g. SAPDB) doesn't allow columns of certain data types (long VARCHAR) to
181     * be used in ORDER BY clause.
182     *
183     * This is variable is set by the persistance layer layer when the data
184     * structure is passed to it during data retrieval. If the data structure is
185     * not passed through database layer that it is not known which columns can
186     * be used for sorting or not and this value will be null. At then it is up
187     * to the caller to decide how does it wants to deal with this situation (if
188     * to assume that all columns are sortable or be conservative and assume none
189     * are).
190     */

191    protected int[] m_arrSortableColumnCodes;
192    
193    /**
194     * List of columns codes which could be used to filter data by the
195     * persistance store.
196     *
197     * This is variable is set by the persistance layer layer when the data
198     * structure is passed to it during data retrieval. If the data structure is
199     * not passed through database layer that it is not known which columns can
200     * be used for filtering or not and this value will be null. At then it is up
201     * to the caller to decide how does it wants to deal with this situation (if
202     * to assume that all columns are filterable or be conservative and assume
203     * none are).
204     */

205    protected int[] m_arrFilterableColumnCodes;
206    
207    /**
208     * Data type of parent object of the list of data. This can be used for
209     * example when all data objects displayed in the list should belong to the
210     * same parent.
211     */

212    protected int m_iParentDataType;
213    
214    /**
215     * ID of parent object of the list of data. This can be used for
216     * example when all data objects displayed in the list should belong to the
217     * same parent.
218     */

219    protected int m_iParentId;
220    
221    /**
222     * Comma separated list of IDs of items which should not be loaded even
223     * though they satisfy filter, extra and security conditions.
224     */

225    protected String JavaDoc m_strIgnoredItemIDs;
226
227    /**
228     * Filter defining what data has user rights to access. This prevents us from
229     * loading data, which user cannot see.
230     */

231    protected SimpleRule m_securityFilter;
232
233    /**
234     * Filter specifying extra conditions which data has to satisfy. It is
235     * combined with the data conditions specified by list definition and with
236     * security filter.
237     */

238    protected SimpleRule m_extraFilter;
239    
240    /**
241     * Logical operation used to merge extra filter with the ones from list
242     * definition. The security is alwasy merged in such a way that it has to be
243     * satisfied. This can be one of SimpleRule..LOGICAL_XXX constants.
244     */

245    protected int m_iExtraLogicalOperation;
246    
247    /**
248     * Load only distinct items. Use (true) this very carefully since it will
249     * cause sorting and it will slow down the query.
250     */

251    protected boolean m_bDistinct;
252
253    /**
254     * Load also previously selected items even if they are not in the current
255     * range of items to load. Depends on 'Keep selected' checkbox in the
256     * scrollable table footer.
257     */

258    protected boolean m_bKeepSelected;
259
260    /**
261     * Domain ID that will be used for constructing query for getting object list.
262     * This gives us possibility to retrieve list of objects not only from current
263     * domain but also from other domain (e.g. for administering another domains).
264     */

265    protected int m_iDomainId;
266
267    // Constructors /////////////////////////////////////////////////////////////
268

269    /**
270     * Empty list options initialized to default parameters
271     * @param listFactoryClass - class representing data factory that implements
272     * list factory interface to use to retrieve data
273     * for list of data objects
274     */

275    public ListOptions(
276       Class JavaDoc listFactoryClass
277    )
278    {
279       this(listFactoryClass, DataObject.NEW_ID_STR,
280            -1 /* Page size has to be negative to initialize it to one from filter */,
281            0, null, null, 0, ListDefinition.ORDER_ASCENDING, 0, 0, 0, 0,
282            DataConstant.NO_DATA_TYPE, DataObject.NEW_ID, null, null, null,
283            null, false, false, DataObject.NEW_ID);
284    }
285    
286    /**
287     * @param listFactoryClass - class representing data factory that implements
288     * list factory interface to use to retrieve data
289     * for list of data objects
290     * @param strDefinitionId - string id of definition used as a basis for this list
291     * This ID can be pure numeric value (id) or there can be
292     * stored whole Filter object values that have to be parsed.
293     * These filter values are used when Filter GUI values have
294     * to be applied.
295     * @param iPageSize - page size
296     * @param iActualListSize - number of all items in list
297     * @param arrOrderColumnCodes - codes for columns to order by, pass null if none
298     * @param arrOrderDirections - order directions (ASC/DESC), see constants in ListDefinition
299     * @param iClientOrderCode - client order column code
300     * @param strClientOrderDirection - client order type (ASC/DESC), see constants
301     * in ListDefinition
302     * @param iBeginPosition - relative begin position
303     * @param iEndPosition - relative end position
304     * @param iActualPage - actual page number
305     * @param iFirstVisibleItem - first visible
306     * @param iParentDataType - parent data type
307     * @param iParentId - parent ID
308     * @param strSelectedItemIds - String of selected items IDs divided by comma
309     * @param strMarkedItemIds - String of marked items IDs divided by comma
310     * @param arrShowColumnCodes - array of showed columns codes (ordered)
311     * @param strIgnoredItemIds - String of ignored items IDs divided by comma
312     * @param bDistinct - if true only distinct items will be listed. Use (true)
313     * this very carefully since it will cause sorting and it
314     * will slow down the query.
315     * @param bKeepSelected - true = if will be loaded also previously selected items
316     * @param iDomainId - domain ID
317     */

318    public ListOptions(
319       Class JavaDoc listFactoryClass,
320       String JavaDoc strDefinitionId,
321       int iPageSize,
322       int iActualListSize,
323       int[] arrOrderColumnCodes,
324       String JavaDoc[] arrOrderDirections,
325       int iClientOrderCode,
326       String JavaDoc strClientOrderDirection,
327       int iBeginPosition,
328       int iEndPosition,
329       int iActualPage,
330       int iFirstVisibleItem,
331       int iParentDataType,
332       int iParentId,
333       String JavaDoc strSelectedItemIds,
334       String JavaDoc strMarkedItemIds,
335       int[] arrShowColumnCodes,
336       String JavaDoc strIgnoredItemIds,
337       boolean bDistinct,
338       boolean bKeepSelected,
339       int iDomainId
340    )
341    {
342       m_listFactoryClass = listFactoryClass;
343       m_strDefinitionId = strDefinitionId;
344       m_iPageSize = iPageSize;
345       m_iActualListSize = iActualListSize;
346       setOrdering(arrOrderColumnCodes, arrOrderDirections);
347       m_iClientOrderCode = iClientOrderCode;
348       m_strClientOrderDirection = strClientOrderDirection;
349       m_iBeginPosition = iBeginPosition;
350       m_iEndPosition = iEndPosition;
351       m_iActualPage = iActualPage;
352       m_iFirstVisibleItem = iFirstVisibleItem;
353       m_iParentDataType = iParentDataType;
354       m_iParentId = iParentId;
355       m_strSelectedItemIDs = strSelectedItemIds;
356       m_strMarkedItemIDs = strMarkedItemIds;
357       m_arrShowColumnCodes = arrShowColumnCodes;
358       m_arrRetrieveColumnCodes = m_arrShowColumnCodes;
359       m_strIgnoredItemIDs = strIgnoredItemIds;
360       m_bDistinct = bDistinct;
361       m_bKeepSelected = bKeepSelected;
362       m_extraFilter = null;
363       m_iDomainId = iDomainId;
364    }
365    
366    /**
367     * @return Class - class representing data factory that implements
368     * list factory interface to use to retrieve data
369     * for list of data objects
370     */

371    public Class JavaDoc getListFactoryClass()
372    {
373       return m_listFactoryClass;
374    }
375
376    /**
377     * @return String
378     */

379    public String JavaDoc getSelectedItemIDs()
380    {
381       return m_strSelectedItemIDs;
382    }
383
384    /**
385     * @return String
386     */

387    public String JavaDoc getMarkedItemIDs()
388    {
389       return m_strMarkedItemIDs;
390    }
391
392    /**
393     * @return String
394     */

395    public String JavaDoc getIgnoredItemIDs()
396    {
397       return m_strIgnoredItemIDs;
398    }
399
400    /**
401     * @return int
402     */

403    public int getActualPage()
404    {
405       return m_iActualPage;
406    }
407
408    /**
409     * @return int
410     */

411    public int getBeginPosition()
412    {
413       return m_iBeginPosition;
414    }
415
416    /**
417     * @return int
418     */

419    public int getClientOrderCode()
420    {
421       return m_iClientOrderCode;
422    }
423
424    /**
425     * @return int
426     */

427    public int getEndPosition()
428    {
429       return m_iEndPosition;
430    }
431
432    /**
433     * @return String
434     */

435    public String JavaDoc getDefinitionId()
436    {
437       return m_strDefinitionId;
438    }
439
440    /**
441     * @return int
442     */

443    public int getFirstVisibleItem()
444    {
445       return m_iFirstVisibleItem;
446    }
447
448    /**
449     * @return int[]
450     */

451    public int[] getOrderColumnCodes()
452    {
453       return m_arrOrderColumnCodes;
454    }
455
456    /**
457     * @return int
458     */

459    public int getPageSize()
460    {
461       return m_iPageSize;
462    }
463    
464    /**
465     * Set IDs of the items, which are or should be selected on the GUI.
466     *
467     * @param strSelectedItems - array of selected item IDs
468     */

469    public void setSelectedItemIDs(
470       String JavaDoc strSelectedItems
471    )
472    {
473       m_strSelectedItemIDs = strSelectedItems;
474    }
475
476    /**
477     * Set IDs of the items, which are or should be highlighted or otherwise
478     * marked on the GUI.
479     *
480     * @param strMarkedItemIDs - marked item IDs
481     */

482    public void setMarkedItemIDs(
483       String JavaDoc strMarkedItemIDs
484    )
485    {
486       m_strMarkedItemIDs = strMarkedItemIDs;
487    }
488
489    /**
490     * Select IDs of tiems which shouldn't be loaded even through they satisfy
491     * other conditions.
492     *
493     * @param strIgnoredItems - string of ignored item IDs (separated by ',')
494     */

495    public void setIgnoredItemIDs(
496       String JavaDoc strIgnoredItems
497    )
498    {
499       m_strIgnoredItemIDs = strIgnoredItems;
500    }
501
502    /**
503     * Set the page which should be the actual page shown.
504     *
505     * @param iActualPage - actual page number
506     */

507    public void setActualPage(
508       int iActualPage
509    )
510    {
511       m_iActualPage = iActualPage;
512    }
513
514    /**
515     * Set the begin position which is the position of the first element
516     * in the full list of elements.
517     *
518     * @param iBeginPosition - relative begin position
519     */

520    public void setBeginPosition(
521       int iBeginPosition
522    )
523    {
524       m_iBeginPosition = iBeginPosition;
525    }
526
527    /**
528     * @param iClientOrderCode - client order column code
529     */

530    public void setClientOrderCode(
531       int iClientOrderCode
532    )
533    {
534       m_iClientOrderCode = iClientOrderCode;
535    }
536
537    /**
538     * Set the end position which is the position of the first element
539     * in the full list of elements.
540     *
541     * @param iEndPosition - relative end position
542     */

543    public void setEndPosition(
544       int iEndPosition
545    )
546    {
547       m_iEndPosition = iEndPosition;
548    }
549
550    /**
551     * @param strDefinitionId - list definition id
552     */

553    public void setDefinitionId(
554       String JavaDoc strDefinitionId
555    )
556    {
557       m_strDefinitionId = strDefinitionId;
558    }
559
560    /**
561     * @param iFirstVisibleItem - first visible item relative position
562     */

563    public void setFirstVisibleItem(
564       int iFirstVisibleItem
565    )
566    {
567       m_iFirstVisibleItem = iFirstVisibleItem;
568    }
569
570    /**
571     * @param arrOrderColumnCodes - codes for columns to order by, pass null if none
572     * @param arrOrderDirections - direction of ordering for each column
573     */

574    public void setOrdering(
575       int[] arrOrderColumnCodes,
576       String JavaDoc[] arrOrderDirections
577    )
578    {
579       if (GlobalConstants.ERROR_CHECKING)
580       {
581          assert (((arrOrderColumnCodes == null) && (arrOrderDirections == null))
582                 || (arrOrderColumnCodes.length == arrOrderDirections.length))
583                 : "Length of order column code and order direction arrays has to be the same";
584       }
585       
586       m_arrOrderColumnCodes = arrOrderColumnCodes;
587       m_arrOrderDirections = arrOrderDirections;
588    }
589
590    /**
591     * @param iPageSize - page size
592     */

593    public void setPageSize(
594       int iPageSize
595    )
596    {
597       m_iPageSize = iPageSize;
598    }
599
600    /**
601     * @return int
602     */

603    public int getActualListSize()
604    {
605       return m_iActualListSize;
606    }
607
608    /**
609     * @param iActualListSize - complete list size
610     */

611    public void setActualListSize(
612       int iActualListSize
613    )
614    {
615       m_iActualListSize = iActualListSize;
616    }
617
618    /**
619     * @return ListDefinition
620     */

621    public ListDefinition getDefinition(
622    )
623    {
624       return m_definition;
625    }
626
627    /**
628     * @param definition - list definition
629     */

630    public void setDefinition(
631       ListDefinition definition
632    )
633    {
634       m_definition = definition;
635    }
636
637    /**
638     * @return int[]
639     */

640    public int[] getShowColumnCodes(
641    )
642    {
643       return m_arrShowColumnCodes;
644    }
645
646    /**
647     * @param arrShowColumnCodes - array of column codes
648     */

649    public void setShowColumnCodes(
650       int[] arrShowColumnCodes
651    )
652    {
653       m_arrShowColumnCodes = arrShowColumnCodes;
654    }
655
656    /**
657     * @return String - one of the ListDefinition.ORDER_XXX constants
658     */

659    public String JavaDoc getClientOrderDirection()
660    {
661       return m_strClientOrderDirection;
662    }
663
664    /**
665     * @return String[]
666     */

667    public String JavaDoc[] getOrderDirections(
668    )
669    {
670       return m_arrOrderDirections;
671    }
672
673    /**
674     * @param strClientOrderDirection - client type for ordering, one of the
675     * ListDefinition.ORDER_XXX constants
676     */

677    public void setClientOrderDirection(
678       String JavaDoc strClientOrderDirection
679    )
680    {
681       m_strClientOrderDirection = strClientOrderDirection;
682    }
683
684    /**
685     * @return SimpleRule
686     */

687    public SimpleRule getSecurityFilter(
688    )
689    {
690       return m_securityFilter;
691    }
692
693    /**
694     * @param securityRule - list security data
695     */

696    public void setSecurityFilter(
697       SimpleRule securityRule
698    )
699    {
700       m_securityFilter = securityRule;
701    }
702    
703    /**
704     * Check if the list is on the first page
705     * Used by JSP
706     *
707     * @return boolean - if it is first page
708     */

709    public boolean getIsFirstPage(
710    )
711    {
712       return ((m_iBeginPosition == 1) || (m_iActualListSize == 0));
713    }
714    
715    /**
716     * Check if the list is on the last page
717     * Used by JSP
718     *
719     * @return boolean - if it is last page
720     */

721    public boolean getIsLastPage(
722    )
723    {
724       return ((m_iEndPosition == m_iActualListSize)
725               || (m_iActualListSize == 0));
726    }
727    
728    /**
729     * Generate list of pages to which user can jump directly. Make sure the
730     * list is not too long.
731     * Used by JSP
732     *
733     * @return List - list of strings with page numbers
734     */

735    public List JavaDoc getGoToPages(
736    )
737    {
738       List JavaDoc lstPages = new ArrayList JavaDoc();
739       
740       // Compute how many pages are there before the actual page and
741
// after the actual page
742
if (m_iPageSize == PAGE_SIZE_ALL)
743       {
744          // User sees all items, there is only one page
745
lstPages.add("1");
746       }
747       else
748       {
749          // This computation is the same as in getRelativePageCount
750
int iBeforePages;
751          int iAfterPages;
752          int iPageStep;
753          int iPosition;
754          int iLastAdded = -1;
755          int iTemp;
756          
757          // Assume page size 10
758
// If begin = 1 then before is 0
759
// If begin = 2 then before is 1
760
// if begin = 11 then before is 1
761
// if begin = 12 then before is 2
762
iBeforePages = (m_iBeginPosition - 1) / m_iPageSize;
763          // check if the current position is not aligned with page size
764
if (((m_iBeginPosition - 1) % m_iPageSize) != 0)
765          {
766             iBeforePages++;
767          }
768          
769          // If total is 100
770
// If end is 60 then after is 4
771
// If end is 61 then after is 4
772
// If end is 59 then after is 5
773
iAfterPages = (m_iActualListSize - m_iEndPosition) / m_iPageSize;
774          if (((m_iActualListSize - m_iEndPosition) % m_iPageSize) != 0)
775          {
776             iAfterPages++;
777          }
778          
779          // The total amount of pages is iBeforePages + 1 (current) + iAfterPages
780
// Now we need to spread them evenly. The first, last and current page is
781
// always visible. If we want to display 10 options total, that leaves 7
782
// to spread out between all the pages
783
iPageStep = m_iActualListSize / 10;
784          
785          iLastAdded = 0;
786          // Now generate the list before the actual page
787
for (iPosition = 1; iPosition < m_iBeginPosition; iPosition += iPageStep)
788          {
789             iTemp = (iPosition / m_iPageSize) + 1;
790             if (iLastAdded != iTemp)
791             {
792                iLastAdded = iTemp;
793                lstPages.add(Integer.toString(iLastAdded));
794             }
795          }
796          
797          // Now add current page
798
if (iLastAdded != m_iActualPage)
799          {
800             iLastAdded = m_iActualPage;
801             lstPages.add(Integer.toString(iLastAdded));
802          }
803    
804          // Now generate the list after the actual page
805
for (iPosition = m_iEndPosition + 1; iPosition < m_iActualListSize;
806               iPosition += iPageStep)
807          {
808             iTemp = m_iActualPage + ((iPosition - m_iEndPosition) / m_iPageSize) + 1;
809             if (iLastAdded != iTemp)
810             {
811                iLastAdded = iTemp;
812                lstPages.add(Integer.toString(iLastAdded));
813             }
814          }
815          
816          if (iLastAdded != (iBeforePages + 1 + iAfterPages))
817          {
818             lstPages.add(Integer.toString(iBeforePages + 1 + iAfterPages));
819          }
820       }
821
822       return lstPages;
823    }
824    
825    /**
826     * Absolute page count is total amount of pages of data independent from
827     * the current position in the list.
828     *
829     * @return int
830     */

831    public int getAbsolutePageCount()
832    {
833       int iPageCount;
834       
835       if (m_iPageSize == PAGE_SIZE_ALL)
836       {
837          iPageCount = 1;
838       }
839       else
840       {
841          iPageCount = (int)(m_iActualListSize / m_iPageSize);
842          if ((m_iActualListSize % m_iPageSize) != 0)
843          {
844             iPageCount++;
845          }
846       }
847       
848       return iPageCount;
849    }
850    
851    /**
852     * Relative page count is total amount of pages of data relative to
853     * the current position in the list since beucase our current position
854     * doesn't have to be alligned with page boundaries there might be 1 more
855     * page before or after the current position which wouldn't be there
856     * otherwise.
857     *
858     * @return int
859     */

860    public int getRelativePageCount()
861    {
862       int iPageCount;
863       
864       if (m_iPageSize == PAGE_SIZE_ALL)
865       {
866          iPageCount = 1;
867       }
868       else
869       {
870          // This computation is the same as in getGoToPages
871

872          int iBeforePages;
873          int iAfterPages;
874          
875          // Assume page size 10
876
// If begin = 1 then before is 0
877
// If begin = 2 then before is 1
878
// if begin = 11 then before is 1
879
// if begin = 12 then before is 2
880
iBeforePages = (m_iBeginPosition - 1) / m_iPageSize;
881          // check if the current position is not aligned with page size
882
if (((m_iBeginPosition - 1) % m_iPageSize) != 0)
883          {
884             iBeforePages++;
885          }
886          
887          // If total is 100
888
// If end is 60 then after is 4
889
// If end is 61 then after is 4
890
// If end is 59 then after is 5
891
iAfterPages = (m_iActualListSize - m_iEndPosition) / m_iPageSize;
892          if (((m_iActualListSize - m_iEndPosition) % m_iPageSize) != 0)
893          {
894             iAfterPages++;
895          }
896          
897          // The total amount of pages is iBeforePages + 1 (current) + iAfterPages
898
iPageCount = iBeforePages + 1 + iAfterPages;
899       }
900       
901       return iPageCount;
902    }
903    
904    /**
905     * Get list of columns codes which were/should be retrieved from the database.
906     * This is different that the columns which will be shown to the user since
907     * some column on UI may be a combination of multiple columns from the
908     * persistance store and vice versa. This is set by the persistance layer
909     * once the ListOptions instance passes through it.
910     *
911     * @return int[] - list of columns codes which were/should be retrieved from
912     * the database.
913     */

914    public int[] getRetrieveColumnCodes(
915    )
916    {
917       return m_arrRetrieveColumnCodes;
918    }
919
920    /**
921     * Set list of columns codes which were/should be retrieved from the
922     * persistance store. This is different that the columns which will be shown
923     * to the user since some column on UI may be a combination of multiple
924     * columns from the persistance store and vice versa. This is set by the
925     * persistance layer once the ListOptions instance passes through it.
926     *
927     * @param arrRetrieveColumnCodes - list of columns codes which were/should
928     * be retrieved from the database.
929     */

930    public void setRetrieveColumnCodes(
931       int[] arrRetrieveColumnCodes
932    )
933    {
934       m_arrRetrieveColumnCodes = arrRetrieveColumnCodes;
935    }
936    
937    /**
938     * Get list of columns codes which could be used to sort data by the
939     * persistance store. This is needed due to the fact that some databases
940     * (e.g. SAPDB) doesn't allow columns of certain data types (long VARCHAR) to
941     * be used in ORDER BY clause.
942     *
943     * This is variable is set by the persistance layer layer when the data
944     * structure is passed to it during data retrieval. If the data structure is
945     * not passed through database layer that it is not known which columns can
946     * be used for sorting or not and this value will be null. At then it is up
947     * to the caller to decide how does it wants to deal with this situation (if
948     * to assume that all columns are sortable or be conservative and assume none
949     * are).
950     *
951     * @return int[] - list of columns codes which could be used to sort data by
952     * the database. If null then we do not know what data can be
953     * used.
954     */

955    public int[] getSortableColumnCodes(
956    )
957    {
958       return m_arrSortableColumnCodes;
959    }
960
961    /**
962     * Set list of columns codes which could be used to sort data by the
963     * persistance store. This is needed due to the fact that some databases
964     * (e.g. SAPDB) doesn't allow columns of certain data types (long VARCHAR) to
965     * be used in ORDER BY clause.
966     *
967     * This is variable is set by the persistance layer layer when the data
968     * structure is passed to it during data retrieval. If the data structure is
969     * not passed through database layer that it is not known which columns can
970     * be used for sorting or not and this value will be null. At then it is up
971     * to the caller to decide how does it wants to deal with this situation (if
972     * to assume that all columns are sortable or be conservative and assume none
973     * are).
974     *
975     * @param arrSortableColumnCodes - list of columns codes which could be used
976     * to sort data by the database.
977     */

978    public void setSortableColumnCodes(
979       int[] arrSortableColumnCodes
980    )
981    {
982       m_arrSortableColumnCodes = arrSortableColumnCodes;
983    }
984    
985    /**
986     * Get list of columns codes which could be used to filter data by the
987     * persistance store.
988     *
989     * This is variable is set by the persistance layer layer when the data
990     * structure is passed to it during data retrieval. If the data structure is
991     * not passed through database layer that it is not known which columns can
992     * be used for filtering or not and this value will be null. At then it is up
993     * to the caller to decide how does it wants to deal with this situation (if
994     * to assume that all columns are filterable or be conservative and assume none
995     * are).
996     *
997     * @return int[] - list of columns codes which could be used to filter data
998     * by the database. If null then we do not know what data can
999     * be used.
1000    */

1001   public int[] getFilterableColumnCodes(
1002   )
1003   {
1004      return m_arrFilterableColumnCodes;
1005   }
1006
1007   /**
1008    * Set llist of columns codes which could be used to filter data by the
1009    * persistance store.
1010    *
1011    * This is variable is set by the persistance layer layer when the data
1012    * structure is passed to it during data retrieval. If the data structure is
1013    * not passed through database layer that it is not known which columns can
1014    * be used for filtering or not and this value will be null. At then it is up
1015    * to the caller to decide how does it wants to deal with this situation (if
1016    * to assume that all columns are filterable or be conservative and assume none
1017    * are).
1018    *
1019    * @param arrFilterableColumnCodes - list of columns codes which could be used
1020    * to filter data by the database. If null
1021    * then we do not know what data can be used.
1022    */

1023   public void setFilterableColumnCodes(
1024      int[] arrFilterableColumnCodes
1025   )
1026   {
1027      m_arrFilterableColumnCodes = arrFilterableColumnCodes;
1028   }
1029
1030   /**
1031    * @return int - list parent data type
1032    */

1033   public int getParentDataType(
1034   )
1035   {
1036      return m_iParentDataType;
1037   }
1038
1039   /**
1040    * @return int - list parent ID
1041    */

1042   public int getParentId(
1043   )
1044   {
1045      return m_iParentId;
1046   }
1047
1048   /**
1049    * @param iParentDataType - list parent data type
1050    */

1051   public void setParentDataType(
1052      int iParentDataType
1053   )
1054   {
1055      m_iParentDataType = iParentDataType;
1056   }
1057
1058   /**
1059    * @param iParentId - list parent ID
1060    */

1061   public void setParentId(
1062      int iParentId
1063   )
1064   {
1065      m_iParentId = iParentId;
1066   }
1067
1068   /**
1069    * @return int - list domain ID
1070    */

1071   public int getDomainId(
1072   )
1073   {
1074      return m_iDomainId;
1075   }
1076
1077   /**
1078    * @param iDomainId - list domain ID
1079    */

1080   public void setDomainId(
1081      int iDomainId
1082   )
1083   {
1084      m_iDomainId = iDomainId;
1085   }
1086
1087   /**
1088    * @return SimpleRule - if not null then these are extra conditions which should
1089    * be applied together with the default definition filter
1090    */

1091   public SimpleRule getExtraFilter()
1092   {
1093      return m_extraFilter;
1094   }
1095
1096   /**
1097    * @return boolean - if Keep selected checkbox is checked
1098    */

1099   public boolean getIsKeepSelectedChecked(
1100   )
1101   {
1102      return m_bKeepSelected;
1103   }
1104
1105   /**
1106    * @return int - if Keep selected checkbox is checked
1107    */

1108   public int getKeepSelected(
1109   )
1110   {
1111      return m_bKeepSelected ? 1 : 0;
1112   }
1113
1114   /**
1115    * @param bKeepSelected - if Keep selected checkbox is checked
1116    */

1117   public void setKeepSelected(
1118      boolean bKeepSelected
1119   )
1120   {
1121      m_bKeepSelected = bKeepSelected;
1122   }
1123
1124   /**
1125    * @param extraFilter - if not null then these are extra conditions which should
1126    * be applied together with filter.
1127    * @param iExtraLogicalOperation - can be one of the SimpleRule.LOGICAL_XXX constants
1128    */

1129   public void setExtraFilter(
1130      SimpleRule extraFilter,
1131      int iExtraLogicalOperation
1132   )
1133   {
1134      assert ((iExtraLogicalOperation == SimpleRule.LOGICAL_AND)
1135             || (iExtraLogicalOperation == SimpleRule.LOGICAL_OR))
1136             : "Extra condition operand is not valid";
1137      
1138      m_extraFilter = extraFilter;
1139      m_iExtraLogicalOperation = iExtraLogicalOperation;
1140   }
1141   
1142   /**
1143    * @return int - can be one of the SimpleRule.LOGICAL_XXX constants
1144    */

1145   public int getExtraLogicalOperation(
1146   )
1147   {
1148      return m_iExtraLogicalOperation;
1149   }
1150   
1151   /**
1152    * @return boolean - if true only distinct items should be loaded
1153    */

1154   public boolean isDistinct()
1155   {
1156      return m_bDistinct;
1157   }
1158
1159   /**
1160    * @param bDistinct - if true only distinct items will be listed. Use (true)
1161    * this very carefully since it will cause sorting and it
1162    * will slow down the query.
1163    */

1164   public void setDistinct(
1165      boolean bDistinct
1166   )
1167   {
1168      m_bDistinct = bDistinct;
1169   }
1170}
1171
Popular Tags