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.preview.CmsImagePreviewHandler;
031import org.opencms.ade.galleries.client.preview.CmsImagePreviewHandler.Attribute;
032import org.opencms.ade.galleries.client.preview.CmsPreviewUtil;
033import org.opencms.ade.galleries.shared.CmsImageInfoBean;
034import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants.GalleryMode;
035import org.opencms.gwt.client.util.CmsJSONMap;
036
037import java.util.Map;
038
039/**
040 * Simple image tag properties tab, use in editor mode only.<p>
041 *
042 * @since 8.0.
043 */
044public class CmsImageEditorTab extends A_CmsPreviewDetailTab {
045
046    /** The editor form. */
047    private CmsImageEditorForm m_form;
048
049    /** The preview handler. */
050    private CmsImagePreviewHandler m_handler;
051
052    /**
053     * The constructor.<p>
054     *
055     * @param dialogMode the mode of the gallery
056     * @param height the height of the tab
057     * @param width the width of the height
058     * @param handler the preview handler
059     */
060    public CmsImageEditorTab(GalleryMode dialogMode, int height, int width, CmsImagePreviewHandler handler) {
061
062        super(dialogMode, height, width);
063        m_handler = handler;
064        m_form = new CmsImageEditorForm();
065        m_main.insert(m_form, 0);
066    }
067
068    /**
069     * Displays the provided image information.<p>
070     *
071     * @param imageInfo the image information
072     */
073    public void fillContent(CmsImageInfoBean imageInfo) {
074
075        //checking for enhanced image options
076        m_form.hideEnhancedOptions(
077            (getDialogMode() != GalleryMode.editor) || !CmsPreviewUtil.hasEnhancedImageOptions());
078        CmsJSONMap imageAttributes = CmsPreviewUtil.getImageAttributes();
079        boolean inititalFill = false;
080        // checking if selected image resource is the same as previewed resource
081        if ((imageAttributes.containsKey(Attribute.emptySelection.name()))
082            || (imageAttributes.containsKey(Attribute.hash.name())
083                && !imageAttributes.getString(Attribute.hash.name()).equals(
084                    String.valueOf(m_handler.getImageIdHash())))) {
085            imageAttributes = CmsJSONMap.createJSONMap();
086            inititalFill = true;
087        }
088        m_form.fillContent(imageInfo, imageAttributes, inititalFill);
089    }
090
091    /**
092     * Adds necessary attributes to the map.<p>
093     *
094     * @param attributes the attribute map
095     * @return the attribute map
096     */
097    public Map<String, String> getImageAttributes(Map<String, String> attributes) {
098
099        return m_form.getImageAttributes(attributes);
100    }
101
102    /**
103     * @see org.opencms.ade.galleries.client.preview.ui.A_CmsPreviewDetailTab#getHandler()
104     */
105    @Override
106    protected CmsImagePreviewHandler getHandler() {
107
108        return m_handler;
109    }
110
111}