001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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.postupload.client.ui;
029
030import org.opencms.gwt.client.property.CmsPropertyPanel;
031import org.opencms.gwt.client.ui.CmsPushButton;
032import org.opencms.gwt.client.ui.I_CmsButton;
033import org.opencms.gwt.client.ui.input.I_CmsFormField;
034import org.opencms.gwt.client.ui.input.form.CmsFormRow;
035import org.opencms.gwt.client.ui.input.form.CmsInfoBoxFormFieldPanel;
036import org.opencms.gwt.shared.CmsListInfoBean;
037import org.opencms.gwt.shared.property.CmsPropertyModification;
038
039/**
040 * Custom form field panel for the post-upload dialog which adds buttons for copying a property value to all other uploads.
041 */
042public class CmsUploadFormFieldPanel extends CmsInfoBoxFormFieldPanel {
043
044    /** The handler that triggers the transfer of the property value to all other uploads. */
045    private I_CmsUpdateAllUploadsHandler m_updateAllHandler;
046
047    /**
048     * Creates a new instance.
049     *
050     * @param info the info bean
051     * @param updateAllHandler the handler to call for transferring a property value to all uploads
052     */
053    public CmsUploadFormFieldPanel(CmsListInfoBean info, I_CmsUpdateAllUploadsHandler updateAllHandler) {
054
055        super(info);
056        m_updateAllHandler = updateAllHandler;
057
058    }
059
060    /**
061     * @see org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel#createRow(org.opencms.gwt.client.ui.input.I_CmsFormField)
062     */
063    @Override
064    protected CmsFormRow createRow(I_CmsFormField field) {
065
066        CmsFormRow result = super.createRow(field);
067        String propName = field.getLayoutData().get(CmsPropertyPanel.LD_PROPERTY);
068        if (m_updateAllHandler != null) {
069            if (!CmsPropertyModification.FILE_NAME_PROPERTY.equals(propName)) {
070                CmsPushButton updateAllButton = new CmsPushButton();
071
072                updateAllButton.setImageClass(I_CmsButton.CIRCLE_PLUS_INV);
073                updateAllButton.setTitle(CmsConfirmTransferWidget.MessageStrings.caption());
074                updateAllButton.setButtonStyle(I_CmsButton.ButtonStyle.FONT_ICON, null);
075                updateAllButton.addClickHandler(event -> {
076                    String currentValue = field.getWidget().getFormValueAsString();
077                    m_updateAllHandler.updateAll(propName, currentValue);
078                    updateAllButton.clearHoverState();
079
080                });
081                result.getIcon().add(updateAllButton);
082            }
083        }
084        return result;
085
086    }
087
088}