001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.apps.sessions; 029 030import org.opencms.main.CmsException; 031import org.opencms.main.CmsLog; 032import org.opencms.main.OpenCms; 033import org.opencms.ui.A_CmsUI; 034import org.opencms.ui.CmsVaadinUtils; 035import org.opencms.ui.FontOpenCms; 036import org.opencms.ui.apps.Messages; 037import org.opencms.ui.components.CmsBasicDialog; 038import org.opencms.util.CmsUUID; 039 040import java.util.Set; 041 042import org.apache.commons.logging.Log; 043 044import com.vaadin.shared.ui.ContentMode; 045import com.vaadin.ui.Button; 046import com.vaadin.ui.Button.ClickEvent; 047import com.vaadin.ui.Button.ClickListener; 048import com.vaadin.ui.Label; 049 050/** 051 * Class for the dialog to kill sessions.<p> 052 */ 053public class CmsKillSessionDialog extends CmsBasicDialog { 054 055 /**vaadin serial id.*/ 056 private static final long serialVersionUID = -7281930091176835024L; 057 058 /** The logger for this class. */ 059 static Log LOG = CmsLog.getLog(CmsKillSessionDialog.class.getName()); 060 061 /**cancel button.*/ 062 private Button m_cancelButton; 063 064 /**warning icon.*/ 065 private Label m_icon; 066 067 /**vaadin component. */ 068 private Label m_label; 069 070 /**ok button.*/ 071 private Button m_okButton; 072 073 /** 074 * public constructor. <p> 075 * 076 * @param sessionIds ids of sessions to be killed 077 * @param canelRunnable runnable to be runned on cancel 078 */ 079 public CmsKillSessionDialog(final Set<String> sessionIds, final Runnable canelRunnable) { 080 081 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 082 083 displayResourceInfoDirectly(CmsSessionsApp.getUserInfos(sessionIds)); 084 085 m_icon.setContentMode(ContentMode.HTML); 086 m_icon.setValue(FontOpenCms.WARNING.getHtml()); 087 088 if (sessionIds.size() == 1) { 089 m_label.setValue(CmsVaadinUtils.getMessageText(Messages.GUI_MESSAGES_CONFIRM_DESTROY_SESSION_SINGLE_0)); 090 } 091 092 m_okButton.addClickListener(new ClickListener() { 093 094 private static final long serialVersionUID = 5044360626122683306L; 095 096 public void buttonClick(ClickEvent event) { 097 098 for (String sessionId : sessionIds) { 099 try { 100 OpenCms.getSessionManager().killSession(A_CmsUI.getCmsObject(), new CmsUUID(sessionId)); 101 LOG.info("Kill session of user with id '" + sessionId + "'"); 102 } catch (NumberFormatException | CmsException e) { 103 //current session cannot be killed 104 } 105 } 106 canelRunnable.run(); 107 } 108 }); 109 m_cancelButton.addClickListener(new ClickListener() { 110 111 private static final long serialVersionUID = 6872628835561250226L; 112 113 public void buttonClick(ClickEvent event) { 114 115 canelRunnable.run(); 116 } 117 }); 118 } 119}