KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > demos > list > CmsGroupDemo


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.list;
33
34 import org.opencms.file.CmsGroup;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.OpenCms;
38 import org.opencms.widgets.CmsDisplayWidget;
39 import org.opencms.workplace.CmsWidgetDialog;
40 import org.opencms.workplace.CmsWidgetDialogParameter;
41 import org.opencms.workplace.tools.accounts.Messages;
42
43 import java.util.ArrayList JavaDoc;
44
45 import javax.servlet.http.HttpServletRequest JavaDoc;
46 import javax.servlet.http.HttpServletResponse JavaDoc;
47 import javax.servlet.jsp.PageContext JavaDoc;
48
49 /**
50  * The group overview widget dialog.<p>
51  *
52  * @author Michael Moossen
53  *
54  * @version $Revision$
55  *
56  * @since 6.0.0
57  */

58 public class CmsGroupDemo extends CmsWidgetDialog {
59
60     /** Defines which pages are valid for this dialog. */
61     public static final String JavaDoc[] PAGES = {"page1"};
62
63     /** The user object that is edited on this dialog. */
64     protected CmsGroup m_group;
65
66     /**
67      * Public constructor with JSP action element.<p>
68      *
69      * @param jsp an initialized JSP action element
70      */

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

83     public CmsGroupDemo(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
84
85         this(new CmsJspActionElement(context, req, res));
86     }
87
88     /**
89      * Commits the edited group to the db.<p>
90      */

91     public void actionCommit() {
92
93         // no saving needed
94
setCommitErrors(new ArrayList JavaDoc());
95     }
96
97     /**
98      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
99      *
100      * This overwrites the method from the super class to create a layout variation for the widgets.<p>
101      *
102      * @param dialog the dialog (page) to get the HTML for
103      * @return the dialog HTML for all defined widgets of the named dialog (page)
104      */

105     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
106
107         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
108
109         // create widget table
110
result.append(createWidgetTableStart());
111
112         // show error header once if there were validation errors
113
result.append(createWidgetErrorHeader());
114
115         if (dialog.equals(PAGES[0])) {
116             // create the widgets for the first dialog page
117
result.append(dialogBlockStart(key(Messages.GUI_GROUP_EDITOR_LABEL_IDENTIFICATION_BLOCK_0)));
118             result.append(createWidgetTableStart());
119             result.append(createDialogRowsHtml(0, 2));
120             result.append(createWidgetTableEnd());
121             result.append(dialogBlockEnd());
122             result.append(dialogBlockStart(key(Messages.GUI_GROUP_EDITOR_LABEL_FLAGS_BLOCK_0)));
123             result.append(createWidgetTableStart());
124             result.append(createDialogRowsHtml(3, 5));
125             result.append(createWidgetTableEnd());
126             result.append(dialogBlockEnd());
127         }
128
129         // close widget table
130
result.append(createWidgetTableEnd());
131
132         return result.toString();
133     }
134
135     /**
136      * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd()
137      */

138     protected String JavaDoc defaultActionHtmlEnd() {
139
140         return "";
141     }
142
143     /**
144      * Creates the list of widgets for this dialog.<p>
145      */

146     protected void defineWidgets() {
147
148         // initialize the user object to use for the dialog
149
initGroupObject();
150
151         // widgets to display
152
addWidget(new CmsWidgetDialogParameter(m_group, "name", PAGES[0], new CmsDisplayWidget()));
153         addWidget(new CmsWidgetDialogParameter(m_group, "description", PAGES[0], new CmsDisplayWidget()));
154         addWidget(new CmsWidgetDialogParameter(m_group, "enabled", PAGES[0], new CmsDisplayWidget()));
155         addWidget(new CmsWidgetDialogParameter(m_group, "role", PAGES[0], new CmsDisplayWidget()));
156         addWidget(new CmsWidgetDialogParameter(m_group, "projectManager", PAGES[0], new CmsDisplayWidget()));
157         addWidget(new CmsWidgetDialogParameter(m_group, "projectCoWorker", PAGES[0], new CmsDisplayWidget()));
158     }
159
160     /**
161      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
162      */

163     protected String JavaDoc[] getPageArray() {
164
165         return PAGES;
166     }
167
168     /**
169      * Initializes the group object.<p>
170      */

171     protected void initGroupObject() {
172
173         try {
174             m_group = getCms().readGroup(OpenCms.getDefaultUsers().getGroupGuests());
175         } catch (CmsException e) {
176             // should never happen
177
}
178     }
179
180     /**
181      * @see org.opencms.workplace.CmsWorkplace#initMessages()
182      */

183     protected void initMessages() {
184
185         // add specific dialog resource bundle
186
addMessages(Messages.get().getBundleName());
187         addMessages(org.opencms.workplace.demos.list.Messages.get().getBundleName());
188         addMessages(org.opencms.workplace.demos.Messages.get().getBundleName());
189         // add default resource bundles
190
super.initMessages();
191     }
192
193     /**
194      * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
195      */

196     protected void validateParamaters() throws Exception JavaDoc {
197
198         // test the needed parameters
199
getCms().readGroup(OpenCms.getDefaultUsers().getGroupGuests());
200     }
201 }
202
Popular Tags