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;
036import org.opencms.gwt.client.util.I_CmsSimpleCallback;
037
038import java.util.Map;
039
040/**
041 * Advanced image tag properties tab, use in editor mode only.<p>
042 *
043 * @since 8.0.
044 */
045public class CmsImageAdvancedTab extends A_CmsPreviewDetailTab {
046
047    /** The form. */
048    private CmsImageAdvancedForm m_form;
049
050    /** The preview handler. */
051    private CmsImagePreviewHandler m_handler;
052
053    /**
054     * The constructor.<p>
055     *
056     * @param dialogMode the mode of the gallery
057     * @param height the height of the tab
058     * @param width the width of the height
059     * @param handler the preview handler
060     */
061    public CmsImageAdvancedTab(GalleryMode dialogMode, int height, int width, CmsImagePreviewHandler handler) {
062
063        super(dialogMode, height, width);
064        m_handler = handler;
065        m_form = new CmsImageAdvancedForm();
066        m_main.insert(m_form, 0);
067    }
068
069    /**
070     * Displays the provided image information.<p>
071     *
072     * @param imageInfo the image information
073     */
074    public void fillContent(CmsImageInfoBean imageInfo) {
075
076        CmsJSONMap imageAttributes = CmsPreviewUtil.getImageAttributes();
077        boolean inititalFill = false;
078        // checking if selected image resource is the same as previewed resource
079        if (imageAttributes.containsKey(Attribute.emptySelection.name())
080            || (imageAttributes.containsKey(Attribute.hash.name())
081                && !imageAttributes.getString(Attribute.hash.name()).equals(
082                    String.valueOf(m_handler.getImageIdHash())))) {
083            imageAttributes = CmsJSONMap.createJSONMap();
084            inititalFill = true;
085        }
086        m_form.fillContent(imageInfo, imageAttributes, inititalFill);
087    }
088
089    /**
090     * Adds necessary attributes to the map.<p>
091     *
092     * @param attributes the attribute map
093     * @param callback the callback to execute
094     */
095    public void getImageAttributes(
096        Map<String, String> attributes,
097        final I_CmsSimpleCallback<Map<String, String>> callback) {
098
099        m_form.getImageAttributes(attributes, callback);
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}