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.CmsObject;
031import org.opencms.file.CmsResource;
032import org.opencms.main.OpenCms;
033import org.opencms.ui.A_CmsUI;
034import org.opencms.ui.I_CmsDialogContext;
035import org.opencms.ui.I_CmsDialogContext.ContextType;
036import org.opencms.ui.components.CmsUploadButton.I_UploadListener;
037import org.opencms.ui.components.CmsUserInfo;
038import org.opencms.ui.components.OpenCmsTheme;
039import org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode;
040import org.opencms.ui.dialogs.CmsEmbeddedDialogContext;
041
042import java.util.List;
043import java.util.Locale;
044
045import com.google.common.collect.Multimap;
046import com.vaadin.ui.UI;
047import com.vaadin.ui.Window;
048
049/**
050 * User info dialog action, used only for sitemap and page editor toolbar.<p>
051 */
052public class CmsUserInfoDialogAction extends A_CmsWorkplaceAction {
053
054    /** The action id. */
055    public static final String ACTION_ID = "userInfo";
056
057    /**
058     * @see org.opencms.ui.actions.I_CmsWorkplaceAction#executeAction(org.opencms.ui.I_CmsDialogContext)
059     */
060    public void executeAction(final I_CmsDialogContext context) {
061
062        CmsUserInfo dialog = new CmsUserInfo(new I_UploadListener() {
063
064            public void onUploadFinished(List<String> uploadedFiles) {
065
066                handleUpload(uploadedFiles, context);
067            }
068        }, context);
069        Multimap<String, String> params = A_CmsUI.get().getParameters();
070        int top = 55;
071        int left = 0;
072        if (params.containsKey("left")) {
073            String buttonLeft = params.get("left").iterator().next();
074            left = Integer.parseInt(buttonLeft) - 290;
075        }
076        final Window window = new Window();
077        window.setModal(false);
078        window.setClosable(true);
079        window.setResizable(false);
080        window.setContent(dialog);
081        context.setWindow(window);
082        window.addStyleName(OpenCmsTheme.DROPDOWN);
083        UI.getCurrent().addWindow(window);
084        window.setPosition(left, top);
085    }
086
087    /**
088     * @see org.opencms.ui.actions.A_CmsWorkplaceAction#getDialogTitle()
089     */
090    @Override
091    public String getDialogTitle() {
092
093        return "";
094    }
095
096    /**
097     * @see org.opencms.ui.actions.I_CmsWorkplaceAction#getId()
098     */
099    public String getId() {
100
101        return ACTION_ID;
102    }
103
104    /**
105     * @see org.opencms.ui.actions.A_CmsWorkplaceAction#getTitle(java.util.Locale)
106     */
107    @Override
108    public String getTitle(Locale locale) {
109
110        return "";
111    }
112
113    /**
114     * @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.file.CmsObject, java.util.List)
115     */
116    public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) {
117
118        return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
119    }
120
121    /**
122     * @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.ui.I_CmsDialogContext)
123     */
124    @Override
125    public CmsMenuItemVisibilityMode getVisibility(I_CmsDialogContext context) {
126
127        if ((context instanceof CmsEmbeddedDialogContext) && (ContextType.appToolbar == context.getContextType())) {
128            return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE;
129        } else {
130            return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
131        }
132    }
133
134    /**
135     * @see org.opencms.ui.actions.A_CmsWorkplaceAction#getTitleKey()
136     */
137    @Override
138    protected String getTitleKey() {
139
140        return "";
141    }
142
143    /**
144     * Handles the user image file upload.<p>
145     *
146     * @param uploadedFiles the uploaded file names
147     * @param context the dialog context
148     */
149    void handleUpload(List<String> uploadedFiles, I_CmsDialogContext context) {
150
151        CmsObject cms = context.getCms();
152        boolean success = OpenCms.getWorkplaceAppManager().getUserIconHelper().handleImageUpload(cms, uploadedFiles);
153        if (success) {
154            context.reload();
155        }
156    }
157}