KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > workplace > broadcast > CmsSessionsList


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/broadcast/CmsSessionsList.java,v $
3  * Date : $Date: 2006/03/27 14:52:49 $
4  * Version: $Revision: 1.14 $
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.workplace.broadcast;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.CmsSessionInfo;
36 import org.opencms.main.OpenCms;
37 import org.opencms.workplace.CmsDialog;
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.CmsListDateMacroFormatter;
42 import org.opencms.workplace.list.CmsListDefaultAction;
43 import org.opencms.workplace.list.CmsListDirectAction;
44 import org.opencms.workplace.list.CmsListItem;
45 import org.opencms.workplace.list.CmsListItemActionIconComparator;
46 import org.opencms.workplace.list.CmsListMetadata;
47 import org.opencms.workplace.list.CmsListMultiAction;
48 import org.opencms.workplace.list.CmsListOrderEnum;
49 import org.opencms.workplace.list.CmsListTimeIntervalFormatter;
50
51 import java.io.IOException JavaDoc;
52 import java.util.ArrayList JavaDoc;
53 import java.util.Date JavaDoc;
54 import java.util.HashMap JavaDoc;
55 import java.util.Iterator JavaDoc;
56 import java.util.List JavaDoc;
57 import java.util.Map JavaDoc;
58
59 import javax.servlet.ServletException JavaDoc;
60 import javax.servlet.http.HttpServletRequest JavaDoc;
61 import javax.servlet.http.HttpServletResponse JavaDoc;
62 import javax.servlet.jsp.PageContext JavaDoc;
63
64 /**
65  * Session list for broadcasting messages.<p>
66  *
67  * @author Michael Moossen
68  *
69  * @version $Revision: 1.14 $
70  *
71  * @since 6.0.0
72  */

73 public class CmsSessionsList extends A_CmsListDialog {
74
75     /** list action id constant. */
76     public static final String JavaDoc LIST_ACTION_MESSAGE = "am";
77
78     /** list action id constant. */
79     public static final String JavaDoc LIST_ACTION_PENDING_DISABLED = "apd";
80
81     /** list action id constant. */
82     public static final String JavaDoc LIST_ACTION_PENDING_ENABLED = "ape";
83
84     /** list column id constant. */
85     public static final String JavaDoc LIST_COLUMN_CREATION = "cc";
86
87     /** list column id constant. */
88     public static final String JavaDoc LIST_COLUMN_EMAIL = "ce";
89
90     /** list column id constant. */
91     public static final String JavaDoc LIST_COLUMN_INACTIVE = "ci";
92
93     /** list column id constant. */
94     public static final String JavaDoc LIST_COLUMN_MESSAGE = "cm";
95
96     /** list column id constant. */
97     public static final String JavaDoc LIST_COLUMN_PENDING = "cp";
98
99     /** list column id constant. */
100     public static final String JavaDoc LIST_COLUMN_PROJECT = "cj";
101
102     /** list column id constant. */
103     public static final String JavaDoc LIST_COLUMN_SITE = "cs";
104
105     /** list column id constant. */
106     public static final String JavaDoc LIST_COLUMN_USER = "cu";
107
108     /** list action id constant. */
109     public static final String JavaDoc LIST_DEFACTION_EMAIL = "de";
110
111     /** list action id constant. */
112     public static final String JavaDoc LIST_DEFACTION_MESSAGE = "dm";
113
114     /** list id constant. */
115     public static final String JavaDoc LIST_ID = "ls";
116
117     /** list action id constant. */
118     public static final String JavaDoc LIST_MACTION_EMAIL = "me";
119
120     /** list action id constant. */
121     public static final String JavaDoc LIST_MACTION_MESSAGE = "mm";
122
123     /** Path to the list buttons. */
124     public static final String JavaDoc PATH_BUTTONS = "tools/workplace/buttons/";
125
126     /**
127      * Public constructor.<p>
128      *
129      * @param jsp an initialized JSP action element
130      */

131     public CmsSessionsList(CmsJspActionElement jsp) {
132
133         super(
134             jsp,
135             LIST_ID,
136             Messages.get().container(Messages.GUI_SESSIONS_LIST_NAME_0),
137             LIST_COLUMN_USER,
138             CmsListOrderEnum.ORDER_ASCENDING,
139             LIST_COLUMN_USER);
140     }
141
142     /**
143      * Public constructor with JSP variables.<p>
144      *
145      * @param context the JSP page context
146      * @param req the JSP request
147      * @param res the JSP response
148      */

149     public CmsSessionsList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
150
151         this(new CmsJspActionElement(context, req, res));
152     }
153
154     /**
155      * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
156      */

