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 protected String getTemplateName(String viewName) {
90 return FreemarkerUtil.createTemplateName(AbstractList.class, "html");
91 }
92
93 public String show() {
94 String view = super.show();
95 ListControl list = this.getList();
96 initList(list);
97 configureList(list);
98 return view;
99 }
100
101
102
103
104 public abstract void configureList(ListControl list);
105
106
107
108
109 public void initList(ListControl list) {
110 list.setName("list");
111 list.setRenderKit(this.getRenderKit());
112 list.setContextMenu(this.getContextMenu());
113 list.setModel(this.getModel());
114 list.setSortBy(this.getSortBy());
115 list.setSortByOrder(this.getSortByOrder());
116 list.setGroupBy(this.getGroupBy());
117 list.setGroupByOrder(this.getGroupByOrder());
118 }
119
120 public String getLanguage(){
121 return MgnlContext.getUser().getLanguage();
122 }
123
124
125
126
127 public abstract ListModel getModel();
128
129
130
131
132 public void setList(ListControl list) {
133 this.list = list;
134 }
135
136
137
138
139 public ListControl getList() {
140 if (list == null) {
141 list = new ListControl();
142 }
143 return list;
144 }
145
146 public ContextMenu getContextMenu() {
147 if (this.contextMenu == null) {
148 this.contextMenu = new ContextMenu("contextMenu");
149 configureContextMenu(this.contextMenu);
150 }
151 return this.contextMenu;
152 }
153
154
155
156
157 protected void configureContextMenu(ContextMenu menu) {
158 }
159
160
161
162
163 protected void addContextMenuItem(ContextMenu menu, String name, String label, String iconName, String methodName, String isActiveMethodName) {
164 final ContextMenuItem showInTree = new ContextMenuItem(name);
165 showInTree.setLabel(getMsgs().get(label));
166 showInTree.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/" + iconName+".gif");
167 showInTree.setOnclick(this.getList().getName() + "." + methodName + "();");
168 showInTree.addJavascriptCondition("function(){return " + this.getList().getName() + "." + isActiveMethodName + "()}");
169 menu.addMenuItem(showInTree);
170 }
171
172
173
174
175
176 protected RenderKit getRenderKit() {
177 return RenderKitFactory.getRenderKit(RenderKitFactory.ADMIN_INTERFACE_RENDER_KIT);
178 }
179
180
181
182
183 public FunctionBar getFunctionBar() {
184 if (this.functionBar == null) {
185 this.functionBar = new FunctionBar("functionBar");
186 configureFunctionBar(this.functionBar);
187 }
188 return this.functionBar;
189 }
190
191
192
193
194 protected void configureFunctionBar(FunctionBar bar) {
195 }
196
197
198
199
200 public void setFunctionBar(FunctionBar functionBar) {
201 this.functionBar = functionBar;
202 }
203
204
205
206
207 public String getGroupBy() {
208 return this.groupBy;
209 }
210
211
212
213
214 public void setGroupBy(String groupBy) {
215 this.groupBy = groupBy;
216 }
217
218
219
220
221 public String getGroupByOrder() {
222 return this.groupByOrder;
223 }
224
225
226
227
228 public void setGroupByOrder(String groupByOrder) {
229 this.groupByOrder = groupByOrder;
230 }
231
232
233
234
235 public String getSortBy() {
236 return this.sortBy;
237 }
238
239
240
241
242 public void setSortBy(String sortBy) {
243 this.sortBy = sortBy;
244 }
245
246
247
248
249 public String getSortByOrder() {
250 return this.sortByOrder;
251 }
252
253
254
255
256 public void setSortByOrder(String sortByOrder) {
257 this.sortByOrder = sortByOrder;
258 }
259
260
261
262
263 public String onRender() {
264 return "";
265 }
266
267
268
269
270 public String onRenderHeader() {
271 return "";
272 }
273
274 public String getURI() {
275 return MgnlContext.getAggregationState().getCurrentURI();
276 }
277
278 }