001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (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.postupload.client.ui;
029
030import org.opencms.gwt.client.property.CmsSimplePropertyEditor;
031import org.opencms.gwt.client.property.I_CmsPropertyEditorHandler;
032import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
033import org.opencms.gwt.client.ui.input.I_CmsFormField;
034import org.opencms.gwt.client.ui.input.form.CmsInfoBoxFormFieldPanel;
035import org.opencms.gwt.shared.property.CmsPropertyModification;
036import org.opencms.util.CmsStringUtil;
037import org.opencms.util.CmsUUID;
038import org.opencms.xml.content.CmsXmlContentProperty;
039
040import java.util.Map;
041
042import com.google.gwt.user.client.ui.Label;
043
044/**
045 * A property editor for the upload property dialog.<p>
046 */
047public class CmsUploadPropertyEditor extends CmsSimplePropertyEditor {
048
049    /** The warning message. */
050    private String m_warning;
051    private CmsUUID m_structureId;
052
053    /**
054     * Creates a new instance.<p>
055     *
056     * @param propConfig the property configuration
057     * @param handler the property editor handler to use
058     */
059    public CmsUploadPropertyEditor(CmsUUID structureId, Map<String, CmsXmlContentProperty> propConfig, I_CmsPropertyEditorHandler handler) {
060
061        super(propConfig, handler);
062        m_structureId = structureId;
063        CmsUploadPropertyEditorHandler uploadPropertyHandler = (CmsUploadPropertyEditorHandler)handler;
064        m_warning = uploadPropertyHandler.getWarning();
065    }
066
067    /**
068     * @see org.opencms.gwt.client.property.CmsSimplePropertyEditor#isAlwaysAllowEmpty(java.lang.String)
069     */
070    @Override
071    protected boolean isAlwaysAllowEmpty(String name) {
072
073        return false;
074    }
075
076    /**
077     * @see org.opencms.gwt.client.property.CmsSimplePropertyEditor#maybeAddCustomValidator(org.opencms.xml.content.CmsXmlContentProperty, org.opencms.gwt.client.ui.input.I_CmsFormField)
078     */
079    @Override
080    protected void maybeAddCustomValidator(CmsXmlContentProperty propDef, I_CmsFormField field) {
081
082        if (field.getId().contains(CmsPropertyModification.FILE_NAME_PROPERTY)) {
083            field.setValidator(new CmsFilenameValidator(m_structureId, propDef));
084        }
085    }
086
087    /**
088    * @see org.opencms.gwt.client.property.CmsSimplePropertyEditor#setupFieldContainer()
089    */
090    @Override
091    protected void setupFieldContainer() {
092
093        CmsInfoBoxFormFieldPanel panel = new CmsInfoBoxFormFieldPanel(m_handler.getPageInfo());
094        panel.addStyleName(I_CmsLayoutBundle.INSTANCE.propertiesCss().noPaddingTop());
095        if (!CmsStringUtil.isEmptyOrWhitespaceOnly(m_warning)) {
096            Label warningLabel = new Label(m_warning);
097            warningLabel.addStyleName(
098                org.opencms.ade.postupload.client.ui.css.I_CmsLayoutBundle.INSTANCE.dialogCss().warningBox());
099            panel.addWidgetAfterListInfo(warningLabel);
100        }
101        m_form.setWidget(panel);
102    }
103
104}