KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
45 import java.util.Iterator JavaDoc;
46 import java.util.List JavaDoc;
47 import java.util.Map JavaDoc;
48 import java.util.TreeMap JavaDoc;
49
50 import javax.servlet.http.HttpServletRequest JavaDoc;
51 import javax.servlet.http.HttpServletResponse JavaDoc;
52 import javax.servlet.jsp.PageContext JavaDoc;
53
54 /**
55  * A basic example and proof-of-concept on how to use OpenCms widgets within a custom build form
56  * without XML contents.<p>
57  *
58  * @author Alexander Kandzior
59  *
60  * @version $Revision$
61  *
62  * @since 6.0.0
63  */

64 public class CmsAdminWidgetDemo5 extends CmsWidgetDialog {
65
66     /** The dialog type. */
67     public static final String JavaDoc DIALOG_TYPE = "widgetdemo5";
68
69     /** The OpenCms context info object used for the job info. */
70     CmsContextInfo m_contextInfo;
71
72     /** The job info object that is edited on this dialog. */
73     CmsScheduledJobInfo m_jobInfo;
74
75     /**
76      * Public constructor with JSP action element.<p>
77      *
78      * @param jsp an initialized JSP action element
79      */

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

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

100     public void actionCommit() {
101
102         // not implemented for this demo
103

104     }
105
106     /**
107      * Builds the HTML for the demo5 form.<p>
108      *
109      * @return the HTML for the demo5 form
110      */

111     public String JavaDoc buildDemo5Form() {
112
113         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
114
115         try {
116             // create the dialog HTML
117
result.append(createDialogHtml());
118         } catch (Throwable JavaDoc t) {
119             // since this is just a simple example...
120
t.printStackTrace();
121         }
122         return result.toString();
123     }
124
125     /**
126      * Creates the list of widgets for this dialog.<p>
127      */

128     protected void defineWidgets() {
129
130         m_jobInfo = new CmsScheduledJobInfo();
131         m_contextInfo = new CmsContextInfo();
132
133         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "jobName", new CmsInputWidget()));
134         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "className", new CmsInputWidget()));
135         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "cronExpression", new CmsInputWidget()));
136
137         addWidget(new CmsWidgetDialogParameter(m_contextInfo, "userName", new CmsInputWidget()));
138         addWidget(new CmsWidgetDialogParameter(m_contextInfo, "projectName", new CmsInputWidget()));
139         addWidget(new CmsWidgetDialogParameter(m_contextInfo, "siteRoot", new CmsVfsFileWidget()));
140         addWidget(new CmsWidgetDialogParameter(m_contextInfo, "requestedUri", new CmsVfsFileWidget()));
141         addWidget(new CmsWidgetDialogParameter(m_contextInfo, "localeName", new CmsInputWidget()));
142         addWidget(new CmsWidgetDialogParameter(m_contextInfo, "encoding", new CmsInputWidget()));
143         addWidget(new CmsWidgetDialogParameter(m_contextInfo, "remoteAddr", new CmsInputWidget()));
144
145         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "reuseInstance", new CmsCheckboxWidget()));
146         addWidget(new CmsWidgetDialogParameter(m_jobInfo, "active", new CmsCheckboxWidget()));
147
148         List JavaDoc testList = new ArrayList JavaDoc();
149         testList.add("value1");
150         testList.add("another value");
151         addWidget(new CmsWidgetDialogParameter(testList, "theList", new CmsInputWidget()));
152
153         Map JavaDoc testMap = new TreeMap JavaDoc();
154         testMap.put("key1", "value1");
155         testMap.put("key2", "another value");
156         addWidget(new CmsWidgetDialogParameter(testMap, "theMap", new CmsInputWidget()));
157     }
158
159     /**
160      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
161      */

162     protected String JavaDoc[] getPageArray() {
163
164         return new String JavaDoc[] {"page1"};
165     }
166
167     /**
168      * @see org.opencms.workplace.CmsWidgetDialog#initMessages()
169      */

170     protected void initMessages() {
171
172         // add specific dialog resource bundle
173
addMessages(Messages.get().getBundleName());
174         // add default resource bundles
175
addMessages(org.opencms.workplace.demos.Messages.get().getBundleName());
176         super.initMessages();
177     }
178
179     /**
180      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
181      */

182     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
183
184         // set the dialog type
185
setParamDialogtype(DIALOG_TYPE);
186
187         // fill the parameter values in the get/set methods
188
fillParamValues(request);
189
190         // fill the widget map
191
defineWidgets();
192         fillWidgetValues(request);
193
194         // set the action for the JSP switch
195
if (DIALOG_SAVE.equals(getParamAction())) {
196             // ok button pressed
197
setAction(ACTION_SAVE);
198             List JavaDoc errors = commitWidgetValues();
199             if (errors.size() > 0) {
200                 Iterator JavaDoc i = errors.iterator();
201                 while (i.hasNext()) {
202                     Exception JavaDoc e = (Exception JavaDoc)i.next();
203                     System.err.println(e.getMessage());
204                     if (e.getCause() != null) {
205                         System.err.println("Cause: " + e.getCause().getMessage());
206                     }
207                 }
208                 setAction(ACTION_DEFAULT);
209             }
210         } else if (DIALOG_OK.equals(getParamAction())) {
211             // ok button pressed
212
setAction(ACTION_CANCEL);
213         } else if (DIALOG_CANCEL.equals(getParamAction())) {
214             // cancel button pressed
215
setAction(ACTION_CANCEL);
216         } else if (EDITOR_ACTION_ELEMENT_ADD.equals(getParamAction())) {
217             setAction(ACTION_ELEMENT_ADD);
218             actionToggleElement();
219             setAction(ACTION_DEFAULT);
220         } else if (EDITOR_ACTION_ELEMENT_REMOVE.equals(getParamAction())) {
221             setAction(ACTION_ELEMENT_REMOVE);
222             actionToggleElement();
223             setAction(ACTION_DEFAULT);
224         } else {
225             // set the default action
226
setAction(ACTION_DEFAULT);
227         }
228     }
229 }
Popular Tags