1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.gui.controlx.list;
35
36 import info.magnolia.cms.gui.control.ContextMenu;
37 import info.magnolia.cms.gui.controlx.impl.AbstractControl;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42 import org.apache.commons.lang.StringUtils;
43
44
45
46
47
48
49
50 public class ListControl extends AbstractControl {
51
52
53
54
55 public static final String RENDER_TYPE = "listControl";
56
57
58
59
60 private ListModelIterator iterator;
61
62
63
64
65 private ListModel model;
66
67
68
69
70 private ContextMenu contextMenu;
71
72
73
74
75 private List sortableFields = new ArrayList();
76
77
78
79
80 private List groupableFields = new ArrayList();
81
82
83
84
85 private int maxRowsPerGroup = 5;
86
87
88
89
90 public ListControl() {
91 this.setRenderType(RENDER_TYPE);
92 }
93
94 public ListModel getModel() {
95 return this.model;
96 }
97
98 public void setModel(ListModel model) {
99 this.model = model;
100 }
101
102
103
104
105 public void addColumn(ListColumn column) {
106 this.addChild(column);
107 }
108
109
110
111
112
113 public ListModelIterator getIterator() {
114 if (this.iterator == null) {
115 this.iterator = this.getModel().getListModelIterator();
116 }
117 return iterator;
118 }
119
120
121
122
123
124
125 public Object getIteratorValue(String name) {
126 return this.getIterator().getValue(name);
127 }
128
129
130
131
132
133 public Object getIteratorValueObject() {
134 return this.getIterator().getValueObject();
135 }
136
137 public String getIteratorId() {
138 return this.getIterator().getId();
139 }
140
141
142
143
144
145 public void resetIterator() {
146 this.iterator = null;
147 }
148
149 public ContextMenu getContextMenu() {
150 return this.contextMenu;
151 }
152
153 public void setContextMenu(ContextMenu contextMenu) {
154 this.contextMenu = contextMenu;
155 }
156
157 public List getGroupableFields() {
158 return this.groupableFields;
159 }
160
161 public List getSortableFields() {
162 return this.sortableFields;
163 }
164
165 public void addSortableField(String name) {
166 this.sortableFields.add(name);
167 }
168
169 public void addGroupableField(String name) {
170 this.groupableFields.add(name);
171 }
172
173 public int getMaxRowsPerGroup() {
174 return this.maxRowsPerGroup;
175 }
176
177 public void setMaxRowsPerGroup(int maxRowsPerGroup) {
178 this.maxRowsPerGroup = maxRowsPerGroup;
179 }
180
181
182
183
184 public String getGroupBy() {
185 return StringUtils.defaultString(this.model.getGroupBy());
186 }
187
188
189
190
191 public String getGroupByOrder() {
192 return StringUtils.defaultIfEmpty(this.model.getGroupByOrder(), "asc");
193 }
194
195
196
197
198 public String getSortBy() {
199 return StringUtils.defaultString(this.model.getSortBy());
200 }
201
202
203
204
205 public String getSortByOrder() {
206 return StringUtils.defaultIfEmpty(this.model.getSortByOrder(), "asc");
207 }
208
209
210
211
212 public void setGroupBy(String name) {
213 this.model.setGroupBy(name, this.model.getGroupByOrder());
214 }
215
216
217
218
219 public void setGroupByOrder(String order) {
220 this.model.setGroupBy(this.model.getGroupBy(), order);
221 }
222
223
224
225
226
227
228 public String getColumnLabel(String name) {
229 ListColumn column = (ListColumn) this.getChild(name);
230 return column.getLabel();
231 }
232
233
234
235
236 public void setSortBy(String name) {
237 this.model.setSortBy(name, this.model.getSortByOrder());
238 }
239
240 public void setSortByOrder(String order) {
241 this.model.setSortBy(this.model.getSortBy(), order);
242 }
243
244 }