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.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        setHeight("500px");
081        m_container = container;
082        PROP_CAPTION = captionProp;
083        PROP_DESCRIPTION = descProp;
084        PROP_ICON = iconProp;
085        PROP_OU = ouProp;
086        setContainerDataSource(m_container);
087        setItemIconPropertyId(iconProp);
088        setColumnWidth(null, 40);
089        setColumnWidth(ouProp, 300);
090        setSelectable(true);
091
092        setWidth("100%");
093        setRowHeaderMode(RowHeaderMode.ICON_ONLY);
094        setVisibleColumns(PROP_CAPTION, PROP_DESCRIPTION, PROP_OU);
095        addItemClickListener(new ItemClickListener() {
096
097            private static final long serialVersionUID = -4593704069277393664L;
098
099            public void itemClick(ItemClickEvent event) {
100
101                dialog.select((I_CmsPrincipal)event.getItemId());
102            }
103
104        });
105    }
106
107    /**
108     * Updates container.<p>
109     *
110     * @param data to be updated
111     */
112    public void updateContainer(IndexedContainer data) {
113
114        m_container.removeAllItems();
115        m_container = data;
116        setContainerDataSource(m_container);
117        setItemIconPropertyId(PROP_ICON);
118        setRowHeaderMode(RowHeaderMode.ICON_ONLY);
119
120        setVisibleColumns(PROP_CAPTION, PROP_DESCRIPTION, PROP_OU);
121        setColumnWidth(null, 40);
122        this.refreshRowCache();
123
124    }
125
126    /**
127     * Filter for table.<p>
128     * @param search text
129     */
130    protected void filterTable(String search) {
131
132        m_container.removeAllContainerFilters();
133        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(search)) {
134            m_container.addContainerFilter(
135                new Or(
136                    new SimpleStringFilter(PROP_CAPTION, search, true, false),
137                    new SimpleStringFilter(PROP_DESCRIPTION, search, true, false)));
138        }
139    }
140}