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.galleries.client.preview.ui;
029
030import org.opencms.ade.galleries.client.Messages;
031import org.opencms.ade.galleries.client.preview.CmsBinaryPreviewHandler;
032import org.opencms.ade.galleries.client.preview.I_CmsPreviewHandler;
033import org.opencms.ade.galleries.shared.CmsResourceInfoBean;
034import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants.GalleryMode;
035
036import com.google.gwt.event.dom.client.ClickEvent;
037import com.google.gwt.event.dom.client.ClickHandler;
038import com.google.gwt.user.client.Command;
039
040/**
041 * Provides a widget for the binary preview dialog .<p>
042 *
043 * @since 8.0.
044 */
045public class CmsBinaryPreviewDialog extends A_CmsPreviewDialog<CmsResourceInfoBean> {
046
047    /** The preview handler. */
048    private CmsBinaryPreviewHandler m_handler;
049
050    /** The properties tab. */
051    private CmsPropertiesTab m_propertiesTab;
052
053    /**
054     * The constructor.<p>
055     *
056     * @param dialogMode the dialog mode
057     * @param dialogHeight the dialog height to set
058     * @param dialogWidth the dialog width to set
059     * @param disableSelection true if selection from the preview should be disabled
060     */
061    public CmsBinaryPreviewDialog(GalleryMode dialogMode, int dialogHeight, int dialogWidth, boolean disableSelection) {
062
063        super(dialogMode, dialogHeight, dialogWidth, disableSelection);
064    }
065
066    /**
067     * @see org.opencms.ade.galleries.client.preview.ui.A_CmsPreviewDialog#fillContent(org.opencms.ade.galleries.shared.CmsResourceInfoBean)
068     */
069    @Override
070    public void fillContent(CmsResourceInfoBean infoBean) {
071
072        fillPreviewPanel(infoBean);
073        m_propertiesTab.fillContent(infoBean);
074    }
075
076    /**
077     * Fills the content of the preview panel part.<p>
078     *
079     * @param infoBean the resource info
080     */
081    public void fillPreviewPanel(CmsResourceInfoBean infoBean) {
082
083        m_previewPanel.setWidget(new CmsBinaryPreviewContent(infoBean, m_handler));
084    }
085
086    /**
087     * @see org.opencms.ade.galleries.client.preview.ui.A_CmsPreviewDialog#hasChanges()
088     */
089    @Override
090    public boolean hasChanges() {
091
092        return m_propertiesTab.isChanged();
093    }
094
095    /**
096     * Initializes the preview.<p>
097     *
098     * @param handler the preview handler
099     */
100    public void init(CmsBinaryPreviewHandler handler) {
101
102        m_handler = handler;
103        final CmsPropertiesTab propTab = new CmsPropertiesTab(m_galleryMode, m_dialogHeight, m_dialogWidth, m_handler);
104        m_selectButton.addClickHandler(new ClickHandler() {
105
106            public void onClick(ClickEvent event) {
107
108                saveChanges(null);
109
110            }
111        });
112        m_propertiesTab = propTab;
113        m_tabbedPanel.add(m_propertiesTab, Messages.get().key(Messages.GUI_PREVIEW_TAB_PROPERTIES_0));
114    }
115
116    /**
117     * @see org.opencms.ade.galleries.client.preview.ui.A_CmsPreviewDialog#saveChanges(com.google.gwt.user.client.Command)
118     */
119    @Override
120    public void saveChanges(Command afterSaveCommand) {
121
122        if (hasChanges()) {
123            m_propertiesTab.saveProperties(afterSaveCommand);
124        }
125    }
126
127    /**
128     * @see org.opencms.ade.galleries.client.preview.ui.A_CmsPreviewDialog#getHandler()
129     */
130    @Override
131    protected I_CmsPreviewHandler<CmsResourceInfoBean> getHandler() {
132
133        return m_handler;
134    }
135}