KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > accounts > CmsGroupOverviewDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsGroupOverviewDialog.java,v $
3  * Date : $Date: 2006/03/27 14:52:49 $
4  * Version: $Revision: 1.11 $
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.accounts;
33
34 import org.opencms.file.CmsGroup;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsIllegalArgumentException;
38 import org.opencms.util.CmsStringUtil;
39 import org.opencms.util.CmsUUID;
40 import org.opencms.widgets.CmsDisplayWidget;
41 import org.opencms.workplace.CmsWidgetDialog;
42 import org.opencms.workplace.CmsWidgetDialogParameter;
43
44 import java.util.ArrayList 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  * The group overview and group info widget dialog.<p>
52  *
53  * @author Michael Moossen
54  *
55  * @version $Revision: 1.11 $
56  *
57  * @since 6.0.0
58  */

59 public class CmsGroupOverviewDialog extends CmsWidgetDialog {
60
61     /** localized messages Keys prefix. */
62     public static final String JavaDoc KEY_PREFIX = "group.ov";
63
64     /** Defines which pages are valid for this dialog. */
65     public static final String JavaDoc[] PAGES = {"page1"};
66
67     /** Request parameter name for the user id. */
68     public static final String JavaDoc PARAM_GROUPID = "groupid";
69
70     /** The user object that is edited on this dialog. */
71     protected CmsGroup m_group;
72
73     /** Stores the value of the request parameter for the group id. */
74     private String JavaDoc m_paramGroupid;
75
76     /** Auxiliary Property for better representation of the bean parentId property. */
77     private String JavaDoc m_parentGroup;
78
79     /**
80      * Public constructor with JSP action element.<p>
81      *
82      * @param jsp an initialized JSP action element
83      */

84     public CmsGroupOverviewDialog(CmsJspActionElement jsp) {
85
86         super(jsp);
87
88     }
89
90     /**
91      * Public constructor with JSP variables.<p>
92      *
93      * @param context the JSP page context
94      * @param req the JSP request
95      * @param res the JSP response
96      */

97     public CmsGroupOverviewDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
98
99         this(new CmsJspActionElement(context, req, res));
100     }
101
102     /**
103      * Commits the edited group to the db.<p>
104      */

105     public void actionCommit() {
106
107         // no saving needed
108
setCommitErrors(new ArrayList JavaDoc());
109     }
110
111     /**
112      * Returns the user id parameter value.<p>
113      *
114      * @return the user id parameter value
115      */

116     public String JavaDoc getParamGroupid() {
117
118         return m_paramGroupid;
119     }
120
121     /**
122      * Returns the parent Group name.<p>
123      *
124      * @return the parent Group name
125      */

126     public String JavaDoc getParentGroup() {
127
128         return m_parentGroup;
129     }
130
131     /**
132      * Sets the user id parameter value.<p>
133      *
134      * @param userId the user id parameter value
135      */

136     public void setParamGroupid(String JavaDoc userId) {
137
138         m_paramGroupid = userId;
139     }
140
141     /**
142      * Sets the parent Group name.<p>
143      *
144      * @param parentGroup the parent Group name to set
145      */

146     public void setParentGroup(String JavaDoc parentGroup) {
147
148         if (CmsStringUtil.isEmpty(parentGroup) || parentGroup.equals("null") || parentGroup.equals("none")) {
149             parentGroup = null;
150         }
151         if (parentGroup != null) {
152             try {
153                 getCms().readGroup(parentGroup);
154             } catch (CmsException e) {
155                 throw new CmsIllegalArgumentException(e.getMessageContainer());
156             }
157         }
158         m_parentGroup = parentGroup;
159     }
160
161     /**
162      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
163      *
164      * This overwrites the method from the super class to create a layout variation for the widgets.<p>
165      *
166      * @param dialog the dialog (page) to get the HTML for
167      * @return the dialog HTML for all defined widgets of the named dialog (page)
168      */

