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.components;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsResource;
032import org.opencms.ui.CmsVaadinUtils;
033
034import java.util.List;
035
036import com.vaadin.ui.Button;
037import com.vaadin.v7.ui.Label;
038import com.vaadin.v7.ui.VerticalLayout;
039
040/**
041 * Widget used to display a list of locked resources.<p<
042 */
043public class CmsLockedResourcesList extends CmsBasicDialog {
044
045    /** Serial version id. */
046    private static final long serialVersionUID = 1L;
047
048    /** The label used to display the message. */
049    private Label m_messageLabel;
050
051    /** The box containing the individual widgets for locked resources. */
052    private VerticalLayout m_resourceBox;
053
054    /** The OK button. */
055    private Button m_okButton;
056
057    /** The cancel button. */
058    private Button m_cancelButton;
059
060    /**
061     * Creates a new instance.<p>
062     *
063     * @param cms the CMS context
064     * @param resources the locked resources to display
065     * @param message the message to display
066     * @param nextAction the action to execute after clicking the OK button
067     * @param cancelAction the action to execute after clicking the Cancel button
068     */
069    public CmsLockedResourcesList(
070        CmsObject cms,
071        List<CmsResource> resources,
072        String message,
073        Runnable nextAction,
074        Runnable cancelAction) {
075
076        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
077        m_messageLabel.setValue(message);
078        if (nextAction != null) {
079            m_okButton.addClickListener(CmsVaadinUtils.createClickListener(nextAction));
080        } else {
081            m_okButton.setVisible(false);
082        }
083
084        if (cancelAction != null) {
085            m_cancelButton.addClickListener(CmsVaadinUtils.createClickListener(cancelAction));
086        } else {
087            m_cancelButton.setVisible(false);
088        }
089        for (CmsResource resource : resources) {
090            m_resourceBox.addComponent(new CmsResourceInfo(resource));
091        }
092    }
093}