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.file.CmsResource; 032import org.opencms.file.CmsUser; 033import org.opencms.main.CmsException; 034import org.opencms.ui.CmsCssIcon; 035import org.opencms.ui.components.CmsResourceInfo; 036import org.opencms.ui.components.OpenCmsTheme; 037import org.opencms.util.CmsUUID; 038 039import java.util.ArrayList; 040import java.util.HashSet; 041import java.util.List; 042import java.util.Set; 043 044import com.vaadin.v7.data.Item; 045import com.vaadin.v7.data.util.IndexedContainer; 046import com.vaadin.v7.ui.Table; 047 048/** 049 * Table to show resources with CmsResourceInfo elements.<p> 050 */ 051public class CmsResourceInfoTable extends Table { 052 053 /**vaadin serial id. */ 054 private static final long serialVersionUID = 5999721724863889097L; 055 056 /**Table column. */ 057 private static String PROP_ELEMENT = "element"; 058 059 /**Indexed container. */ 060 IndexedContainer m_container; 061 062 /** 063 * Public constructor.<p> 064 * 065 * @param cms CmsObject 066 * @param userIDs user id 067 * @param groupIDs group id 068 */ 069 public CmsResourceInfoTable(CmsObject cms, Set<CmsUUID> userIDs, Set<CmsUUID> groupIDs) { 070 List<CmsUser> user = new ArrayList<CmsUser>(); 071 try { 072 for (CmsUUID group : groupIDs) { 073 user.addAll(cms.getUsersOfGroup(cms.readGroup(group).getName())); 074 } 075 Set<CmsUUID> principalIDs = new HashSet<CmsUUID>(); 076 principalIDs.addAll(userIDs); 077 principalIDs.addAll(groupIDs); 078 Set<CmsResource> resources = new HashSet<CmsResource>(); 079 for (CmsUUID id : principalIDs) { 080 resources.addAll(cms.getResourcesForPrincipal(id, null, false)); 081 } 082 083 init(resources, user); 084 } catch (CmsException e) { 085 // 086 } 087 } 088 089 /** 090 * public constructor.<p> 091 * 092 * @param resources to be shown 093 * @param user list of user 094 */ 095 public CmsResourceInfoTable(Set<CmsResource> resources, List<CmsUser> user) { 096 addStyleName("o-no-padding"); 097 m_container = new IndexedContainer(); 098 m_container.addContainerProperty(PROP_ELEMENT, CmsResourceInfo.class, null); 099 100 for (CmsResource res : resources) { 101 Item item = m_container.addItem(res); 102 item.getItemProperty(PROP_ELEMENT).setValue(new CmsResourceInfo(res)); 103 } 104 if (user != null) { 105 for (CmsUser us : user) { 106 Item item = m_container.addItem(us); 107 item.getItemProperty(PROP_ELEMENT).setValue( 108 new CmsResourceInfo( 109 us.getSimpleName(), 110 us.getDescription(), 111 new CmsCssIcon(OpenCmsTheme.ICON_USER))); 112 } 113 } 114 setColumnHeaderMode(ColumnHeaderMode.HIDDEN); 115 setContainerDataSource(m_container); 116 setVisibleColumns(PROP_ELEMENT); 117 118 } 119 120 /** 121 * Initializes the table.<p> 122 * 123 * @param resources List of resources 124 * @param user List user 125 */ 126 private void init(Set<CmsResource> resources, List<CmsUser> user) { 127 128 addStyleName("o-no-padding"); 129 m_container = new IndexedContainer(); 130 m_container.addContainerProperty(PROP_ELEMENT, CmsResourceInfo.class, null); 131 132 for (CmsResource res : resources) { 133 Item item = m_container.addItem(res); 134 if (item != null) { //Item is null if resource is dependency of multiple groups/user to delete 135 item.getItemProperty(PROP_ELEMENT).setValue(new CmsResourceInfo(res)); 136 } 137 } 138 if (user != null) { 139 for (CmsUser us : user) { 140 Item item = m_container.addItem(us); 141 if (item != null) { //Item is null if User is dependency of multiple groups to delete 142 item.getItemProperty(PROP_ELEMENT).setValue( 143 new CmsResourceInfo( 144 us.getSimpleName(), 145 us.getDescription(), 146 new CmsCssIcon(OpenCmsTheme.ICON_USER))); 147 } 148 } 149 } 150 setColumnHeaderMode(ColumnHeaderMode.HIDDEN); 151 setContainerDataSource(m_container); 152 setVisibleColumns(PROP_ELEMENT); 153 154 } 155}