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.CmsRuntimeException;
037: import org.opencms.workplace.list.A_CmsListDialog;
038: import org.opencms.workplace.list.CmsListColumnAlignEnum;
039: import org.opencms.workplace.list.CmsListColumnDefinition;
040: import org.opencms.workplace.list.CmsListDefaultAction;
041: import org.opencms.workplace.list.CmsListDirectAction;
042: import org.opencms.workplace.list.CmsListItem;
043: import org.opencms.workplace.list.CmsListMetadata;
044: import org.opencms.workplace.list.CmsListMultiAction;
045: import org.opencms.workplace.list.CmsListOrderEnum;
046: import org.opencms.workplace.tools.accounts.A_CmsUsersList;
047: import org.opencms.workplace.tools.accounts.Messages;
048:
049: import java.util.ArrayList;
050: import java.util.HashMap;
051: import java.util.HashSet;
052: import java.util.Iterator;
053: import java.util.List;
054: import java.util.Map;
055: import java.util.Set;
056:
057: import javax.servlet.http.HttpServletRequest;
058: import javax.servlet.http.HttpServletResponse;
059: import javax.servlet.jsp.PageContext;
060:
061: /**
062: * Not Usergroups view.<p>
063: *
064: * @author Michael Moossen
065: *
066: * @version $Revision$
067: *
068: * @since 6.0.0
069: */
070: public class CmsListDemo16b extends A_CmsListDialog {
071:
072: /** list action id constant. */
073: public static final String LIST_ACTION_ADD = "aa";
074:
075: /** list action id constant. */
076: public static final String LIST_ACTION_ICON = "ai";
077:
078: /** list action id constant. */
079: public static final String LIST_ACTION_STATE = "as";
080:
081: /** list column id constant. */
082: public static final String LIST_COLUMN_FULLNAME = "cf";
083:
084: /** list column id constant. */
085: public static final String LIST_COLUMN_ICON = "ci";
086:
087: /** list column id constant. */
088: public static final String LIST_COLUMN_LOGIN = "cn";
089:
090: /** list column id constant. */
091: public static final String LIST_COLUMN_STATE = "cs";
092:
093: /** list action id constant. */
094: public static final String LIST_DEFACTION_ADD = "da";
095:
096: /** list id constant. */
097: public static final String LIST_ID = "lngu";
098:
099: /** list action id constant. */
100: public static final String LIST_MACTION_ADD = "ma";
101:
102: /** the list data. */
103: public static Map usersOut = new HashMap();
104:
105: /** a set of action id's to use for adding. */
106: protected static Set m_addActionIds = new HashSet();
107:
108: /**
109: * default constructor.<p>
110: *
111: * @param jsp an initialized JSP action element
112: */
113: public CmsListDemo16b(CmsJspActionElement jsp) {
114:
115: super (jsp, LIST_ID, Messages.get().container(
116: Messages.GUI_NOTGROUPUSERS_LIST_NAME_0),
117: LIST_COLUMN_LOGIN, CmsListOrderEnum.ORDER_ASCENDING,
118: LIST_COLUMN_LOGIN);
119: }
120:
121: /**
122: * Public constructor with JSP variables.<p>
123: *
124: * @param context the JSP page context
125: * @param req the JSP request
126: * @param res the JSP response
127: */
128: public CmsListDemo16b(PageContext context, HttpServletRequest req,
129: HttpServletResponse res) {
130:
131: this (new CmsJspActionElement(context, req, res));
132: }
133:
134: /**
135: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
136: */
137: public void executeListMultiActions() throws CmsRuntimeException {
138:
139: if (getParamListAction().equals(LIST_MACTION_ADD)) {
140: // execute the remove multiaction
141: Iterator itItems = getSelectedItems().iterator();
142: while (itItems.hasNext()) {
143: CmsListItem listItem = (CmsListItem) itItems.next();
144: CmsUser user = (CmsUser) usersOut.remove(listItem
145: .getId());
146: CmsListDemo16a.usersIn.put(listItem.getId(), user);
147: }
148: } else {
149: throwListUnsupportedActionException();
150: }
151: listSave();
152: }
153:
154: /**
155: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
156: */
157: public void executeListSingleActions() throws CmsRuntimeException {
158:
159: if (LIST_ACTION_ADD.equals(getParamListAction())
160: || getParamListAction().equals(LIST_DEFACTION_ADD)) {
161: CmsListItem listItem = getSelectedItem();
162: CmsUser user = (CmsUser) usersOut.remove(listItem.getId());
163: CmsListDemo16a.usersIn.put(listItem.getId(), user);
164: } else {
165: throwListUnsupportedActionException();
166: }
167: listSave();
168: }
169:
170: /**
171: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
172: */
173: protected void fillDetails(String detailId) {
174:
175: // noop
176: }
177:
178: /**
179: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
180: */
181: protected List getListItems() {
182:
183: List ret = new ArrayList();
184:
185: // get content
186: Iterator itUsers = usersOut.values().iterator();
187: while (itUsers.hasNext()) {
188: CmsUser user = (CmsUser) itUsers.next();
189: CmsListItem item = getList().newItem(
190: user.getId().toString());
191: item.set(LIST_COLUMN_LOGIN, user.getName());
192: item.set(LIST_COLUMN_FULLNAME, user.getFullName());
193: ret.add(item);
194: }
195:
196: return ret;
197: }
198:
199: /**
200: * @see org.opencms.workplace.CmsWorkplace#initMessages()
201: */
202: protected void initMessages() {
203:
204: // add specific dialog resource bundle
205: addMessages(Messages.get().getBundleName());
206: // add default resource bundles
207: addMessages(org.opencms.workplace.demos.list.Messages.get()
208: .getBundleName());
209: addMessages(org.opencms.workplace.demos.Messages.get()
210: .getBundleName());
211: super .initMessages();
212: }
213:
214: /**
215: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
216: */
217: protected void setColumns(CmsListMetadata metadata) {
218:
219: // create column for icon display
220: CmsListColumnDefinition iconCol = new CmsListColumnDefinition(
221: LIST_COLUMN_ICON);
222: iconCol.setName(Messages.get().container(
223: Messages.GUI_USERS_LIST_COLS_ICON_0));
224: iconCol.setHelpText(Messages.get().container(
225: Messages.GUI_USERS_LIST_COLS_ICON_HELP_0));
226: iconCol.setWidth("20");
227: iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
228: iconCol.setSorteable(false);
229: // set icon action
230: CmsListDirectAction iconAction = new CmsListDirectAction(
231: LIST_ACTION_ICON);
232: iconAction.setName(Messages.get().container(
233: Messages.GUI_USERS_LIST_AVAILABLE_NAME_0));
234: iconAction.setHelpText(Messages.get().container(
235: Messages.GUI_USERS_LIST_AVAILABLE_HELP_0));
236: iconAction
237: .setIconPath(A_CmsUsersList.PATH_BUTTONS + "user.png");
238: iconAction.setEnabled(false);
239: iconCol.addDirectAction(iconAction);
240: // add it to the list definition
241: metadata.addColumn(iconCol);
242:
243: // create column for state change
244: CmsListColumnDefinition stateCol = new CmsListColumnDefinition(
245: LIST_COLUMN_STATE);
246: stateCol.setName(Messages.get().container(
247: Messages.GUI_USERS_LIST_COLS_STATE_0));
248: stateCol.setHelpText(Messages.get().container(
249: Messages.GUI_USERS_LIST_COLS_STATE_HELP_0));
250: stateCol.setWidth("20");
251: stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
252: stateCol.setSorteable(false);
253: // add add action
254: CmsListDirectAction stateAction = new CmsListDirectAction(
255: LIST_ACTION_ADD);
256: stateAction.setName(Messages.get().container(
257: Messages.GUI_USERS_LIST_DEFACTION_ADD_NAME_0));
258: stateAction.setHelpText(Messages.get().container(
259: Messages.GUI_USERS_LIST_DEFACTION_ADD_HELP_0));
260: stateAction.setIconPath(ICON_ADD);
261: stateCol.addDirectAction(stateAction);
262: // add it to the list definition
263: metadata.addColumn(stateCol);
264:
265: // create column for login
266: CmsListColumnDefinition loginCol = new CmsListColumnDefinition(
267: LIST_COLUMN_LOGIN);
268: loginCol.setName(Messages.get().container(
269: Messages.GUI_USERS_LIST_COLS_LOGIN_0));
270: loginCol.setWidth("35%");
271: // add add action
272: CmsListDefaultAction addAction = new CmsListDefaultAction(
273: LIST_DEFACTION_ADD);
274: addAction.setName(Messages.get().container(
275: Messages.GUI_USERS_LIST_DEFACTION_ADD_NAME_0));
276: addAction.setHelpText(Messages.get().container(
277: Messages.GUI_USERS_LIST_DEFACTION_ADD_HELP_0));
278: loginCol.addDefaultAction(addAction);
279: // add it to the list definition
280: metadata.addColumn(loginCol);
281:
282: // create column for fullname
283: CmsListColumnDefinition fullnameCol = new CmsListColumnDefinition(
284: LIST_COLUMN_FULLNAME);
285: fullnameCol.setName(Messages.get().container(
286: Messages.GUI_USERS_LIST_COLS_FULLNAME_0));
287: fullnameCol.setWidth("65%");
288: fullnameCol.setTextWrapping(true);
289: // add it to the list definition
290: metadata.addColumn(fullnameCol);
291: }
292:
293: /**
294: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
295: */
296: protected void setIndependentActions(CmsListMetadata metadata) {
297:
298: // noop
299: }
300:
301: /**
302: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
303: */
304: protected void setMultiActions(CmsListMetadata metadata) {
305:
306: // add add multi action
307: CmsListMultiAction addMultiAction = new CmsListMultiAction(
308: LIST_MACTION_ADD);
309: addMultiAction.setName(Messages.get().container(
310: Messages.GUI_USERS_LIST_MACTION_ADD_NAME_0));
311: addMultiAction.setHelpText(Messages.get().container(
312: Messages.GUI_USERS_LIST_MACTION_ADD_HELP_0));
313: addMultiAction.setConfirmationMessage(Messages.get().container(
314: Messages.GUI_USERS_LIST_MACTION_ADD_CONF_0));
315: addMultiAction.setIconPath(ICON_MULTI_ADD);
316: metadata.addMultiAction(addMultiAction);
317: }
318: }
|