KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > modules > CmsModulesOverview


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/modules/CmsModulesOverview.java,v $
3  * Date : $Date: 2006/10/06 14:02:20 $
4  * Version: $Revision: 1.10 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.modules;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.OpenCms;
36 import org.opencms.module.CmsModule;
37 import org.opencms.util.CmsStringUtil;
38 import org.opencms.widgets.CmsDisplayWidget;
39 import org.opencms.workplace.CmsDialog;
40 import org.opencms.workplace.CmsWidgetDialog;
41 import org.opencms.workplace.CmsWidgetDialogParameter;
42 import org.opencms.workplace.CmsWorkplaceSettings;
43
44 import java.util.Map JavaDoc;
45
46 import javax.servlet.http.HttpServletRequest JavaDoc;
47 import javax.servlet.http.HttpServletResponse JavaDoc;
48 import javax.servlet.jsp.PageContext JavaDoc;
49
50 /**
51  * Class to show the module overview.<p>
52  *
53  * @author Michael Emmerich
54  *
55  * @version $Revision: 1.10 $
56  *
57  * @since 6.0.0
58  */

59 public class CmsModulesOverview extends CmsWidgetDialog {
60
61     /** The dialog type. */
62     public static final String JavaDoc DIALOG_TYPE = "ModulesOverview";
63
64     /** Defines which pages are valid for this dialog. */
65     public static final String JavaDoc[] PAGES = {"page1"};
66
67     /** The module object that is edited on this dialog. */
68     private CmsModule m_module;
69
70     /** Modulename. */
71     private String JavaDoc m_paramModule;
72
73     /**
74      * Public constructor with JSP action element.<p>
75      *
76      * @param jsp an initialized JSP action element
77      */

78     public CmsModulesOverview(CmsJspActionElement jsp) {
79
80         super(jsp);
81     }
82
83     /**
84      * Public constructor with JSP variables.<p>
85      *
86      * @param context the JSP page context
87      * @param req the JSP request
88      * @param res the JSP response
89      */

90     public CmsModulesOverview(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
91
92         this(new CmsJspActionElement(context, req, res));
93     }
94
95     /**
96      * Commits the edited module.<p>
97      */

98     public void actionCommit() {
99
100         // noop
101
}
102
103     /**
104      * Builds the HTML for the dialog form.<p>
105      *
106      * @return the HTML for the dialog form
107      */

108     public String JavaDoc buildDialogForm() {
109
110         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
111
112         try {
113
114             // create the dialog HTML
115
result.append(createDialogHtml(getParamPage()));
116
117         } catch (Throwable JavaDoc t) {
118             // TODO: Error handling
119
}
120         return result.toString();
121     }
122
123     /**
124      * @see org.opencms.workplace.CmsDialog#getCancelAction()
125      */

126     public String JavaDoc getCancelAction() {
127
128         // set the default action
129
setParamPage((String JavaDoc)getPages().get(0));
130
131         return DIALOG_SET;
132     }
133
134     /**
135      * Gets the module parameter.<p>
136      *
137      * @return the module parameter
138      */

139     public String JavaDoc getParamModule() {
140
141         return m_paramModule;
142     }
143
144     /**
145      * Sets the module parameter.<p>
146      * @param paramModule the module parameter
147      */

148     public void setParamModule(String JavaDoc paramModule) {
149
150         m_paramModule = paramModule;
151     }
152
153     /**
154      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
155      *
156      * @param dialog the dialog (page) to get the HTML for
157      * @return the dialog HTML for all defined widgets of the named dialog (page)
158      */

159     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
160
161         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
162
163         // create table
164
result.append(createWidgetTableStart());
165
166         // show error header once if there were validation errors
167
result.append(createWidgetErrorHeader());
168
169         if (dialog.equals(PAGES[0])) {
170             result.append(dialogBlockStart(key("label.moduleinformation")));
171             result.append(createWidgetTableStart());
172             result.append(createDialogRowsHtml(0, 5));
173             result.append(createWidgetTableEnd());
174             result.append(dialogBlockEnd());
175             result.append(dialogBlockStart(key("label.modulecreator")));
176             result.append(createWidgetTableStart());
177             result.append(createDialogRowsHtml(6, 7));
178             result.append(createWidgetTableEnd());
179             result.append(dialogBlockEnd());
180         }
181
182         // close table
183
result.append(createWidgetTableEnd());
184
185         return result.toString();
186     }
187
188     /**
189      * Creates the list of widgets for this dialog.<p>
190      */

