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.user; 029 030import org.opencms.file.CmsObject; 031import org.opencms.main.CmsException; 032import org.opencms.main.CmsLog; 033import org.opencms.main.OpenCms; 034import org.opencms.security.CmsPrincipal; 035import org.opencms.ui.A_CmsUI; 036import org.opencms.ui.CmsVaadinUtils; 037import org.opencms.ui.components.CmsBasicDialog; 038import org.opencms.util.CmsUUID; 039 040import java.util.Collections; 041 042import org.apache.commons.logging.Log; 043 044import com.vaadin.ui.Button; 045import com.vaadin.ui.Button.ClickEvent; 046import com.vaadin.ui.Button.ClickListener; 047import com.vaadin.v7.ui.VerticalLayout; 048import com.vaadin.ui.Window; 049 050/** 051 * Dialog to show resources with permissions for principle.<p> 052 */ 053public class CmsShowResourcesDialog extends CmsBasicDialog { 054 055 /**Type of Dialog. */ 056 protected enum DialogType { 057 Group, User, Error; 058 } 059 060 /**vaadin serial id. */ 061 private static final long serialVersionUID = -1744033403586325260L; 062 063 /** Log instance for this class. */ 064 private static final Log LOG = CmsLog.getLog(CmsShowResourcesDialog.class); 065 066 /**vaadin component.*/ 067 private Button m_cancel; 068 069 /**vaadin component.*/ 070 private VerticalLayout m_layout; 071 072 /**CmsPrincipal. */ 073 private CmsPrincipal m_principal; 074 075 /**CmsObject. */ 076 private CmsObject m_cms; 077 078 /**Type of dialog. */ 079 private DialogType m_type; 080 081 /** 082 * public constructor.<p> 083 * 084 * @param id of principal 085 * @param window holding dialog 086 */ 087 public CmsShowResourcesDialog(String id, final Window window) { 088 089 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 090 091 iniCmsObject(); 092 093 try { 094 m_principal = A_CmsUI.getCmsObject().readUser(new CmsUUID(id)); 095 m_type = DialogType.User; 096 } catch (CmsException e) { 097 try { 098 m_principal = A_CmsUI.getCmsObject().readGroup(new CmsUUID(id)); 099 m_type = DialogType.Group; 100 } catch (CmsException e1) { 101 m_type = DialogType.Error; 102 } 103 } 104 displayResourceInfoDirectly(Collections.singletonList(CmsAccountsApp.getPrincipalInfo(m_principal))); 105 CmsShowResourceTable table = new CmsShowResourceTable(m_cms, m_principal.getId(), m_type); 106 if (table.hasNoEntries()) { 107 m_layout.addComponent( 108 CmsVaadinUtils.getInfoLayout( 109 org.opencms.ui.apps.Messages.GUI_USERMANAGEMENT_NO_RESOURCES_WITH_PERMISSIONS_0)); 110 } else { 111 m_layout.addComponent(table); 112 } 113 m_cancel.addClickListener(new ClickListener() { 114 115 private static final long serialVersionUID = -2117164384116082079L; 116 117 public void buttonClick(ClickEvent event) { 118 119 window.close(); 120 121 } 122 }); 123 } 124 125 /** 126 * Initializes CmsObject.<p> 127 */ 128 private void iniCmsObject() { 129 130 try { 131 m_cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject()); 132 m_cms.getRequestContext().setSiteRoot(""); 133 } catch (CmsException e) { 134 LOG.error("Unable to clone CmsObject", e); 135 } 136 } 137 138}