157     public void executeListMultiActions() throws IOException JavaDoc, ServletException JavaDoc {
158
159         Map JavaDoc params = new HashMap JavaDoc();
160         params.put(A_CmsMessageDialog.PARAM_SESSIONIDS, getParamSelItems());
161         // set action parameter to initial dialog call
162
params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
163
164         if (getParamListAction().equals(LIST_MACTION_MESSAGE)) {
165             // execute the send message multiaction
166
// forward to the edit message screen
167
getToolManager().jspForwardTool(this, "/workplace/broadcast/message", params);
168         } else if (getParamListAction().equals(LIST_MACTION_EMAIL)) {
169             // execute the send email multiaction
170
// forward to the edit email screen
171
getToolManager().jspForwardTool(this, "/workplace/broadcast/email", params);
172         } else {
173             throwListUnsupportedActionException();
174         }
175     }
176
177     /**
178      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
179      */

180     public void executeListSingleActions() throws IOException JavaDoc, ServletException JavaDoc {
181
182         Map JavaDoc params = new HashMap JavaDoc();
183         params.put(A_CmsMessageDialog.PARAM_SESSIONIDS, getSelectedItem().getId());
184         // set action parameter to initial dialog call
185
params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
186
187         if (getParamListAction().equals(LIST_DEFACTION_EMAIL)) {
188             // forward to the edit user screen
189
getToolManager().jspForwardTool(this, "/workplace/broadcast/email", params);
190         } else if (getParamListAction().equals(LIST_ACTION_MESSAGE)
191             || getParamListAction().equals(LIST_DEFACTION_MESSAGE)) {
192             getToolManager().jspForwardTool(this, "/workplace/broadcast/message", params);
193         } else {
194             throwListUnsupportedActionException();
195         }
196         listSave();
197     }
198
199     /**
200      * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
201      */

202     protected void fillDetails(String JavaDoc detailId) {
203
204         // no details
205
}
206
207     /**
208      * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
209      */

210     protected List JavaDoc getListItems() {
211
212         List JavaDoc ret = new ArrayList JavaDoc();
213         // get content
214
List JavaDoc sessions = OpenCms.getSessionManager().getSessionInfos();
215         Iterator JavaDoc itSessions = sessions.iterator();
216         while (itSessions.hasNext()) {
217             CmsSessionInfo session = (CmsSessionInfo)itSessions.next();
218             CmsListItem item = getList().newItem(session.getSessionId());
219             item.set(LIST_COLUMN_USER, session.getUser().getFullName());
220             item.set(LIST_COLUMN_EMAIL, session.getUser().getEmail());
221             item.set(LIST_COLUMN_CREATION, new Date JavaDoc(session.getTimeCreated()));
222             item.set(LIST_COLUMN_INACTIVE, new Long JavaDoc(System.currentTimeMillis() - session.getTimeUpdated()));
223             try {
224                 item.set(LIST_COLUMN_PROJECT, getCms().readProject(session.getProject()).getName());
225             } catch (Exception JavaDoc e) {
226                 // ignore
227
}
228             item.set(LIST_COLUMN_SITE, session.getSiteRoot());
229             ret.add(item);
230         }
231
232         return ret;
233     }
234
235     /**
236      * @see org.opencms.workplace.CmsWorkplace#initMessages()
237      */