191     protected void defineWidgets() {
192
193         initModule();
194
195         addWidget(new CmsWidgetDialogParameter(m_module, "name", PAGES[0], new CmsDisplayWidget()));
196         addWidget(new CmsWidgetDialogParameter(m_module, "niceName", PAGES[0], new CmsDisplayWidget()));
197         addWidget(new CmsWidgetDialogParameter(m_module, "description", PAGES[0], new CmsDisplayWidget()));
198         addWidget(new CmsWidgetDialogParameter(m_module, "version.version", PAGES[0], new CmsDisplayWidget()));
199         addWidget(new CmsWidgetDialogParameter(m_module, "group", PAGES[0], new CmsDisplayWidget()));
200         addWidget(new CmsWidgetDialogParameter(m_module, "actionClass", PAGES[0], new CmsDisplayWidget()));
201         addWidget(new CmsWidgetDialogParameter(m_module, "authorName", PAGES[0], new CmsDisplayWidget()));
202         addWidget(new CmsWidgetDialogParameter(m_module, "authorEmail", PAGES[0], new CmsDisplayWidget()));
203
204     }
205
206     /**
207      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
208      */

209     protected String JavaDoc[] getPageArray() {
210
211         return PAGES;
212     }
213
214     /**
215      * @see org.opencms.workplace.CmsWorkplace#initMessages()
216      */

217     protected void initMessages() {
218
219         // add specific dialog resource bundle
220
addMessages(Messages.get().getBundleName());
221         // add default resource bundles
222
super.initMessages();
223     }
224
225     /**
226      * Initializes the module to work with depending on the dialog state and request parameters.<p>
227      */

228     protected void initModule() {
229
230         Object JavaDoc o;
231
232         if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
233             // this is the initial dialog call
234
if (CmsStringUtil.isNotEmpty(m_paramModule)) {
235                 // edit an existing module, get it from manager
236
o = OpenCms.getModuleManager().getModule(m_paramModule);
237             } else {
238                 // create a new module
239
o = null;
240             }
241         } else {
242             // this is not the initial call, get module from session
243
o = getDialogObject();
244         }
245
246         if (!(o instanceof CmsModule)) {
247             // create a new module
248
m_module = new CmsModule();
249
250         } else {
251             // reuse module stored in session
252
m_module = (CmsModule)((CmsModule)o).clone();
253         }
254     }
255
256     /**
257      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
258      */

259     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
260
261         // set the dialog type
262
setParamDialogtype(DIALOG_TYPE);
263
264         super.initWorkplaceRequestValues(settings, request);
265
266         // refresh the list
267
Map JavaDoc objects = (Map JavaDoc)getSettings().getListObject();
268         if (objects != null) {
269             objects.remove(CmsExportpointsList.class.getName());
270             objects.remove(CmsModulesDependenciesList.class.getName());
271         }
272
273         // save the current state of the module (may be changed because of the widget values)
274
setDialogObject(m_module);
275     }
276
277     /**
278      * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
279      */

280     protected void validateParamaters() throws Exception JavaDoc {
281
282         String JavaDoc moduleName = getParamModule();
283         // check module
284
CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
285         if (module == null) {
286             throw new Exception JavaDoc();
287         }
288     }
289 }
290
Popular Tags