KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > lists > AbstractList


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 package info.magnolia.module.admininterface.lists;
14
15 import info.magnolia.cms.core.Path;
16 import info.magnolia.cms.gui.control.ContextMenu;
17 import info.magnolia.cms.gui.control.FunctionBar;
18 import info.magnolia.cms.gui.controlx.RenderKit;
19 import info.magnolia.cms.gui.controlx.RenderKitFactory;
20 import info.magnolia.cms.gui.controlx.list.ListControl;
21 import info.magnolia.cms.gui.controlx.list.ListModel;
22 import info.magnolia.cms.util.FreeMarkerUtil;
23 import info.magnolia.context.MgnlContext;
24 import info.magnolia.context.WebContext;
25 import info.magnolia.module.admininterface.TemplatedMVCHandler;
26
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29
30
31 /**
32  * @author Philipp Bracher
33  * @version $Revision: 7439 $ ($Author: philipp $)
34  */

35 public abstract class AbstractList extends TemplatedMVCHandler {
36
37     private String JavaDoc sortBy = "";
38
39     private String JavaDoc sortByOrder = "asc";
40
41     private String JavaDoc groupBy = "";
42
43     private String JavaDoc groupByOrder = "asc";
44
45     /**
46      * Control used.
47      */

48     private ListControl list;
49
50     /**
51      * The function bar shown at the bottom
52      */

53     private FunctionBar functionBar;
54
55     private ContextMenu contextMenu;
56
57     /**
58      * @param name
59      * @param request
60      * @param response
61      */

62     public AbstractList(String JavaDoc name, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
63         super(name, request, response);
64     }
65
66     /**
67      * Don't use the class name.
68      */

69     protected String JavaDoc getTemplateName(String JavaDoc viewName) {
70         return FreeMarkerUtil.createTemplateName(AbstractList.class, "html");
71     }
72
73     /**
74      * @see com.obinary.magnolia.professional.PageMVCHandler#show()
75      */

76     public String JavaDoc show() {
77         String JavaDoc view = super.show();
78         ListControl list = this.getList();
79         initList(list);
80         configureList(list);
81         return view;
82     }
83
84     /**
85      * @param list
86      */

87     public abstract void configureList(ListControl list);
88
89     /**
90      * @param list
91      */

92     public void initList(ListControl list) {
93         list.setName("list");
94         list.setRenderKit(this.getRenderKit());
95         list.setContextMenu(this.getContextMenu());
96         list.setModel(this.getModel());
97         list.setSortBy(this.getSortBy());
98         list.setSortByOrder(this.getSortByOrder());
99         list.setGroupBy(this.getGroupBy());
100         list.setGroupByOrder(this.getGroupByOrder());
101     }
102
103     /**
104      * Returns the model used by this list
105      */

106     public abstract ListModel getModel();
107
108     /**
109      * @param list The list to set.
110      */

111     public void setList(ListControl list) {
112         this.list = list;
113     }
114
115     /**
116      * @return Returns the list.
117      */

118     public ListControl getList() {
119         if (list == null) {
120             list = new ListControl();
121         }
122         return list;
123     }
124
125     public ContextMenu getContextMenu() {
126         if (this.contextMenu == null) {
127             this.contextMenu = new ContextMenu("contextMenu");
128             configureContextMenu(this.contextMenu);
129         }
130         return this.contextMenu;
131     }
132
133     /**
134      * Override to configure the menu
135      */

136     protected void configureContextMenu(ContextMenu menu) {
137     }
138
139     /**
140      * Returns the default admin interface render kit.
141      */

142     protected RenderKit getRenderKit() {
143         return RenderKitFactory.getRenderKit(RenderKitFactory.ADMIN_INTERFACE_RENDER_KIT);
144     }
145
146     /**
147      * @return Returns the functionBar.
148      */

149     public FunctionBar getFunctionBar() {
150         if (this.functionBar == null) {
151             this.functionBar = new FunctionBar("functionBar");
152             configureFunctionBar(this.functionBar);
153         }
154         return this.functionBar;
155     }
156
157     /**
158      * Override to configure the bar
159      */

160     protected void configureFunctionBar(FunctionBar bar) {
161     }
162
163     /**
164      * @param functionBar The functionBar to set.
165      */

166     public void setFunctionBar(FunctionBar functionBar) {
167         this.functionBar = functionBar;
168     }
169
170     /**
171      * @return Returns the groupBy.
172      */

173     public String JavaDoc getGroupBy() {
174         return this.groupBy;
175     }
176
177     /**
178      * @param groupBy The groupBy to set.
179      */

180     public void setGroupBy(String JavaDoc groupBy) {
181         this.groupBy = groupBy;
182     }
183
184     /**
185      * @return Returns the groupByOrder.
186      */

187     public String JavaDoc getGroupByOrder() {
188         return this.groupByOrder;
189     }
190
191     /**
192      * @param groupByOrder The groupByOrder to set.
193      */

194     public void setGroupByOrder(String JavaDoc groupByOrder) {
195         this.groupByOrder = groupByOrder;
196     }
197
198     /**
199      * @return Returns the sortBy.
200      */

201     public String JavaDoc getSortBy() {
202         return this.sortBy;
203     }
204
205     /**
206      * @param sortBy The sortBy to set.
207      */

208     public void setSortBy(String JavaDoc sortBy) {
209         this.sortBy = sortBy;
210     }
211
212     /**
213      * @return Returns the sortByOrder.
214      */

215     public String JavaDoc getSortByOrder() {
216         return this.sortByOrder;
217     }
218
219     /**
220      * @param sortByOrder The sortByOrder to set.
221      */

222     public void setSortByOrder(String JavaDoc sortByOrder) {
223         this.sortByOrder = sortByOrder;
224     }
225
226     /**
227      * Do some additional rendering in the subclass
228      */

229     public String JavaDoc onRender() {
230         return "";
231     }
232     
233     public String JavaDoc getURI() {
234         String JavaDoc uri = (String JavaDoc) MgnlContext.getAttribute(Path.MGNL_REQUEST_URI_DECODED);
235         return uri;
236     }
237
238 }
239
Popular Tags