KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > list > support > ListParamsImpl


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.list.support;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.LinkedList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.riotfamily.riot.dao.ListParams;
31 import org.riotfamily.riot.dao.Order;
32
33 /**
34  * A bean style implementation of the ListModelParams interface.
35  */

36 public class ListParamsImpl implements ListParams {
37
38     private Object JavaDoc filter;
39     
40     private String JavaDoc[] filteredProperties;
41
42     private String JavaDoc search;
43     
44     private String JavaDoc[] searchProperties;
45     
46     private List JavaDoc order;
47     
48     private int pageSize;
49     
50     private int offset;
51
52     
53     public ListParamsImpl() {
54     }
55     
56     public Object JavaDoc getFilter() {
57         return filter;
58     }
59
60     public void setFilter(Object JavaDoc filter) {
61         this.filter = filter;
62     }
63     
64     public String JavaDoc[] getFilteredProperties() {
65         return this.filteredProperties;
66     }
67
68     public void setFilteredProperties(String JavaDoc[] filterProperties) {
69         this.filteredProperties = filterProperties;
70     }
71
72     public String JavaDoc getSearch() {
73         return this.search;
74     }
75
76     public void setSearch(String JavaDoc search) {
77         this.search = search;
78     }
79     
80     public String JavaDoc[] getSearchProperties() {
81         return this.searchProperties;
82     }
83
84     public void setSearchProperties(String JavaDoc[] searchProperties) {
85         this.searchProperties = searchProperties;
86     }
87
88     public int getOffset() {
89         return offset;
90     }
91
92     public void setOffset(int offset) {
93         this.offset = offset;
94     }
95     
96     public int getPage() {
97         return offset / pageSize + 1;
98     }
99     
100     public void setPage(int page) {
101         offset = (page - 1) * pageSize;
102     }
103
104     public List JavaDoc getOrder() {
105         return order;
106     }
107
108     public void setOrder(List JavaDoc order) {
109         this.order = order;
110     }
111     
112     public void setOrder(Order order) {
113         this.order = new LinkedList JavaDoc();
114         if (order != null) {
115             this.order.add(order);
116         }
117     }
118     
119     public boolean hasOrder() {
120         return order != null && !order.isEmpty();
121     }
122     
123     public Order getPrimaryOrder() {
124         if (!hasOrder()) {
125             return null;
126         }
127         return (Order) getOrder().get(0);
128     }
129
130     /**
131      * Changes the sort order so that the list will be ordered by the given
132      * property. The previous order will be shifted to the right (from an
133      * SQL point of view) unless the list was already ordered by the given
134      * property in which case only the sort direction will be toggled.
135      */

136     public void orderBy(String JavaDoc property, boolean ascending, boolean caseSensitive) {
137         if (getOrder() == null) {
138             setOrder(new LinkedList JavaDoc());
139         }
140         else {
141             Order primary = getPrimaryOrder();
142             if (primary != null && primary.isProperty(property)) {
143                 primary.toggleDirection();
144                 return;
145             }
146             Iterator JavaDoc it = getOrder().iterator();
147             while (it.hasNext()) {
148                 Order order = (Order) it.next();
149                 if (order.isProperty(property)) {
150                     it.remove();
151                 }
152             }
153         }
154         getOrder().add(0, new Order(property, ascending, caseSensitive));
155     }
156     
157     public int getPageSize() {
158         return pageSize;
159     }
160
161     public void setPageSize(int pageSize) {
162         this.pageSize = pageSize;
163     }
164
165 }
166
Popular Tags