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