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.ade.upload.client.lists;
029
030import org.opencms.ade.upload.client.I_CmsUploadContext;
031import org.opencms.ade.upload.client.ui.CmsDialogUploadButtonHandler;
032import org.opencms.gwt.client.ui.CmsListItemWidget;
033import org.opencms.gwt.client.ui.input.upload.CmsUploadButton;
034import org.opencms.gwt.shared.CmsListInfoBean;
035
036import java.util.Arrays;
037import java.util.List;
038
039import com.google.gwt.core.client.GWT;
040import com.google.gwt.uibinder.client.UiBinder;
041import com.google.gwt.uibinder.client.UiField;
042import com.google.gwt.user.client.ui.Composite;
043import com.google.gwt.user.client.ui.Label;
044import com.google.gwt.user.client.ui.SimplePanel;
045import com.google.gwt.user.client.ui.Widget;
046
047/**
048 * Content of the upload dialog used to upload files in lists.
049 */
050public class CmsUploadView extends Composite {
051
052    /**
053     * The uiBinder interface for this widget.<p>
054     */
055    interface I_UploadViewUiBinder extends UiBinder<Widget, CmsUploadView> {
056        // empty
057    }
058
059    /** The uiBinder instance for this widget. */
060    private static I_UploadViewUiBinder uiBinder = GWT.create(I_UploadViewUiBinder.class);
061
062    /** The container for the list info item. */
063    @UiField
064    SimplePanel m_infoBoxContainer;
065
066    /** The text displayed in the middle of the dialog. */
067    @UiField
068    Label m_mainLabel;
069
070    /** The upload button. */
071    @UiField(provided = true)
072    CmsUploadButton m_uploadButton;
073
074    /**
075     * Creates a new instance.
076     *
077     * @param uploadFolder the upload folder
078     * @param postCreateHandler the post-create handler
079     * @param context the upload context
080     * @param info the list info bean to display on top (may be null)
081     */
082    public CmsUploadView(
083        String uploadFolder,
084        String postCreateHandler,
085        I_CmsUploadContext context,
086        CmsListInfoBean info) {
087
088        CmsDialogUploadButtonHandler handler = new CmsDialogUploadButtonHandler(() -> context);
089        handler.setPostCreateHandler(postCreateHandler);
090        handler.setTargetFolder(uploadFolder);
091        m_uploadButton = new CmsUploadButton(handler);
092        initWidget(uiBinder.createAndBindUi(this));
093        if (info != null) {
094            CmsListItemWidget infoWidget = new CmsListItemWidget(info);
095            m_infoBoxContainer.add(infoWidget);
096        }
097        m_mainLabel.setText(CmsUploadMessages.innerText(uploadFolder));
098
099    }
100
101    /**
102     * Gets the buttons.
103     *
104     * @return the buttons
105     */
106    public List<Widget> getButtons() {
107
108        return Arrays.asList(m_uploadButton);
109    }
110
111}