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
35 package info.magnolia.module.admininterface.lists;
36
37 import info.magnolia.cms.gui.control.ContextMenu;
38 import info.magnolia.cms.gui.control.ContextMenuItem;
39 import info.magnolia.cms.gui.control.FunctionBar;
40 import info.magnolia.cms.gui.controlx.RenderKit;
41 import info.magnolia.cms.gui.controlx.RenderKitFactory;
42 import info.magnolia.cms.gui.controlx.list.ListControl;
43 import info.magnolia.cms.gui.controlx.list.ListModel;
44 import info.magnolia.context.MgnlContext;
45 import info.magnolia.freemarker.FreemarkerUtil;
46 import info.magnolia.module.admininterface.TemplatedMVCHandler;
47
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
50
51
52
53
54
55
56 public abstract class AbstractList extends TemplatedMVCHandler {
57
58 private String sortBy = "";
59
60 private String sortByOrder = "asc";
61
62 private String groupBy = "";
63
64 private String groupByOrder = "asc";
65
66
67
68
69 private ListControl list;
70
71
72
73
74 private FunctionBar functionBar;
75
76 private ContextMenu contextMenu;
77
78
79
80
81
82
83 public AbstractList(String name, HttpServletRequest request, HttpServletResponse response) {
84 super(name, request, response);
85 }
86
87
88
89
90 protected String getTemplateName(String viewName) {
91 return FreemarkerUtil.createTemplateName(AbstractList.class, "html");
92 }
93
94 public String show() {
95 String view = super.show();
96 ListControl list = this.getList();
97 initList(list);
98 configureList(list);
99 return view;
100 }
101
102
103
104
105 public abstract void configureList(ListControl list);
106
107
108
109
110 public void initList(ListControl list) {
111 list.setName("list");
112 list.setRenderKit(this.getRenderKit());
113 list.setContextMenu(this.getContextMenu());
114 list.setModel(this.getModel());
115 list.setSortBy(this.getSortBy());
116 list.setSortByOrder(this.getSortByOrder());
117 list.setGroupBy(this.getGroupBy());
118 list.setGroupByOrder(this.getGroupByOrder());
119 }
120
121 public String getLanguage(){
122 return MgnlContext.getUser().getLanguage();
123 }
124
125
126
127
128 public abstract ListModel getModel();
129
130
131
132
133 public void setList(ListControl list) {
134 this.list = list;
135 }
136
137
138
139
140 public ListControl getList() {
141 if (list == null) {
142 list = new ListControl();
143 }
144 return list;
145 }
146
147 public ContextMenu getContextMenu() {
148 if (this.contextMenu == null) {
149 this.contextMenu = new ContextMenu("mgnlContextMenu");
150 configureContextMenu(this.contextMenu);
151 }
152 return this.contextMenu;
153 }
154
155
156
157
158 protected void configureContextMenu(ContextMenu menu) {
159 }
160
161
162
163
164 protected void addContextMenuItem(ContextMenu menu, String name, String label, String iconName, String methodName, String isActiveMethodName) {
165 final ContextMenuItem showInTree = new ContextMenuItem(name);
166 showInTree.setLabel(getMsgs().get(label));
167 showInTree.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/" + iconName+".gif");
168 showInTree.setOnclick(this.getList().getName() + "." + methodName + "();");
169 showInTree.addJavascriptCondition("function(){return " + this.getList().getName() + "." + isActiveMethodName + "()}");
170 menu.addMenuItem(showInTree);
171 }
172
173
174
175
176
177 protected RenderKit getRenderKit() {
178 return RenderKitFactory.getRenderKit(RenderKitFactory.ADMIN_INTERFACE_RENDER_KIT);
179 }
180
181
182
183
184 public FunctionBar getFunctionBar() {
185 if (this.functionBar == null) {
186 this.functionBar = new FunctionBar("functionBar");
187 configureFunctionBar(this.functionBar);
188 }
189 return this.functionBar;
190 }
191
192
193
194
195 protected void configureFunctionBar(FunctionBar bar) {
196 }
197
198
199
200
201 public void setFunctionBar(FunctionBar functionBar) {
202 this.functionBar = functionBar;
203 }
204
205
206
207
208 public String getGroupBy() {
209 return this.groupBy;
210 }
211
212
213
214
215 public void setGroupBy(String groupBy) {
216 this.groupBy = groupBy;
217 }
218
219
220
221
222 public String getGroupByOrder() {
223 return this.groupByOrder;
224 }
225
226
227
228
229 public void setGroupByOrder(String groupByOrder) {
230 this.groupByOrder = groupByOrder;
231 }
232
233
234
235
236 public String getSortBy() {
237 return this.sortBy;
238 }
239
240
241
242
243 public void setSortBy(String sortBy) {
244 this.sortBy = sortBy;
245 }
246
247
248
249
250 public String getSortByOrder() {
251 return this.sortByOrder;
252 }
253
254
255
256
257 public void setSortByOrder(String sortByOrder) {
258 this.sortByOrder = sortByOrder;
259 }
260
261
262
263
264 public String onRender() {
265 return "";
266 }
267
268
269
270
271 public String onRenderHeader() {
272 return "";
273 }
274
275 public String getURI() {
276 return MgnlContext.getAggregationState().getCurrentURI();
277 }
278
279 }