KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/A_CmsUserGroupsList.java,v $
3  * Date : $Date: 2006/03/27 14:52:49 $
4  * Version: $Revision: 1.18 $
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.i18n.CmsMessageContainer;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.CmsException;
38 import org.opencms.util.CmsUUID;
39 import org.opencms.workplace.list.A_CmsListDialog;
40 import org.opencms.workplace.list.CmsHtmlList;
41 import org.opencms.workplace.list.CmsListColumnAlignEnum;
42 import org.opencms.workplace.list.CmsListColumnDefinition;
43 import org.opencms.workplace.list.CmsListItem;
44 import org.opencms.workplace.list.CmsListMetadata;
45 import org.opencms.workplace.list.CmsListOrderEnum;
46 import org.opencms.workplace.list.I_CmsListDirectAction;
47
48 import java.util.ArrayList JavaDoc;
49 import java.util.Iterator JavaDoc;
50 import java.util.List JavaDoc;
51
52 /**
53  * Generalized user groups view.<p>
54  *
55  * @author Michael Moossen
56  *
57  * @version $Revision: 1.18 $
58  *
59  * @since 6.0.0
60  */

61 public abstract class A_CmsUserGroupsList extends A_CmsListDialog {
62
63     /** list action id constant. */
64     public static final String JavaDoc LIST_ACTION_ICON = "ai";
65
66     /** list action id constant. */
67     public static final String JavaDoc LIST_ACTION_ICON_DIRECT = "aid";
68
69     /** list action id constant. */
70     public static final String JavaDoc LIST_ACTION_ICON_INDIRECT = "aii";
71
72     /** list action id constant. */
73     public static final String JavaDoc LIST_ACTION_STATE_DIRECT = "asd";
74
75     /** list action id constant. */
76     public static final String JavaDoc LIST_ACTION_STATE_INDIRECT = "asi";
77
78     /** list column id constant. */
79     public static final String JavaDoc LIST_COLUMN_DESCRIPTION = "cd";
80
81     /** list column id constant. */
82     public static final String JavaDoc LIST_COLUMN_ICON = "ci";
83
84     /** list column id constant. */
85     public static final String JavaDoc LIST_COLUMN_NAME = "cn";
86
87     /** list column id constant. */
88     public static final String JavaDoc LIST_COLUMN_STATE = "cs";
89
90     /** Stores the value of the request parameter for the user id. */
91     private String JavaDoc m_paramUserid;
92
93     /** Stores the value of the request parameter for the user name. */
94     private String JavaDoc m_paramUsername;
95
96     /**
97      * Public constructor.<p>
98      *
99      * @param jsp an initialized JSP action element
100      * @param listId the id of the list
101      * @param listName the name of the list
102      * @param searchable searchable flag
103      */

104     protected A_CmsUserGroupsList(
105         CmsJspActionElement jsp,
106         String JavaDoc listId,
107         CmsMessageContainer listName,
108         boolean searchable) {
109
110         super(jsp, listId, listName, LIST_COLUMN_NAME, CmsListOrderEnum.ORDER_ASCENDING, searchable ? LIST_COLUMN_NAME
111         : null);
112     }
113
114     /**
115      * @see org.opencms.workplace.list.A_CmsListDialog#getList()
116      */

117     public CmsHtmlList getList() {
118
119         // assure we have the right username
120
CmsHtmlList list = super.getList();
121         if (list != null) {
122             CmsListColumnDefinition col = list.getMetadata().getColumnDefinition(LIST_COLUMN_ICON);
123             if (col != null) {
124                 Iterator JavaDoc it = col.getDirectActions().iterator();
125                 while (it.hasNext()) {
126                     I_CmsListDirectAction action = (I_CmsListDirectAction)it.next();
127                     if (action instanceof CmsGroupStateAction) {
128                         ((CmsGroupStateAction)action).setUserName(m_paramUsername);
129                     }
130                 }
131             }
132         }
133         return list;
134     }
135
136     /**
137      * Returns the user id parameter value.<p>
138      *
139      * @return the user id parameter value
140      */

141     public String JavaDoc getParamUserid() {
142
143         return m_paramUserid;
144     }
145
146     /**
147      * Returns the User name parameter.<p>
148      *
149      * @return the User name paramter
150      */

151     public String JavaDoc getParamUsername() {
152
153         return m_paramUsername;
154     }
155
156     /**
157      * Sets the user id parameter value.<p>
158      *
159      * @param userId the user id parameter value
160      */

161     public void setParamUserid(String JavaDoc userId) {
162
163         m_paramUserid = userId;
164     }
165
166     /**
167      * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
168      */

169     protected void fillDetails(String JavaDoc detailId) {
170
171         // noop
172
}
173
174     /**
175      * Returns a list of groups to display.<p>
176      *
177      * @return a list of <code><{@link CmsGroup}</code>s
178      *
179      * @throws CmsException if something goes wrong
180      */

181     protected abstract List getGroups() throws CmsException;
182
183     /**
184      * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
185      */

186     protected List getListItems() throws CmsException {
187
188         List ret = new ArrayList JavaDoc();
189
190         // get content
191
List groups = getGroups();
192         Iterator JavaDoc itGroups = groups.iterator();
193         while (itGroups.hasNext()) {
194             CmsGroup group = (CmsGroup)itGroups.next();
195             CmsListItem item = getList().newItem(group.getId().toString());
196             item.set(LIST_COLUMN_NAME, group.getName());
197             item.set(LIST_COLUMN_DESCRIPTION, group.getDescription());
198             ret.add(item);
199         }
200
201         return ret;
202     }
203
204     /**
205      * @see org.opencms.workplace.CmsWorkplace#initMessages()
206      */

207     protected void initMessages() {
208
209         // add specific dialog resource bundle
210
addMessages(Messages.get().getBundleName());
211         // add default resource bundles
212
super.initMessages();
213     }
214
215     /**
216      * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
217      */

218     protected void setColumns(CmsListMetadata metadata) {
219
220         // create column for icon display
221
CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON);
222         iconCol.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_ICON_0));
223         iconCol.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_ICON_HELP_0));
224         iconCol.setWidth("20");
225         iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
226         iconCol.setSorteable(false);
227         // add icon actions
228
setIconAction(iconCol);
229         // add it to the list definition
230
metadata.addColumn(iconCol);
231         // add state column and actions
232
setStateActionCol(metadata);
233
234         // create column for name
235
CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_NAME);
236         nameCol.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_NAME_0));
237         nameCol.setWidth("35%");
238         // add default actions
239
setDefaultAction(nameCol);
240
241         // add it to the list definition
242
metadata.addColumn(nameCol);
243
244         // create column for description
245
CmsListColumnDefinition descCol = new CmsListColumnDefinition(LIST_COLUMN_DESCRIPTION);
246         descCol.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_DESCRIPTION_0));
247         descCol.setWidth("65%");
248         descCol.setTextWrapping(true);
249         // add it to the list definition
250
metadata.addColumn(descCol);
251     }
252
253     /**
254      * Sets the optional login default action.<p>
255      *
256      * @param nameCol the group name column
257      */

258     protected abstract void setDefaultAction(CmsListColumnDefinition nameCol);
259
260     /**
261      * Sets the needed icon action(s).<p>
262      *
263      * @param iconCol the list column for edition.
264      */

265     protected abstract void setIconAction(CmsListColumnDefinition iconCol);
266
267     /**
268      * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
269      */

270     protected void setIndependentActions(CmsListMetadata metadata) {
271
272         // noop
273
}
274
275     /**
276      * Sets the optional state change action column.<p>
277      *
278      * @param metadata the list metadata object
279      */

280     protected abstract void setStateActionCol(CmsListMetadata metadata);
281
282     /**
283      * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
284      */

285     protected void validateParamaters() throws Exception JavaDoc {
286
287         // test the needed parameters
288
m_paramUsername = getCms().readUser(new CmsUUID(getParamUserid())).getName();
289     }
290 }
291
Popular Tags