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.gwt.client.ui.replace;
029
030import org.opencms.gwt.client.ui.contextmenu.CmsReplace;
031import org.opencms.gwt.client.ui.input.upload.CmsFileInput;
032import org.opencms.gwt.client.ui.input.upload.I_CmsUploadButton;
033import org.opencms.gwt.client.ui.input.upload.I_CmsUploadButtonHandler;
034import org.opencms.util.CmsUUID;
035
036import com.google.gwt.dom.client.Style.Unit;
037import com.google.gwt.event.logical.shared.CloseHandler;
038import com.google.gwt.user.client.ui.PopupPanel;
039
040/**
041 * The replace dialog handler.<p>
042 */
043public class CmsReplaceHandler implements I_CmsUploadButtonHandler {
044
045    /** The replace dialog. */
046    private CmsReplaceDialog m_dialog;
047
048    /** The menu item. */
049    private CmsReplace m_menuItem;
050
051    /** The structure id of the resource to replace. */
052    private CmsUUID m_structureId;
053
054    /** The upload button. */
055    private I_CmsUploadButton m_uploadButton;
056
057    /** The dialog close handler. */
058    private CloseHandler<PopupPanel> m_closeHandler;
059
060    /**
061     * Constructor.<p>
062     *
063     * @param structureId the structure id of the resource to replace
064     */
065    public CmsReplaceHandler(CmsUUID structureId) {
066
067        m_structureId = structureId;
068    }
069
070    /**
071     * @see org.opencms.gwt.client.ui.input.upload.I_CmsUploadButtonHandler#initializeFileInput(org.opencms.gwt.client.ui.input.upload.CmsFileInput)
072     */
073    public void initializeFileInput(CmsFileInput fileInput) {
074
075        // important to set font-size as inline style, as IE7 and IE8 will not accept it otherwise
076        fileInput.getElement().getStyle().setFontSize(200, Unit.PX);
077        fileInput.getElement().getStyle().setProperty("minHeight", "200px");
078        fileInput.setAllowMultipleFiles(false);
079        fileInput.setName("replace");
080        fileInput.addStyleName(
081            org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.uploadButton().uploadFileInput());
082    }
083
084    /**
085     * @see org.opencms.gwt.client.ui.input.upload.I_CmsUploadButtonHandler#onChange(org.opencms.gwt.client.ui.input.upload.CmsFileInput)
086     */
087    public void onChange(CmsFileInput fileInput) {
088
089        if (m_dialog == null) {
090            m_dialog = new CmsReplaceDialog(this);
091            m_dialog.center();
092            m_dialog.initContent(m_structureId);
093            if (m_closeHandler != null) {
094                m_dialog.addCloseHandler(m_closeHandler);
095            }
096        } else if (m_uploadButton != null) {
097            m_uploadButton.createFileInput();
098        }
099        if (fileInput.getFiles().length == 1) {
100            m_dialog.setFileInput(fileInput);
101        }
102        if (m_menuItem != null) {
103            m_menuItem.getParentMenu().hide();
104        }
105    }
106
107    /**
108     * @see org.opencms.gwt.client.ui.input.upload.I_CmsUploadButtonHandler#setButton(org.opencms.gwt.client.ui.input.upload.I_CmsUploadButton)
109     */
110    public void setButton(I_CmsUploadButton button) {
111
112        m_uploadButton = button;
113    }
114
115    /**
116     * Sets the dialog close handler.<p>
117     *
118     * @param closeHandler the close handler
119     */
120    public void setCloseHandler(CloseHandler<PopupPanel> closeHandler) {
121
122        m_closeHandler = closeHandler;
123        if (m_dialog != null) {
124            m_dialog.addCloseHandler(closeHandler);
125        }
126    }
127
128    /**
129     * Sets the replace menu item.<p>
130     *
131     * @param menuItem the replace menu item to set
132     */
133    public void setMenuItem(CmsReplace menuItem) {
134
135        m_menuItem = menuItem;
136    }
137
138}