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