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.flex.CmsFlexCache;
031import org.opencms.main.OpenCms;
032import org.opencms.ui.A_CmsUI;
033import org.opencms.ui.CmsVaadinUtils;
034import org.opencms.ui.apps.cacheadmin.CmsCacheViewApp.Mode;
035import org.opencms.ui.components.CmsBasicDialog;
036
037import java.util.Iterator;
038import java.util.Set;
039
040import com.vaadin.ui.Button;
041import com.vaadin.ui.Button.ClickEvent;
042import com.vaadin.ui.FormLayout;
043import com.vaadin.ui.Panel;
044import com.vaadin.v7.ui.Label;
045import com.vaadin.v7.ui.VerticalLayout;
046
047/**
048 * Class for the dialog to show variations of flex cache and image cache.<p>
049 */
050public class CmsVariationsDialog extends CmsBasicDialog {
051
052    /**generated vaadin id.*/
053    private static final long serialVersionUID = -7346908393288365974L;
054
055    /**vaadin component.*/
056    private Button m_cancelButton;
057
058    /**vaadin component.*/
059    private FormLayout m_layout;
060
061    /**vaadin component.*/
062    private VerticalLayout m_outerlayout;
063
064    /**vaadin component.*/
065    private Panel m_panel;
066
067    /**
068     * public constructor.<p>
069     *
070     * @param resource to show variations for.
071     * @param cancel runnable
072     * @param mode mode
073     */
074    public CmsVariationsDialog(String resource, final Runnable cancel, CmsCacheViewApp.Mode mode) {
075
076        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
077
078        m_cancelButton.addClickListener(new Button.ClickListener() {
079
080            private static final long serialVersionUID = -4321889329235244258L;
081
082            public void buttonClick(ClickEvent event) {
083
084                cancel.run();
085            }
086        });
087
088        Iterator<String> variationsIterator = null;
089
090        if (Mode.FlexCache.equals(mode)) {
091            //For FlexCache
092            CmsFlexCache cache = OpenCms.getFlexCache();
093            Set<String> variations = cache.getCachedVariations(resource, A_CmsUI.getCmsObject());
094            variationsIterator = variations.iterator();
095
096            m_panel.setSizeFull();
097
098            m_layout.setHeight("100%");
099            m_outerlayout.setHeight("100%");
100
101            m_layout.addStyleName("v-scrollable");
102
103            while (variationsIterator.hasNext()) {
104                m_layout.addComponent(new Label(variationsIterator.next()));
105            }
106        } else {
107            m_outerlayout.addComponent(new CmsImageVariationsTable(resource));
108        }
109
110    }
111}