KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > list > ListConfig


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;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.riotfamily.riot.dao.Order;
31 import org.riotfamily.riot.dao.RiotDao;
32 import org.riotfamily.riot.list.command.Command;
33 import org.springframework.util.StringUtils;
34
35 /**
36  *
37  */

38 public class ListConfig {
39     
40     private static final String JavaDoc DEFAULT_ID_PROPERTY = "id";
41
42     private String JavaDoc id;
43
44     private RiotDao dao;
45
46     private List JavaDoc columnConfigs = new ArrayList JavaDoc();
47
48     private List JavaDoc commands = new ArrayList JavaDoc();
49     
50     private ArrayList JavaDoc columnCommands = new ArrayList JavaDoc();
51     
52     private List JavaDoc formCommands;
53     
54     private String JavaDoc[] defaultCommandIds;
55
56     private String JavaDoc idProperty;
57     
58     private String JavaDoc rowStyleProperty;
59     
60     private int pageSize = 15;
61     
62     private String JavaDoc filterFormId;
63     
64     private Order defaultOrder;
65     
66     private String JavaDoc[] searchProperties;
67
68     public String JavaDoc getId() {
69         return id;
70     }
71
72     public void setId(String JavaDoc id) {
73         this.id = id;
74     }
75
76     public String JavaDoc getIdProperty() {
77         return idProperty != null ? idProperty : DEFAULT_ID_PROPERTY;
78     }
79
80     public void setIdProperty(String JavaDoc idProperty) {
81         this.idProperty = idProperty;
82     }
83
84     public String JavaDoc getRowStyleProperty() {
85         return this.rowStyleProperty;
86     }
87
88     public void setRowStyleProperty(String JavaDoc rowStyleProperty) {
89         this.rowStyleProperty = rowStyleProperty;
90     }
91
92     public void setDao(RiotDao dao) {
93         this.dao = dao;
94     }
95
96     public RiotDao getDao() {
97         return dao;
98     }
99
100     public int getPageSize() {
101         return pageSize;
102     }
103
104     public void setPageSize(int pageSize) {
105         this.pageSize = pageSize;
106     }
107
108     public void addColumnConfig(ColumnConfig column) {
109         columnConfigs.add(column);
110     }
111
112     public List JavaDoc getColumnConfigs() {
113         return columnConfigs;
114     }
115
116     public ColumnConfig getColumnConfig(int index) {
117         return (ColumnConfig) columnConfigs.get(index);
118     }
119     
120     public ColumnConfig getColumnConfig(String JavaDoc property) {
121         property = property.trim();
122         Iterator JavaDoc it = columnConfigs.iterator();
123         while (it.hasNext()) {
124             ColumnConfig columnConfig = (ColumnConfig) it.next();
125             if (property.equals(columnConfig.getProperty())) {
126                 return columnConfig;
127             }
128         }
129         return null;
130     }
131
132     public void addCommand(Command command) {
133         commands.add(command);
134     }
135
136     public List JavaDoc getCommands() {
137         return commands;
138     }
139
140     public Class JavaDoc getItemClass() {
141         return dao.getEntityClass();
142     }
143
144     public String JavaDoc getFirstProperty() {
145         if (!columnConfigs.isEmpty()) {
146             ColumnConfig columnConfig = (ColumnConfig) columnConfigs.get(0);
147             return columnConfig.getProperty();
148         }
149         return null;
150     }
151     
152     public String JavaDoc getFirstSortableProperty() {
153         Iterator JavaDoc it = columnConfigs.iterator();
154         while (it.hasNext()) {
155             ColumnConfig columnConfig = (ColumnConfig) it.next();
156             if (columnConfig.getProperty() != null
157                     && columnConfig.isSortable()) {
158                 return columnConfig.getProperty();
159             }
160         }
161         return null;
162     }
163     
164     public void addColumnCommand(Command command) {
165         columnCommands.add(command);
166     }
167     
168     public List JavaDoc getColumnCommands() {
169         return columnCommands;
170     }
171     
172     public List JavaDoc getFormCommands() {
173         if (formCommands == null) {
174             formCommands = new ArrayList JavaDoc();
175             Iterator JavaDoc it = columnCommands.iterator();
176             while (it.hasNext()) {
177                 Command command = (Command) it.next();
178                 if (command.isShowOnForm()) {
179                     formCommands.add(command);
180                 }
181             }
182         }
183         return formCommands;
184     }
185     
186     public Command getFirstColumnCommand() {
187         if (!columnCommands.isEmpty()) {
188             return (Command) columnCommands.get(0);
189         }
190         return null;
191     }
192
193     public String JavaDoc getFilterFormId() {
194         return filterFormId;
195     }
196
197     public void setFilterFormId(String JavaDoc filterForm) {
198         this.filterFormId = filterForm;
199     }
200
201     public void setDefaultCommandId(String JavaDoc defaultCommandId) {
202         setDefaultCommandIds(new String JavaDoc[] {defaultCommandId});
203     }
204     
205     public void setDefaultCommandIds(String JavaDoc[] defaultCommandIds) {
206         this.defaultCommandIds = defaultCommandIds;
207     }
208
209     public String JavaDoc[] getDefaultCommandIds() {
210         if (defaultCommandIds == null) {
211             Command command = getFirstColumnCommand();
212             if (command != null) {
213                 defaultCommandIds = new String JavaDoc[] {command.getId()};
214             }
215         }
216         return defaultCommandIds;
217     }
218
219     public void setOrderBy(String JavaDoc orderBy) {
220         int i = orderBy.indexOf(' ');
221         if (i != -1) {
222             String JavaDoc property = orderBy.substring(0, i);
223             boolean asc = !orderBy.endsWith(" desc");
224             ColumnConfig col = getColumnConfig(property);
225             boolean caseSensitive = (col == null) ? true : col.isCaseSensitive();
226             defaultOrder = new Order(property, asc, caseSensitive);
227         }
228         else {
229             ColumnConfig col = getColumnConfig(orderBy);
230             boolean caseSensitive = (col == null) ? true : col.isCaseSensitive();
231             defaultOrder = new Order(orderBy, true, caseSensitive);
232         }
233     }
234     
235     public Order getDefaultOrder() {
236         if (defaultOrder == null) {
237             String JavaDoc property = getFirstSortableProperty();
238             if (property != null) {
239                 ColumnConfig col = getColumnConfig(property);
240                 boolean caseSensitive = (col == null) ? true : col.isCaseSensitive();
241                 defaultOrder = new Order(property, true, caseSensitive);
242             }
243         }
244         return defaultOrder;
245     }
246     
247     public String JavaDoc[] getSearchProperties() {
248         return this.searchProperties;
249     }
250
251     public void setSearchProperties(String JavaDoc[] searchProperties) {
252         this.searchProperties = searchProperties;
253     }
254
255     public void setSearch(String JavaDoc search) {
256         setSearchProperties(StringUtils.tokenizeToStringArray(
257                 search, " ,\t\r\n"));
258     }
259     
260 }
261
Popular Tags