001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.dialogs.permissions; 029 030import org.opencms.security.I_CmsPrincipal; 031import org.opencms.util.CmsStringUtil; 032 033import com.vaadin.v7.data.util.IndexedContainer; 034import com.vaadin.v7.data.util.filter.Or; 035import com.vaadin.v7.data.util.filter.SimpleStringFilter; 036import com.vaadin.v7.event.ItemClickEvent; 037import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; 038import com.vaadin.v7.ui.Table; 039 040/** 041 * Table to selecet principals used in the CmsPrincipalSelect vaadin element.<p> 042 */ 043public class CmsPrincipalTable extends Table { 044 045 /**vaadin serial id. */ 046 private static final long serialVersionUID = -6291109098461446195L; 047 048 /**Caption property. */ 049 private static String PROP_CAPTION; 050 051 /**Icon property. */ 052 private static String PROP_ICON; 053 054 /**Ou property. */ 055 private static String PROP_OU; 056 057 /**Description property. */ 058 private static String PROP_DESCRIPTION; 059 060 /**Indexed Contaier. */ 061 private IndexedContainer m_container; 062 063 /** 064 * public constructor.<p> 065 * 066 * @param dialog which holds the table 067 * @param container indexedcontainer 068 * @param iconProp icon property 069 * @param captionProp caption property 070 * @param descProp description property 071 * @param ouProp Ou 072 */ 073 public CmsPrincipalTable( 074 final CmsPrincipalSelectDialog dialog, 075 IndexedContainer container, 076 String iconProp, 077 String captionProp, 078 String descProp, 079 String ouProp) { 080 081 setHeight("500px"); 082 m_container = container; 083 PROP_CAPTION = captionProp; 084 PROP_DESCRIPTION = descProp; 085 PROP_ICON = iconProp; 086 PROP_OU = ouProp; 087 setContainerDataSource(m_container); 088 setItemIconPropertyId(iconProp); 089 setColumnWidth(null, 40); 090 setColumnWidth(ouProp, 300); 091 setSelectable(true); 092 093 setWidth("100%"); 094 setRowHeaderMode(RowHeaderMode.ICON_ONLY); 095 setVisibleColumns(PROP_CAPTION, PROP_DESCRIPTION, PROP_OU); 096 addItemClickListener(new ItemClickListener() { 097 098 private static final long serialVersionUID = -4593704069277393664L; 099 100 public void itemClick(ItemClickEvent event) { 101 102 dialog.select((I_CmsPrincipal)event.getItemId()); 103 } 104 105 }); 106 } 107 108 /** 109 * Updates container.<p> 110 * 111 * @param data to be updated 112 */ 113 public void updateContainer(IndexedContainer data) { 114 115 m_container.removeAllItems(); 116 m_container = data; 117 setContainerDataSource(m_container); 118 setItemIconPropertyId(PROP_ICON); 119 setRowHeaderMode(RowHeaderMode.ICON_ONLY); 120 121 setVisibleColumns(PROP_CAPTION, PROP_DESCRIPTION, PROP_OU); 122 setColumnWidth(null, 40); 123 this.refreshRowCache(); 124 125 } 126 127 /** 128 * Filter for table.<p> 129 * @param search text 130 */ 131 protected void filterTable(String search) { 132 133 m_container.removeAllContainerFilters(); 134 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(search)) { 135 m_container.addContainerFilter( 136 new Or( 137 new SimpleStringFilter(PROP_CAPTION, search, true, false), 138 new SimpleStringFilter(PROP_DESCRIPTION, search, true, false))); 139 } 140 } 141}