KickJava   Java API By Example, From Geeks To Geeks.

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


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.widgets.CmsCheckboxWidget;
36 import org.opencms.widgets.CmsImageGalleryWidget;
37 import org.opencms.widgets.CmsInputWidget;
38 import org.opencms.widgets.CmsTextareaWidget;
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
48 import javax.servlet.http.HttpServletRequest JavaDoc;
49 import javax.servlet.http.HttpServletResponse JavaDoc;
50 import javax.servlet.jsp.PageContext JavaDoc;
51
52 /**
53  * A basic example and proof-of-concept on how to use OpenCms widgets within a custom build form
54  * without XML contents.<p>
55  *
56  * @author Alexander Kandzior
57  *
58  * @version $Revision$
59  *
60  * @since 6.0.0
61  */

62 public class CmsAdminWidgetDemo1 extends CmsWidgetDialog {
63
64     /** The dialog type. */
65     public static final String JavaDoc DIALOG_TYPE = "widgetdemo1";
66
67     /**
68      * Public constructor with JSP action element.<p>
69      *
70      * @param jsp an initialized JSP action element
71      */

72     public CmsAdminWidgetDemo1(CmsJspActionElement jsp) {
73
74         super(jsp);
75     }
76
77     /**
78      * Public constructor with JSP variables.<p>
79      *
80      * @param context the JSP page context
81      * @param req the JSP request
82      * @param res the JSP response
83      */

84     public CmsAdminWidgetDemo1(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
85
86         this(new CmsJspActionElement(context, req, res));
87     }
88
89     /**
90      * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
91      */

92     public void actionCommit() {
93
94         // not implemented for this demo
95

96     }
97
98     /**
99      * Builds the HTML for the demo1 form.<p>
100      *
101      * @return the HTML for the demo1 form
102      */

103     public String JavaDoc buildDemo1Form() {
104
105         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc(512);
106
107         try {
108
109             retValue.append("<table class=\"xmlTable\">");
110
111             Iterator JavaDoc i = getWidgets().iterator();
112             while (i.hasNext()) {
113
114                 // get the current widget base definition
115
CmsWidgetDialogParameter base = (CmsWidgetDialogParameter)i.next();
116                 List JavaDoc sequence = (List JavaDoc)getParameters().get(base.getName());
117                 int count = sequence.size();
118
119                 if ((count < 1) && (base.getMinOccurs() > 0)) {
120                     // no parameter with the value present, but also not optional: use base as parameter
121
sequence = new ArrayList JavaDoc();
122                     sequence.add(base);
123                 }
124
125                 Iterator JavaDoc j = sequence.iterator();
126                 while (j.hasNext()) {
127                     CmsWidgetDialogParameter param = (CmsWidgetDialogParameter)j.next();
128                     retValue.append("<tr>\n");
129                     retValue.append(getWidget(param));
130                     retValue.append("</tr>\n");
131                 }
132             }
133
134             retValue.append("</table>\n");
135
136         } catch (Exception JavaDoc e) {
137             e.printStackTrace(System.err);
138         }
139
140         return retValue.toString();
141     }
142
143     /**
144      * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
145      */

146     protected void defineWidgets() {
147
148         addWidget(new CmsWidgetDialogParameter("stringwidget", new CmsInputWidget()));
149         addWidget(new CmsWidgetDialogParameter("textwidget", new CmsTextareaWidget()));
150         addWidget(new CmsWidgetDialogParameter("boolwidget", new CmsCheckboxWidget()));
151         addWidget(new CmsWidgetDialogParameter("vfsfilewidget", new CmsVfsFileWidget()));
152         addWidget(new CmsWidgetDialogParameter("imagegalwidget", new CmsImageGalleryWidget()));
153     }
154
155     /**
156      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
157      */

158     protected String JavaDoc[] getPageArray() {
159
160         return new String JavaDoc[] {"page1"};
161     }
162
163     /**
164      * @see org.opencms.workplace.CmsWidgetDialog#initMessages()
165      */

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

178     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
179
180         // set the dialog type
181
setParamDialogtype(DIALOG_TYPE);
182
183         // fill the parameter values in the get/set methods
184
fillParamValues(request);
185
186         // fill the widget map
187
defineWidgets();
188         fillWidgetValues(request);
189
190         // set the action for the JSP switch
191
if (DIALOG_SAVE.equals(getParamAction())) {
192             // ok button pressed
193
setAction(ACTION_SAVE);
194         } else if (DIALOG_OK.equals(getParamAction())) {
195             // ok button pressed
196
setAction(ACTION_CANCEL);
197         } else if (DIALOG_CANCEL.equals(getParamAction())) {
198             // cancel button pressed
199
setAction(ACTION_CANCEL);
200         } else {
201             // set the default action
202
setAction(ACTION_DEFAULT);
203         }
204     }
205 }
206
Popular Tags