KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > controlx > list > ListControl


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13
14 package info.magnolia.cms.gui.controlx.list;
15
16 import info.magnolia.cms.gui.control.ContextMenu;
17 import info.magnolia.cms.gui.controlx.impl.AbstractControl;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.commons.lang.StringUtils;
23
24
25 /**
26  * A list. Can sort or group data.
27  * @author Philipp Bracher
28  * @version $Revision: 6341 $ ($Author: philipp $)
29  */

30 public class ListControl extends AbstractControl {
31
32     /**
33      * The type used for rendering
34      */

35     public static final String JavaDoc RENDER_TYPE = "listControl";
36
37     /**
38      * The current itarotor.
39      */

40     private ListModelIterator iterator;
41
42     /**
43      * The underlaying model
44      */

45     private ListModel model;
46
47     /**
48      * The context menu used
49      */

50     private ContextMenu contextMenu;
51
52     /**
53      * Fields on which you can sort
54      */

55     private List JavaDoc sortableFields = new ArrayList JavaDoc();
56
57     /**
58      * Fields you can group
59      */

60     private List JavaDoc groupableFields = new ArrayList JavaDoc();
61
62     /**
63      * Max rows shown per group
64      */

65     private int maxRowsPerGroup = 5;
66
67     /**
68      * Constructor. Setting the render type.
69      */

70     public ListControl() {
71         this.setRenderType(RENDER_TYPE);
72     }
73
74     public ListModel getModel() {
75         return this.model;
76     }
77
78     public void setModel(ListModel model) {
79         this.model = model;
80     }
81
82     /**
83      * @see info.magnolia.cms.gui.controlx.list.ListControl#addColumn(info.magnolia.cms.gui.controlx.list.ListColumn)
84      */

85     public void addColumn(ListColumn column) {
86         this.addChild(column);
87     }
88
89     /**
90      * Layzy bound iterator.
91      * @return Returns the iterator.
92      */

93     public ListModelIterator getIterator() {
94         if (this.iterator == null) {
95             this.iterator = this.getModel().getListModelIterator();
96         }
97         return iterator;
98     }
99
100     /**
101      * Get the value for a column in the current iterator.
102      * @param name
103      * @return the value
104      */

105     public Object JavaDoc getIteratorValue(String JavaDoc name) {
106         return this.getIterator().getValue(name);
107     }
108
109     /**
110      * Get the current object (not the value) in the current iterator.
111      * @return the object. corresponds to a row.
112      */

113     public Object JavaDoc getIteratorValueObject() {
114         return this.getIterator().getValueObject();
115     }
116
117     /**
118      * Restart the iterator.
119      */

120     public void resetIterator() {
121         this.iterator = null;
122     }
123
124     public ContextMenu getContextMenu() {
125         return this.contextMenu;
126     }
127
128     public void setContextMenu(ContextMenu contextMenu) {
129         this.contextMenu = contextMenu;
130     }
131
132     public List JavaDoc getGroupableFields() {
133         return this.groupableFields;
134     }
135
136     public List JavaDoc getSortableFields() {
137         return this.sortableFields;
138     }
139
140     public void addSortableField(String JavaDoc name) {
141         this.sortableFields.add(name);
142     }
143
144     public void addGroupableField(String JavaDoc name) {
145         this.groupableFields.add(name);
146     }
147
148     public int getMaxRowsPerGroup() {
149         return this.maxRowsPerGroup;
150     }
151
152     public void setMaxRowsPerGroup(int maxRowsPerGroup) {
153         this.maxRowsPerGroup = maxRowsPerGroup;
154     }
155
156     /**
157      * @see info.magnolia.cms.gui.controlx.list.ListModel#getGroupBy()
158      */

159     public String JavaDoc getGroupBy() {
160         return StringUtils.defaultString(this.model.getGroupBy());
161     }
162
163     /**
164      * @see info.magnolia.cms.gui.controlx.list.ListModel#getGroupByOrder()
165      */

166     public String JavaDoc getGroupByOrder() {
167         return StringUtils.defaultIfEmpty(this.model.getGroupByOrder(), "asc");
168     }
169
170     /**
171      * @see info.magnolia.cms.gui.controlx.list.ListModel#getSortBy()
172      */

173     public String JavaDoc getSortBy() {
174         return StringUtils.defaultString(this.model.getSortBy());
175     }
176
177     /**
178      * @see info.magnolia.cms.gui.controlx.list.ListModel#getSortByOrder()
179      */

180     public String JavaDoc getSortByOrder() {
181         return StringUtils.defaultIfEmpty(this.model.getSortByOrder(), "asc");
182     }
183
184     /**
185      * @see info.magnolia.cms.gui.controlx.list.ListModel#setGroupBy(java.lang.String)
186      */

187     public void setGroupBy(String JavaDoc name) {
188         this.model.setGroupBy(name, this.model.getGroupByOrder());
189     }
190
191     /**
192      * @see info.magnolia.cms.gui.controlx.list.ListModel#setGroupBy(java.lang.String)
193      */

194     public void setGroupByOrder(String JavaDoc order) {
195         this.model.setGroupBy(this.model.getGroupBy(), order);
196     }
197
198     /**
199      * Get the lable of a specific
200      * @param name
201      * @return
202      */

203     public String JavaDoc getColumnLabel(String JavaDoc name) {
204         ListColumn column = (ListColumn) this.getChild(name);
205         return column.getLabel();
206     }
207
208     /**
209      * @see info.magnolia.cms.gui.controlx.list.ListModel#setSortBy(java.lang.String)
210      */

211     public void setSortBy(String JavaDoc name) {
212         this.model.setSortBy(name, this.model.getSortByOrder());
213     }
214
215     public void setSortByOrder(String JavaDoc order) {
216         this.model.setSortBy(this.model.getSortBy(), order);
217     }
218
219 }
220
Popular Tags