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.cacheadmin;
029
030import org.opencms.file.types.CmsResourceTypeImage;
031import org.opencms.main.OpenCms;
032import org.opencms.ui.CmsVaadinUtils;
033import org.opencms.ui.apps.Messages;
034import org.opencms.workplace.explorer.CmsResourceUtil;
035
036import java.util.List;
037
038import com.vaadin.v7.data.Item;
039import com.vaadin.v7.data.util.IndexedContainer;
040import com.vaadin.server.Resource;
041import com.vaadin.v7.ui.Table;
042
043/**
044 * Table showing information about variations of images.<p>
045 */
046public class CmsImageVariationsTable extends Table {
047
048    /**vaadin serial id.*/
049    private static final long serialVersionUID = 4050556105747017491L;
050
051    /**The icon property.*/
052    protected static final String PROP_ICON = "icon";
053
054    /**The name property. */
055    protected static final String PROP_NAME = "name";
056
057    /**The dimension property. */
058    protected static final String PROP_DIMENSION = "dimension";
059
060    /**The length property. */
061    protected static final String PROP_LENGTH = "length";
062
063    /**Indexed container.*/
064    private IndexedContainer m_container;
065
066    /**
067     * public constructor.<p>
068     * @param resource to show variations from
069     */
070    public CmsImageVariationsTable(String resource) {
071
072        m_container = new IndexedContainer();
073
074        m_container.addContainerProperty(
075            PROP_ICON,
076            Resource.class,
077            CmsResourceUtil.getBigIconResource(
078                OpenCms.getWorkplaceManager().getExplorerTypeSetting(CmsResourceTypeImage.getStaticTypeName()),
079                null));
080        m_container.addContainerProperty(PROP_NAME, String.class, "");
081        m_container.addContainerProperty(PROP_DIMENSION, String.class, "");
082        m_container.addContainerProperty(PROP_LENGTH, String.class, "");
083
084        List<CmsVariationBean> variations = CmsImageCacheTable.HELPER.getVariations(resource);
085        for (CmsVariationBean var : variations) {
086            Item item = m_container.addItem(var);
087            item.getItemProperty(PROP_NAME).setValue(var.getName());
088            item.getItemProperty(PROP_DIMENSION).setValue(var.getDimensions());
089            item.getItemProperty(PROP_LENGTH).setValue(var.getLength());
090        }
091
092        setContainerDataSource(m_container);
093
094        setColumnHeader(null, "");
095        setColumnHeader(PROP_DIMENSION, CmsVaadinUtils.getMessageText(Messages.GUI_CACHE_IMAGECACHE_LIST_COLS_SIZE_0));
096        setColumnHeader(PROP_NAME, CmsVaadinUtils.getMessageText(Messages.GUI_CACHE_IMAGECACHE_LIST_COLS_RESOURCE_0));
097        setColumnHeader(PROP_LENGTH, CmsVaadinUtils.getMessageText(Messages.GUI_CACHE_IMAGECACHE_LIST_COLS_LENGTH_0));
098
099        setItemIconPropertyId(PROP_ICON);
100        setRowHeaderMode(RowHeaderMode.ICON_ONLY);
101        setWidth("100%");
102        setHeight("500px");
103        setVisibleColumns(PROP_NAME, PROP_DIMENSION, PROP_LENGTH);
104
105    }
106}