KickJava   Java API By Example, From Geeks To Geeks.

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


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.CmsUser;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsRuntimeException;
38 import org.opencms.workplace.list.A_CmsListDialog;
39 import org.opencms.workplace.list.CmsListColumnAlignEnum;
40 import org.opencms.workplace.list.CmsListColumnDefinition;
41 import org.opencms.workplace.list.CmsListItem;
42 import org.opencms.workplace.list.CmsListMetadata;
43 import org.opencms.workplace.list.CmsListOrderEnum;
44 import org.opencms.workplace.list.CmsListPrintIAction;
45 import org.opencms.workplace.list.CmsListSearchAction;
46 import org.opencms.workplace.tools.accounts.Messages;
47
48 import java.util.ArrayList JavaDoc;
49 import java.util.Date JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import java.util.List JavaDoc;
52
53 import javax.servlet.http.HttpServletRequest JavaDoc;
54 import javax.servlet.http.HttpServletResponse JavaDoc;
55 import javax.servlet.jsp.PageContext JavaDoc;
56
57 /**
58  * User accounts list demo.<p>
59  *
60  * @author Michael Moossen
61  *
62  * @version $Revision$
63  *
64  * @since 6.0.0
65  */

66 public class CmsListDemo3 extends A_CmsListDialog {
67
68     /** list column id constant. */
69     public static final String JavaDoc LIST_COLUMN_ACTIVATE = "ca";
70
71     /** list column id constant. */
72     public static final String JavaDoc LIST_COLUMN_EMAIL = "cm";
73
74     /** list column id constant. */
75     public static final String JavaDoc LIST_COLUMN_LASTLOGIN = "cl";
76
77     /** list column id constant. */
78     public static final String JavaDoc LIST_COLUMN_LOGIN = "ci";
79
80     /** list column id constant. */
81     public static final String JavaDoc LIST_COLUMN_NAME = "cn";
82
83     /** list id constant. */
84     public static final String JavaDoc LIST_ID = "lsu1";
85
86     /**
87      * Public constructor.<p>
88      *
89      * @param jsp an initialized JSP action element
90      */

91     public CmsListDemo3(CmsJspActionElement jsp) {
92
93         super(
94             jsp,
95             LIST_ID,
96             Messages.get().container(Messages.GUI_USERS_LIST_NAME_0),
97             LIST_COLUMN_LOGIN,
98             CmsListOrderEnum.ORDER_ASCENDING,
99             LIST_COLUMN_LOGIN);
100     }
101
102     /**
103      * Public constructor with JSP variables.<p>
104      *
105      * @param context the JSP page context
106      * @param req the JSP request
107      * @param res the JSP response
108      */

109     public CmsListDemo3(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
110
111         this(new CmsJspActionElement(context, req, res));
112     }
113
114     /**
115      * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
116      */

117     public void executeListMultiActions() throws CmsRuntimeException {
118
119         throwListUnsupportedActionException();
120     }
121
122     /**
123      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
124      */

125     public void executeListSingleActions() {
126
127         throwListUnsupportedActionException();
128     }
129
130     /**
131      * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
132      */

133     protected void fillDetails(String JavaDoc detailId) {
134
135         // noop
136
}
137
138     /**
139      * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
140      */

141     protected List JavaDoc getListItems() throws CmsException {
142
143         List JavaDoc ret = new ArrayList JavaDoc();
144         // get content
145
List JavaDoc users = getCms().getUsers(CmsUser.USER_TYPE_SYSTEMUSER);
146         Iterator JavaDoc itUsers = users.iterator();
147         while (itUsers.hasNext()) {
148             CmsUser user = (CmsUser)itUsers.next();
149             CmsListItem item = getList().newItem(user.getId().toString());
150             item.set(LIST_COLUMN_ACTIVATE, Boolean.valueOf(user.isEnabled()));
151             item.set(LIST_COLUMN_LOGIN, user.getName());
152             item.set(LIST_COLUMN_NAME, user.getFullName());
153             item.set(LIST_COLUMN_EMAIL, user.getEmail());
154             item.set(LIST_COLUMN_LASTLOGIN, new Date JavaDoc(user.getLastlogin()));
155             ret.add(item);
156         }
157         return ret;
158     }
159
160     /**
161      * @see org.opencms.workplace.CmsWorkplace#initMessages()
162      */

163     protected void initMessages() {
164
165         // add specific dialog resource bundle
166
addMessages(Messages.get().getBundleName());
167         addMessages(org.opencms.workplace.demos.list.Messages.get().getBundleName());
168         addMessages(org.opencms.workplace.demos.Messages.get().getBundleName());
169         // add default resource bundles
170
super.initMessages();
171     }
172
173     /**
174      * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
175      */

176     protected void setColumns(CmsListMetadata metadata) {
177
178         // create column for activation/deactivation
179
CmsListColumnDefinition actCol = new CmsListColumnDefinition(LIST_COLUMN_ACTIVATE);
180         actCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_ACTIVATE_0));
181         actCol.setWidth("30");
182         actCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
183         actCol.setSorteable(true);
184         metadata.addColumn(actCol);
185
186         // create column for login
187
CmsListColumnDefinition loginCol = new CmsListColumnDefinition(LIST_COLUMN_LOGIN);
188         loginCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_LOGIN_0));
189         loginCol.setWidth("20%");
190         loginCol.setSorteable(true);
191         metadata.addColumn(loginCol);
192
193         // add column for name
194
CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_NAME);
195         nameCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_USERNAME_0));
196         nameCol.setWidth("30%");
197         nameCol.setSorteable(true);
198         metadata.addColumn(nameCol);
199
200         // add column for email
201
CmsListColumnDefinition emailCol = new CmsListColumnDefinition(LIST_COLUMN_EMAIL);
202         emailCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_EMAIL_0));
203         emailCol.setWidth("30%");
204         emailCol.setSorteable(true);
205         metadata.addColumn(emailCol);
206
207         // add column for last login date
208
CmsListColumnDefinition lastLoginCol = new CmsListColumnDefinition(LIST_COLUMN_LASTLOGIN);
209         lastLoginCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_LASTLOGIN_0));
210         lastLoginCol.setWidth("20%");
211         lastLoginCol.setSorteable(true);
212         metadata.addColumn(lastLoginCol);
213     }
214
215     /**
216      * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
217      */

218     protected void setIndependentActions(CmsListMetadata metadata) {
219
220         // noop
221
}
222
223     /**
224      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
225      */

226     protected void setMultiActions(CmsListMetadata metadata) {
227
228         // makes the list searchable by several columns
229
CmsListSearchAction searchAction = new CmsListSearchAction(metadata.getColumnDefinition(LIST_COLUMN_LOGIN));
230         searchAction.addColumn(metadata.getColumnDefinition(LIST_COLUMN_EMAIL));
231         metadata.setSearchAction(searchAction);
232
233         // remove print action
234
metadata.getIndependentAction(CmsListPrintIAction.LIST_ACTION_ID).setVisible(false);
235     }
236
237 }
Popular Tags