001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.context;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.theme.PortletDisplay;
019    import com.liferay.portal.theme.ThemeDisplay;
020    import com.liferay.portal.util.PortletKeys;
021    import com.liferay.portal.util.WebKeys;
022    import com.liferay.portlet.documentlibrary.DLPortletInstanceSettings;
023    
024    import javax.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Iv??n Zaera
028     * @author Sergio Gonz??lez
029     */
030    public class DLActionsDisplayContext {
031    
032            public DLActionsDisplayContext(
033                    HttpServletRequest request,
034                    DLPortletInstanceSettings dlPortletInstanceSettings) {
035    
036                    _request = request;
037                    _dlPortletInstanceSettings = dlPortletInstanceSettings;
038    
039                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
040                            WebKeys.THEME_DISPLAY);
041    
042                    _portletDisplay = themeDisplay.getPortletDisplay();
043            }
044    
045            public boolean isAddFolderButtonVisible() {
046                    String portletName = _portletDisplay.getPortletName();
047    
048                    if (portletName.equals(PortletKeys.DOCUMENT_LIBRARY) ||
049                            portletName.equals(PortletKeys.DOCUMENT_LIBRARY_ADMIN)) {
050    
051                            return true;
052                    }
053    
054                    return false;
055            }
056    
057            public boolean isFolderMenuVisible() {
058                    String portletName = _portletDisplay.getPortletName();
059    
060                    if (portletName.equals(PortletKeys.DOCUMENT_LIBRARY) ||
061                            portletName.equals(PortletKeys.DOCUMENT_LIBRARY_ADMIN)) {
062    
063                            return true;
064                    }
065    
066                    return _dlPortletInstanceSettings.isShowFolderMenu();
067            }
068    
069            public boolean isShowActions() {
070                    String portletName = _portletDisplay.getPortletName();
071                    String portletResource = _portletDisplay.getPortletResource();
072    
073                    if (portletName.equals(PortletKeys.DOCUMENT_LIBRARY) ||
074                            portletName.equals(PortletKeys.DOCUMENT_LIBRARY_ADMIN) ||
075                            portletResource.equals(PortletKeys.DOCUMENT_LIBRARY) ||
076                            portletResource.equals(PortletKeys.DOCUMENT_LIBRARY_ADMIN)) {
077    
078                            return true;
079                    }
080    
081                    return _dlPortletInstanceSettings.isShowActions();
082            }
083    
084            public boolean isShowMinimalActionsButton() {
085                    String portletName = _portletDisplay.getPortletName();
086    
087                    if (portletName.equals(PortletKeys.DOCUMENT_LIBRARY) ||
088                            portletName.equals(PortletKeys.DOCUMENT_LIBRARY_ADMIN)) {
089    
090                            return true;
091                    }
092    
093                    return ParamUtil.getBoolean(_request, "showMinimalActionButtons");
094            }
095    
096            public boolean isShowTabs() {
097                    String portletName = _portletDisplay.getPortletName();
098    
099                    if (portletName.equals(PortletKeys.DOCUMENT_LIBRARY) ||
100                            portletName.equals(PortletKeys.DOCUMENT_LIBRARY_ADMIN)) {
101    
102                            return true;
103                    }
104    
105                    return _dlPortletInstanceSettings.isShowTabs();
106            }
107    
108            public boolean isShowWhenSingleIconActionButton() {
109                    String portletName = _portletDisplay.getPortletName();
110    
111                    if (portletName.equals(PortletKeys.DOCUMENT_LIBRARY) ||
112                            portletName.equals(PortletKeys.DOCUMENT_LIBRARY_ADMIN)) {
113    
114                            return true;
115                    }
116    
117                    return false;
118            }
119    
120            private final DLPortletInstanceSettings _dlPortletInstanceSettings;
121            private final PortletDisplay _portletDisplay;
122            private final HttpServletRequest _request;
123    
124    }