KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > demos > widget > CmsAdminWidgetDemo9


1 /*
2  * File : $Source$
3  * Date : $Date$
4  * Version: $Revision$
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.demos.widget;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.CmsContextInfo;
36 import org.opencms.scheduler.CmsScheduledJobInfo;
37 import org.opencms.widgets.CmsCheckboxWidget;
38 import org.opencms.widgets.CmsInputWidget;
39 import org.opencms.widgets.CmsVfsFileWidget;
40 import org.opencms.workplace.CmsWidgetDialog;
41 import org.opencms.workplace.CmsWidgetDialogParameter;
42 import org.opencms.workplace.CmsWorkplaceSettings;
43
44 import javax.servlet.http.HttpServletRequest JavaDoc;
45 import javax.servlet.http.HttpServletResponse JavaDoc;
46 import javax.servlet.jsp.PageContext JavaDoc;
47
48 /**
49  * A basic example and proof-of-concept on how to use OpenCms widgets within a custom build form
50  * without XML contents.<p>
51  *
52  * @author Alexander Kandzior
53  *
54  * @version $Revision$
55  *
56  * @since 6.0.0
57  */

58 public class CmsAdminWidgetDemo9 extends CmsWidgetDialog {
59
60     /** The dialog type. */
61     public static final String JavaDoc DIALOG_TYPE = "widgetdemo8";
62
63     /** Defines which pages are valid for this dialog. */
64     public static final String JavaDoc[] PAGES = {"page1", "page2"};
65
66     /** The OpenCms context info object used for the job info. */
67     CmsContextInfo m_contextInfo;
68
69     /** The job info object that is edited on this dialog. */
70     CmsScheduledJobInfo m_jobInfo;
71
72     /**
73      * Public constructor with JSP action element.<p>
74      *
75      * @param jsp an initialized JSP action element
76      */

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

89     public CmsAdminWidgetDemo9(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
90
91         this(new CmsJspActionElement(context, req, res));
92     }
93
94     /**
95      * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
96      */

97     public void actionCommit() {
98
99         // not implemented for this demo
100

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      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
136      *
137      * @param dialog the dialog (page) to get the HTML for
138      * @return the dialog HTML for all defined widgets of the named dialog (page)
139      */

140     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
141
142         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
143
144         // create table
145
result.append(createWidgetTableStart());
146
147         // show error header once if there were validation errors
148
result.append(createWidgetErrorHeader());
149
150         if (dialog.equals(PAGES[0])) {
151             result.append(createDialogRowsHtml(0, 2));
152             result.append(dialogBlockStart("User context"));
153             result.append(createWidgetTableStart());
154             result.append(createDialogRowsHtml(3, 9));
155             result.append(createWidgetTableEnd());
156             result.append(dialogBlockEnd());
157             result.append(createDialogRowsHtml(10, 11));
158         } else if (dialog.equals(PAGES[1])) {
159             result.append(dialogBlockStart("Parameters"));
160             result.append(createWidgetTableStart());
161             result.append(createDialogRowsHtml(12, 12));
162             result.append(createWidgetTableEnd());
163             result.append(dialogBlockEnd());
164         }
165
166         // close table
167
result.append(createWidgetTableEnd());
168
169         return result.toString();
170     }
171
172     /**
173      * Creates the list of widgets for this dialog.<p>
174      */

175     protected void defineWidgets() {
176
177         Object JavaDoc o = getDialogObject();
178
179         // required to read the default values for the optional context parameters
180
CmsContextInfo dC = new CmsContextInfo();
181
182         if (!(o instanceof CmsScheduledJobInfo)) {
183             // create a new job info
184
m_jobInfo = new CmsScheduledJobInfo();
185             m_jobInfo.setContextInfo(dC);
186
187             // add some parameters to check issues with pre-filled maps
188
m_jobInfo.getParameters().put("key1", "value1");
189             m_jobInfo.getParameters().put("key2", "value2");
190
191         } else {
192             // reuse job info object stored in session
193
m_jobInfo = (CmsScheduledJobInfo)o;
194         }
195
196         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "jobName", PAGES[0], new CmsInputWidget()));
197         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "className", PAGES[0], new CmsInputWidget()));
198         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "cronExpression", PAGES[0], new CmsInputWidget()));
199
200         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "contextInfo.userName", PAGES[0], new CmsInputWidget()));
201         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "contextInfo.projectName", PAGES[0], new CmsInputWidget()));
202         addWidget(new CmsWidgetDialogParameter(
203             m_jobInfo,
204             "contextInfo.siteRoot",
205             dC.getSiteRoot(),
206             PAGES[0],
207             new CmsVfsFileWidget(),
208             0,
209             1));
210         addWidget(new CmsWidgetDialogParameter(
211             m_jobInfo,
212             "contextInfo.requestedUri",
213             dC.getRequestedUri(),
214             PAGES[0],
215             new CmsVfsFileWidget(),
216             0,
217             1));
218         addWidget(new CmsWidgetDialogParameter(
219             m_jobInfo,
220             "contextInfo.localeName",
221             dC.getLocaleName(),
222             PAGES[0],
223             new CmsInputWidget(),
224             0,
225             1));
226         addWidget(new CmsWidgetDialogParameter(
227             m_jobInfo,
228             "contextInfo.encoding",
229             dC.getEncoding(),
230             PAGES[0],
231             new CmsInputWidget(),
232             0,
233             1));
234         addWidget(new CmsWidgetDialogParameter(
235             m_jobInfo,
236             "contextInfo.remoteAddr",
237             dC.getRemoteAddr(),
238             PAGES[0],
239             new CmsInputWidget(),
240             0,
241             1));
242
243         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "reuseInstance", PAGES[0], new CmsCheckboxWidget()));
244         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "active", PAGES[0], new CmsCheckboxWidget()));
245
246         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "parameters", PAGES[1], new CmsInputWidget()));
247     }
248
249     /**
250      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
251      */

252     protected String JavaDoc[] getPageArray() {
253
254         return PAGES;
255     }
256
257     /**
258      * @see org.opencms.workplace.CmsWidgetDialog#initMessages()
259      */

260     protected void initMessages() {
261
262         // add specific dialog resource bundle
263
addMessages(Messages.get().getBundleName());
264         // add default resource bundles
265
addMessages(org.opencms.workplace.demos.Messages.get().getBundleName());
266         super.initMessages();
267     }
268
269     /**
270      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
271      */

272     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
273
274         // set the dialog type
275
setParamDialogtype(DIALOG_TYPE);
276
277         super.initWorkplaceRequestValues(settings, request);
278
279         // save the current state of the job (may be changed because of the widget values)
280
setDialogObject(m_jobInfo);
281     }
282 }
283
Popular Tags