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.ui.actions;
029
030import org.opencms.file.CmsResource;
031import org.opencms.ui.A_CmsUI;
032import org.opencms.ui.I_CmsDialogContext;
033import org.opencms.ui.I_CmsUpdateListener;
034import org.opencms.ui.components.extensions.CmsGwtDialogExtension;
035import org.opencms.ui.contextmenu.CmsStandardVisibilityCheck;
036import org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility;
037import org.opencms.util.CmsUUID;
038import org.opencms.workplace.explorer.Messages;
039
040import java.util.List;
041
042import com.google.common.collect.Lists;
043
044/**
045 * The gallery dialog action.<p>
046 */
047public class CmsGalleryDialogAction extends A_CmsGalleryDialogAction {
048
049    /** The action id. */
050    public static final String ACTION_ID = "gallery";
051
052    /** The action visibility. */
053    public static final I_CmsHasMenuItemVisibility VISIBILITY = CmsStandardVisibilityCheck.VISIBLE;
054
055    /** The folder types this action is available for. */
056    private static final String[] GALLERY_TYPES = new String[] {"imagegallery", "downloadgallery", "linkgallery"};
057
058    /**
059     * @see org.opencms.ui.actions.I_CmsWorkplaceAction#executeAction(org.opencms.ui.I_CmsDialogContext)
060     */
061    public void executeAction(final I_CmsDialogContext context) {
062
063        CmsResource gallery = getGallery(context);
064        try {
065            CmsGwtDialogExtension dialogExtension = new CmsGwtDialogExtension(
066                A_CmsUI.get(),
067                new I_CmsUpdateListener<String>() {
068
069                    public void onUpdate(List<String> updatedItems) {
070
071                        List<CmsUUID> updatedIds = Lists.newArrayList();
072                        for (String item : updatedItems) {
073                            updatedIds.add(new CmsUUID(item));
074                        }
075                        context.finish(updatedIds);
076                    }
077                });
078            dialogExtension.openGalleryDialog(gallery);
079        } catch (Exception e) {
080            context.error(e);
081        }
082    }
083
084    /**
085     * @see org.opencms.ui.actions.I_CmsWorkplaceAction#getId()
086     */
087    public String getId() {
088
089        return ACTION_ID;
090    }
091
092    /**
093     * @see org.opencms.ui.actions.A_CmsGalleryDialogAction#getSupportedGalleryTypes()
094     */
095    @Override
096    protected String[] getSupportedGalleryTypes() {
097
098        return GALLERY_TYPES;
099    }
100
101    /**
102     * @see org.opencms.ui.actions.A_CmsWorkplaceAction#getTitleKey()
103     */
104    @Override
105    protected String getTitleKey() {
106
107        return Messages.GUI_EXPLORER_CONTEXT_OPENGALLERY_0;
108    }
109}