001: /*
002: * File : $Source$
003: * Date : $Date$
004: * Version: $Revision$
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.demos.list;
033:
034: import org.opencms.file.CmsUser;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.CmsException;
037: import org.opencms.main.CmsRuntimeException;
038: import org.opencms.main.OpenCms;
039: import org.opencms.workplace.list.A_CmsListDialog;
040: import org.opencms.workplace.list.CmsListColumnAlignEnum;
041: import org.opencms.workplace.list.CmsListColumnDefinition;
042: import org.opencms.workplace.list.CmsListItem;
043: import org.opencms.workplace.list.CmsListMetadata;
044: import org.opencms.workplace.list.CmsListOrderEnum;
045: import org.opencms.workplace.list.CmsListPrintIAction;
046: import org.opencms.workplace.list.CmsListSearchAction;
047: import org.opencms.workplace.tools.accounts.Messages;
048:
049: import java.util.ArrayList;
050: import java.util.Date;
051: import java.util.Iterator;
052: import java.util.List;
053:
054: import javax.servlet.http.HttpServletRequest;
055: import javax.servlet.http.HttpServletResponse;
056: import javax.servlet.jsp.PageContext;
057:
058: /**
059: * User accounts list demo.<p>
060: *
061: * @author Michael Moossen
062: *
063: * @version $Revision$
064: *
065: * @since 6.0.0
066: */
067: public class CmsListDemo3 extends A_CmsListDialog {
068:
069: /** list column id constant. */
070: public static final String LIST_COLUMN_ACTIVATE = "ca";
071:
072: /** list column id constant. */
073: public static final String LIST_COLUMN_EMAIL = "cm";
074:
075: /** list column id constant. */
076: public static final String LIST_COLUMN_LASTLOGIN = "cl";
077:
078: /** list column id constant. */
079: public static final String LIST_COLUMN_LOGIN = "ci";
080:
081: /** list column id constant. */
082: public static final String LIST_COLUMN_NAME = "cn";
083:
084: /** list id constant. */
085: public static final String LIST_ID = "lsu1";
086:
087: /**
088: * Public constructor.<p>
089: *
090: * @param jsp an initialized JSP action element
091: */
092: public CmsListDemo3(CmsJspActionElement jsp) {
093:
094: super (jsp, LIST_ID, Messages.get().container(
095: Messages.GUI_USERS_LIST_NAME_0), LIST_COLUMN_LOGIN,
096: CmsListOrderEnum.ORDER_ASCENDING, LIST_COLUMN_LOGIN);
097: }
098:
099: /**
100: * Public constructor with JSP variables.<p>
101: *
102: * @param context the JSP page context
103: * @param req the JSP request
104: * @param res the JSP response
105: */
106: public CmsListDemo3(PageContext context, HttpServletRequest req,
107: HttpServletResponse res) {
108:
109: this (new CmsJspActionElement(context, req, res));
110: }
111:
112: /**
113: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
114: */
115: public void executeListMultiActions() throws CmsRuntimeException {
116:
117: throwListUnsupportedActionException();
118: }
119:
120: /**
121: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
122: */
123: public void executeListSingleActions() {
124:
125: throwListUnsupportedActionException();
126: }
127:
128: /**
129: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
130: */
131: protected void fillDetails(String detailId) {
132:
133: // noop
134: }
135:
136: /**
137: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
138: */
139: protected List getListItems() throws CmsException {
140:
141: List ret = new ArrayList();
142: // get content
143: List users = OpenCms.getOrgUnitManager().getUsers(getCms(),
144: "/", true);
145: Iterator itUsers = users.iterator();
146: while (itUsers.hasNext()) {
147: CmsUser user = (CmsUser) itUsers.next();
148: CmsListItem item = getList().newItem(
149: user.getId().toString());
150: item.set(LIST_COLUMN_ACTIVATE, Boolean.valueOf(user
151: .isEnabled()));
152: item.set(LIST_COLUMN_LOGIN, user.getName());
153: item.set(LIST_COLUMN_NAME, user.getFullName());
154: item.set(LIST_COLUMN_EMAIL, user.getEmail());
155: item.set(LIST_COLUMN_LASTLOGIN, new Date(user
156: .getLastlogin()));
157: ret.add(item);
158: }
159: return ret;
160: }
161:
162: /**
163: * @see org.opencms.workplace.CmsWorkplace#initMessages()
164: */
165: protected void initMessages() {
166:
167: // add specific dialog resource bundle
168: addMessages(Messages.get().getBundleName());
169: addMessages(org.opencms.workplace.demos.list.Messages.get()
170: .getBundleName());
171: addMessages(org.opencms.workplace.demos.Messages.get()
172: .getBundleName());
173: // add default resource bundles
174: super .initMessages();
175: }
176:
177: /**
178: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
179: */
180: protected void setColumns(CmsListMetadata metadata) {
181:
182: // create column for activation/deactivation
183: CmsListColumnDefinition actCol = new CmsListColumnDefinition(
184: LIST_COLUMN_ACTIVATE);
185: actCol.setName(Messages.get().container(
186: Messages.GUI_USERS_LIST_COLS_ACTIVATE_0));
187: actCol.setWidth("30");
188: actCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
189: actCol.setSorteable(true);
190: metadata.addColumn(actCol);
191:
192: // create column for login
193: CmsListColumnDefinition loginCol = new CmsListColumnDefinition(
194: LIST_COLUMN_LOGIN);
195: loginCol.setName(Messages.get().container(
196: Messages.GUI_USERS_LIST_COLS_LOGIN_0));
197: loginCol.setWidth("20%");
198: loginCol.setSorteable(true);
199: metadata.addColumn(loginCol);
200:
201: // add column for name
202: CmsListColumnDefinition nameCol = new CmsListColumnDefinition(
203: LIST_COLUMN_NAME);
204: nameCol.setName(Messages.get().container(
205: Messages.GUI_USERS_LIST_COLS_USERNAME_0));
206: nameCol.setWidth("30%");
207: nameCol.setSorteable(true);
208: metadata.addColumn(nameCol);
209:
210: // add column for email
211: CmsListColumnDefinition emailCol = new CmsListColumnDefinition(
212: LIST_COLUMN_EMAIL);
213: emailCol.setName(Messages.get().container(
214: Messages.GUI_USERS_LIST_COLS_EMAIL_0));
215: emailCol.setWidth("30%");
216: emailCol.setSorteable(true);
217: metadata.addColumn(emailCol);
218:
219: // add column for last login date
220: CmsListColumnDefinition lastLoginCol = new CmsListColumnDefinition(
221: LIST_COLUMN_LASTLOGIN);
222: lastLoginCol.setName(Messages.get().container(
223: Messages.GUI_USERS_LIST_COLS_LASTLOGIN_0));
224: lastLoginCol.setWidth("20%");
225: lastLoginCol.setSorteable(true);
226: metadata.addColumn(lastLoginCol);
227: }
228:
229: /**
230: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
231: */
232: protected void setIndependentActions(CmsListMetadata metadata) {
233:
234: // noop
235: }
236:
237: /**
238: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
239: */
240: protected void setMultiActions(CmsListMetadata metadata) {
241:
242: // makes the list searchable by several columns
243: CmsListSearchAction searchAction = new CmsListSearchAction(
244: metadata.getColumnDefinition(LIST_COLUMN_LOGIN));
245: searchAction.addColumn(metadata
246: .getColumnDefinition(LIST_COLUMN_EMAIL));
247: metadata.setSearchAction(searchAction);
248:
249: // remove print action
250: metadata.getIndependentAction(
251: CmsListPrintIAction.LIST_ACTION_ID).setVisible(false);
252: }
253:
254: }
|