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;
029
030import org.opencms.ade.galleries.client.Messages;
031import org.opencms.ade.galleries.client.ui.CmsGalleryDialog;
032import org.opencms.ade.galleries.shared.CmsResourceInfoBean;
033import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants.GalleryMode;
034
035import java.util.Map;
036
037import com.google.gwt.user.client.Command;
038import com.google.gwt.user.client.ui.Widget;
039
040/**
041 * Preview dialog handler.<p>
042 *
043 * Delegates the actions of the preview controller to the preview dialog.<p>
044 *
045 * @param <T> the resource info bean type
046 *
047 * @since 8.0.0
048 */
049public abstract class A_CmsPreviewHandler<T extends CmsResourceInfoBean> implements I_CmsPreviewHandler<T> {
050
051    /** The resource info. */
052    protected T m_resourceInfo;
053
054    /** The resource preview instance. */
055    protected I_CmsResourcePreview<T> m_resourcePreview;
056
057    /**
058     * Constructor.<p>
059     *
060     * @param resourcePreview the resource preview instance
061     */
062    public A_CmsPreviewHandler(I_CmsResourcePreview<T> resourcePreview) {
063
064        m_resourcePreview = resourcePreview;
065    }
066
067    /**
068     * @see org.opencms.ade.galleries.client.preview.I_CmsPreviewHandler#closePreview()
069     */
070    public void closePreview() {
071
072        if (m_resourcePreview.getPreviewDialog().getGalleryMode() == GalleryMode.editor) {
073            CmsPreviewUtil.enableEditorOk(false);
074        }
075        m_resourcePreview.getGalleryDialog().setPreviewVisible(false);
076    }
077
078    /**
079     * @see org.opencms.ade.galleries.client.preview.I_CmsPreviewHandler#getAdditionalWidgetForPropertyTab()
080     */
081    public Widget getAdditionalWidgetForPropertyTab() {
082
083        // TODO Auto-generated method stub
084        return null;
085    }
086
087    /**
088     * @see org.opencms.ade.galleries.client.preview.I_CmsPreviewHandler#getGalleryDialog()
089     */
090    public CmsGalleryDialog getGalleryDialog() {
091
092        return m_resourcePreview.getGalleryDialog();
093    }
094
095    /**
096     * @see org.opencms.ade.galleries.client.preview.I_CmsPropertiesHandler#saveProperties(java.util.Map, com.google.gwt.user.client.Command)
097     */
098    public void saveProperties(Map<String, String> properties, Command afterSaveCallback) {
099
100        m_resourcePreview.saveProperties(properties, afterSaveCallback);
101    }
102
103    /**
104     * @see org.opencms.ade.galleries.client.preview.I_CmsPropertiesHandler#selectResource()
105     */
106    public void selectResource() {
107
108        m_resourcePreview.setResource();
109    }
110
111    /**
112     * @see org.opencms.ade.galleries.client.preview.I_CmsPreviewHandler#setDataInEditor()
113     */
114    public boolean setDataInEditor() {
115
116        if (m_resourcePreview.getGalleryMode() == GalleryMode.editor) {
117            if (m_resourcePreview.getPreviewDialog().hasChanges()) {
118                m_resourcePreview.getPreviewDialog().confirmSaveChanges(
119                    Messages.get().key(Messages.GUI_PREVIEW_CONFIRM_LEAVE_SAVE_0),
120                    new Command() {
121
122                        /**
123                         * @see com.google.gwt.user.client.Command#execute()
124                         */
125                        public void execute() {
126
127                            m_resourcePreview.getPreviewDialog().saveChanges(new Command() {
128
129                                public void execute() {
130
131                                    CmsPreviewUtil.setDataAndCloseDialog();
132                                }
133                            });
134                        }
135                    },
136                    null);
137                return false;
138            } else {
139                m_resourcePreview.setResource();
140                return true;
141            }
142        } else {
143            throw new UnsupportedOperationException();
144        }
145    }
146
147    /**
148     * @see org.opencms.ade.galleries.client.preview.I_CmsPreviewHandler#showData(org.opencms.ade.galleries.shared.CmsResourceInfoBean)
149     */
150    public void showData(T resourceInfo) {
151
152        m_resourceInfo = resourceInfo;
153        // once the resource info is displayed, enable the OK button for editor mode
154        if (m_resourcePreview.getGalleryMode().equals(GalleryMode.editor)) {
155            CmsPreviewUtil.enableEditorOk(true);
156        }
157        m_resourcePreview.getPreviewDialog().fillContent(resourceInfo);
158    }
159}