169     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
170
171         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
172
173         // create widget table
174
result.append(createWidgetTableStart());
175
176         // show error header once if there were validation errors
177
result.append(createWidgetErrorHeader());
178
179         int n = (!isOverview() ? 1 : 3);
180         if (dialog.equals(PAGES[0])) {
181             // create the widgets for the first dialog page
182
result.append(dialogBlockStart(key(Messages.GUI_GROUP_EDITOR_LABEL_IDENTIFICATION_BLOCK_0)));
183             result.append(createWidgetTableStart());
184             result.append(createDialogRowsHtml(0, n));
185             result.append(createWidgetTableEnd());
186             result.append(dialogBlockEnd());
187             if (!isOverview()) {
188                 result.append(createWidgetTableEnd());
189                 return result.toString();
190             }
191             result.append(dialogBlockStart(key(Messages.GUI_GROUP_EDITOR_LABEL_FLAGS_BLOCK_0)));
192             result.append(createWidgetTableStart());
193             result.append(createDialogRowsHtml(4, 6));
194             result.append(createWidgetTableEnd());
195             result.append(dialogBlockEnd());
196         }
197
198         // close widget table
199
result.append(createWidgetTableEnd());
200
201         return result.toString();
202     }
203
204     /**
205      * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd()
206      */

207     protected String JavaDoc defaultActionHtmlEnd() {
208
209         return "";
210     }
211
212     /**
213      * Creates the list of widgets for this dialog.<p>
214      */

215     protected void defineWidgets() {
216
217         // initialize the user object to use for the dialog
218
initGroupObject();
219
220         setKeyPrefix(KEY_PREFIX);
221
222         // widgets to display
223
if (!isOverview()) {
224             addWidget(new CmsWidgetDialogParameter(m_group, "name", PAGES[0], new CmsDisplayWidget()));
225             addWidget(new CmsWidgetDialogParameter(m_group, "description", PAGES[0], new CmsDisplayWidget()));
226         } else {
227             addWidget(new CmsWidgetDialogParameter(m_group, "name", PAGES[0], new CmsDisplayWidget()));
228             addWidget(new CmsWidgetDialogParameter(m_group, "description", PAGES[0], new CmsDisplayWidget()));
229             addWidget(new CmsWidgetDialogParameter(this, "parentGroup", PAGES[0], new CmsDisplayWidget()));
230             addWidget(new CmsWidgetDialogParameter(m_group, "enabled", PAGES[0], new CmsDisplayWidget()));
231             addWidget(new CmsWidgetDialogParameter(m_group, "role", PAGES[0], new CmsDisplayWidget()));
232             addWidget(new CmsWidgetDialogParameter(m_group, "projectManager", PAGES[0], new CmsDisplayWidget()));
233             addWidget(new CmsWidgetDialogParameter(m_group, "projectCoWorker", PAGES[0], new CmsDisplayWidget()));
234         }
235     }
236
237     /**
238      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
239      */

240     protected String JavaDoc[] getPageArray() {
241
242         return PAGES;
243     }
244
245     /**
246      * Initializes the group object.<p>
247      */

248     protected void initGroupObject() {
249
250         try {
251             // edit an existing group, get the group object from db
252
m_group = getCms().readGroup(new CmsUUID(getParamGroupid()));
253             setParentGroup(getCms().readGroup(m_group.getParentId()).getName());
254         } catch (CmsException e) {
255             // should never happen
256
}
257     }
258
259     /**
260      * @see org.opencms.workplace.CmsWorkplace#initMessages()
261      */

262     protected void initMessages() {
263
264         // add specific dialog resource bundle
265
addMessages(Messages.get().getBundleName());
266         // add default resource bundles
267
super.initMessages();
268     }
269
270     /**
271      * Overridden to set the online help path for this dialog.<p>
272      *
273      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement)
274      */

275     protected void initWorkplaceMembers(CmsJspActionElement jsp) {
276
277         super.initWorkplaceMembers(jsp);
278         setOnlineHelpUriCustom("/accounts/groups/overview/");
279     }
280
281     /**
282      * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
283      */

284     protected void validateParamaters() throws Exception JavaDoc {
285
286         // test the needed parameters
287
getCms().readGroup(new CmsUUID(getParamGroupid())).getName();
288     }
289
290     /**
291      * Checks if the group overview has to be displayed.<p>
292      *
293      * @return <code>true</code> if the group overview has to be displayed
294      */

295     private boolean isOverview() {
296
297         return getCurrentToolPath().endsWith("/groups/edit");
298     }
299 }
300
Popular Tags