238     protected void initMessages() {
239
240         // add specific dialog resource bundle
241
addMessages(Messages.get().getBundleName());
242         addMessages(org.opencms.workplace.tools.workplace.Messages.get().getBundleName());
243         // add default resource bundles
244
super.initMessages();
245     }
246
247     /**
248      * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
249      */

250     protected void setColumns(CmsListMetadata metadata) {
251
252         // create column for send message
253
CmsListColumnDefinition messageCol = new CmsListColumnDefinition(LIST_COLUMN_MESSAGE);
254         messageCol.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_COLS_MESSAGE_0));
255         messageCol.setHelpText(Messages.get().container(Messages.GUI_SESSIONS_LIST_COLS_MESSAGE_HELP_0));
256         messageCol.setWidth("20");
257         messageCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
258         messageCol.setSorteable(false);
259         // add send message action
260
CmsListDirectAction messageAction = new CmsListDirectAction(LIST_ACTION_MESSAGE);
261         messageAction.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_ACTION_MESSAGE_NAME_0));
262         messageAction.setHelpText(Messages.get().container(Messages.GUI_SESSIONS_LIST_ACTION_MESSAGE_HELP_0));
263         messageAction.setIconPath(PATH_BUTTONS + "send_message.png");
264         messageCol.addDirectAction(messageAction);
265         // add it to the list definition
266
metadata.addColumn(messageCol);
267
268         // create column for pending
269
CmsListColumnDefinition pendingCol = new CmsListColumnDefinition(LIST_COLUMN_PENDING);
270         pendingCol.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_COLS_PENDING_0));
271         pendingCol.setWidth("20");
272         pendingCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
273         pendingCol.setListItemComparator(new CmsListItemActionIconComparator());
274         // add pending action
275
CmsListDirectAction pendingAction = new CmsListDirectAction(LIST_ACTION_PENDING_ENABLED) {
276
277             /**
278              * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
279              */

280             public boolean isVisible() {
281
282                 if (getItem() != null) {
283                     return !OpenCms.getSessionManager().getBroadcastQueue(getItem().getId()).isEmpty();
284                 }
285                 return super.isVisible();
286             }
287         };
288         pendingAction.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_ACTION_PENDING_NAME_0));
289         pendingAction.setHelpText(Messages.get().container(Messages.GUI_SESSIONS_LIST_ACTION_PENDING_HELP_0));
290         pendingAction.setIconPath(PATH_BUTTONS + "message_pending.png");
291         pendingAction.setEnabled(false);
292         pendingCol.addDirectAction(pendingAction);
293
294         // not pending action
295
CmsListDirectAction notPendingAction = new CmsListDirectAction(LIST_ACTION_PENDING_DISABLED) {
296
297             /**
298              * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
299              */

300             public boolean isVisible() {
301
302                 if (getItem() != null) {
303                     return OpenCms.getSessionManager().getBroadcastQueue(getItem().getId()).isEmpty();
304                 }
305                 return super.isVisible();
306             }
307         };
308         notPendingAction.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_ACTION_NOTPENDING_NAME_0));
309         notPendingAction.setHelpText(Messages.get().container(Messages.GUI_SESSIONS_LIST_ACTION_NOTPENDING_HELP_0));
310         notPendingAction.setIconPath(PATH_BUTTONS + "message_notpending.png");
311         notPendingAction.setEnabled(false);
312         pendingCol.addDirectAction(notPendingAction);
313
314         // add it to the list definition
315
metadata.addColumn(pendingCol);
316
317         // create column for user name
318
CmsListColumnDefinition userCol = new CmsListColumnDefinition(LIST_COLUMN_USER);
319         userCol.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_COLS_USER_0));
320         userCol.setWidth("20%");
321         // create default edit message action
322
CmsListDefaultAction messageEditAction = new CmsListDefaultAction(LIST_DEFACTION_MESSAGE);
323         messageEditAction.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_ACTION_MESSAGE_NAME_0));
324         messageEditAction.setHelpText(Messages.get().container(Messages.GUI_SESSIONS_LIST_ACTION_MESSAGE_HELP_0));
325         userCol.addDefaultAction(messageEditAction);
326         // add it to the list definition
327
metadata.addColumn(userCol);
328
329         // add column for email
330
CmsListColumnDefinition emailCol = new CmsListColumnDefinition(LIST_COLUMN_EMAIL);
331         emailCol.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_COLS_EMAIL_0));
332         emailCol.setWidth("30%");
333         // create default edit email action
334
CmsListDefaultAction emailEditAction = new CmsListDefaultAction(LIST_DEFACTION_EMAIL);
335         emailEditAction.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_DEFACTION_EMAIL_NAME_0));
336         emailEditAction.setHelpText(Messages.get().container(Messages.GUI_SESSIONS_LIST_DEFACTION_EMAIL_HELP_0));
337         emailCol.addDefaultAction(emailEditAction);
338         metadata.addColumn(emailCol);
339
340         // add column for creation date
341
CmsListColumnDefinition creationCol = new CmsListColumnDefinition(LIST_COLUMN_CREATION);
342         creationCol.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_COLS_CREATION_0));
343         creationCol.setWidth("16%");
344         creationCol.setFormatter(CmsListDateMacroFormatter.getDefaultDateFormatter());
345         metadata.addColumn(creationCol);
346
347         // add column for inactive time
348
CmsListColumnDefinition inactiveCol = new CmsListColumnDefinition(LIST_COLUMN_INACTIVE);
349         inactiveCol.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_COLS_INACTIVE_0));
350         inactiveCol.setWidth("10%");
351         inactiveCol.setFormatter(new CmsListTimeIntervalFormatter());
352         metadata.addColumn(inactiveCol);
353
354         // add column for project
355
CmsListColumnDefinition projectCol = new CmsListColumnDefinition(LIST_COLUMN_PROJECT);
356         projectCol.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_COLS_PROJECT_0));
357         projectCol.setWidth("12%");
358         metadata.addColumn(projectCol);
359
360         // add column for site
361
CmsListColumnDefinition siteCol = new CmsListColumnDefinition(LIST_COLUMN_SITE);
362         siteCol.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_COLS_SITE_0));
363         siteCol.setWidth("12%");
364         metadata.addColumn(siteCol);
365     }
366
367     /**
368      * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
369      */

