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.sitemap.client.toolbar;
029
030import org.opencms.ade.sitemap.client.CmsGalleryTreeItem;
031import org.opencms.ade.sitemap.client.Messages;
032import org.opencms.ade.sitemap.client.control.CmsSitemapController;
033import org.opencms.ade.sitemap.client.ui.CmsCreateGalleryDialog;
034import org.opencms.ade.sitemap.shared.CmsGalleryType;
035import org.opencms.gwt.client.ui.CmsList;
036import org.opencms.gwt.client.ui.CmsListItem;
037import org.opencms.gwt.client.ui.CmsPushButton;
038import org.opencms.gwt.client.ui.I_CmsButton;
039import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
040import org.opencms.gwt.client.ui.I_CmsListItem;
041
042import java.util.Collection;
043
044import com.google.gwt.event.dom.client.ClickEvent;
045import com.google.gwt.event.dom.client.ClickHandler;
046
047/**
048 * The create new gallery menu.<p>
049 */
050public class CmsToolbarNewGalleryButton extends A_CmsToolbarListMenuButton {
051
052    /** The gallery types list. */
053    private CmsList<I_CmsListItem> m_galleriesList;
054
055    /**
056     * Constructor.<p>
057     *
058     * @param toolbar the tool bar instance
059     * @param controller the controller
060     */
061    public CmsToolbarNewGalleryButton(CmsSitemapToolbar toolbar, CmsSitemapController controller) {
062
063        super("", I_CmsButton.ButtonData.WAND_BUTTON.getIconClass(), toolbar, controller);
064        m_galleriesList = new CmsList<I_CmsListItem>();
065        addTab(createTab(m_galleriesList), Messages.get().key(Messages.GUI_GALLERIES_TYPES_TAB_0));
066    }
067
068    /**
069     * @see org.opencms.ade.sitemap.client.toolbar.A_CmsToolbarListMenuButton#initContent()
070     */
071    @Override
072    protected boolean initContent() {
073
074        return true;
075    }
076
077    /**
078     * Sets the available gallery types.<p>
079     *
080     * @param galleryTypes the gallery types
081     */
082    protected void setGalleryTypes(Collection<CmsGalleryType> galleryTypes) {
083
084        m_galleriesList.clear();
085        for (CmsGalleryType galleryType : galleryTypes) {
086            m_galleriesList.addItem(makeGalleryTypeItem(galleryType));
087        }
088        m_galleriesList.truncate(TM_LITST_MENU, DIALOG_WIDTH);
089    }
090
091    /**
092     * Creates a gallery type item.<p>
093     *
094     * @param galleryType the gallery type
095     *
096     * @return the type item
097     */
098    private I_CmsListItem makeGalleryTypeItem(final CmsGalleryType galleryType) {
099
100        CmsListItem item = new CmsListItem(CmsGalleryTreeItem.createListWidget(galleryType));
101        CmsPushButton button = new CmsPushButton();
102        button.setImageClass(I_CmsButton.ADD_SMALL);
103        button.setButtonStyle(ButtonStyle.FONT_ICON, null);
104        button.setTitle(Messages.get().key(Messages.GUI_GALLERIES_CREATE_0));
105        button.addClickHandler(new ClickHandler() {
106
107            public void onClick(ClickEvent event) {
108
109                closeMenu();
110                CmsCreateGalleryDialog dialog = new CmsCreateGalleryDialog(
111                    getController(),
112                    galleryType.getTypeId(),
113                    null);
114                dialog.center();
115            }
116        });
117        item.getListItemWidget().addButton(button);
118        return item;
119    }
120}