370     protected void setIndependentActions(CmsListMetadata metadata) {
371
372         // noop
373
}
374
375     /**
376      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
377      */

378     protected void setMultiActions(CmsListMetadata metadata) {
379
380         // add message multi action
381
CmsListMultiAction messageMultiAction = new CmsListMultiAction(LIST_MACTION_MESSAGE);
382         messageMultiAction.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_MACTION_MESSAGE_NAME_0));
383         messageMultiAction.setHelpText(Messages.get().container(Messages.GUI_SESSIONS_LIST_MACTION_MESSAGE_HELP_0));
384         messageMultiAction.setConfirmationMessage(Messages.get().container(
385             Messages.GUI_SESSIONS_LIST_MACTION_MESSAGE_CONF_0));
386         messageMultiAction.setIconPath(PATH_BUTTONS + "multi_send_message.png");
387         metadata.addMultiAction(messageMultiAction);
388
389         // add email multi action
390
CmsListMultiAction emailMultiAction = new CmsListMultiAction(LIST_MACTION_EMAIL);
391         emailMultiAction.setName(Messages.get().container(Messages.GUI_SESSIONS_LIST_MACTION_EMAIL_NAME_0));
392         emailMultiAction.setHelpText(Messages.get().container(Messages.GUI_SESSIONS_LIST_MACTION_EMAIL_HELP_0));
393         emailMultiAction.setConfirmationMessage(Messages.get().container(
394             Messages.GUI_SESSIONS_LIST_MACTION_EMAIL_CONF_0));
395         emailMultiAction.setIconPath(PATH_BUTTONS + "multi_send_email.png");
396         metadata.addMultiAction(emailMultiAction);
397     }
398
399 }
400
Popular Tags