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.taglib.portletext;
016    
017    import com.liferay.portal.kernel.portlet.configuration.icon.PortletConfigurationIcon;
018    import com.liferay.portal.kernel.portlet.configuration.icon.PortletConfigurationIconTracker;
019    import com.liferay.portal.kernel.util.JavaConstants;
020    import com.liferay.portal.kernel.util.WebKeys;
021    import com.liferay.portal.theme.PortletDisplay;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.comparator.PortletConfigurationIconFactoryComparator;
024    import com.liferay.taglib.ui.IconTag;
025    
026    import java.util.List;
027    
028    import javax.portlet.PortletRequest;
029    
030    import javax.servlet.http.HttpServletRequest;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     */
035    public class IconOptionsTag extends IconTag {
036    
037            public List<PortletConfigurationIcon>
038                    getPortletConfigurationIcons() {
039    
040                    if (_portletConfigurationIcons != null) {
041                            return _portletConfigurationIcons;
042                    }
043    
044                    _portletConfigurationIcons =
045                            PortletConfigurationIconTracker.getPortletConfigurationIcons(
046                                    getPortletId(), getPortletRequest(),
047                                    PortletConfigurationIconFactoryComparator.INSTANCE);
048    
049                    return _portletConfigurationIcons;
050            }
051    
052            public void setDirection(String direction) {
053                    _direction = direction;
054            }
055    
056            public void setPortletConfigurationIcons(
057                    List<PortletConfigurationIcon> portletConfigurationIcons) {
058    
059                    _portletConfigurationIcons = portletConfigurationIcons;
060            }
061    
062            public void setShowArrow(boolean showArrow) {
063                    _showArrow = showArrow;
064            }
065    
066            @Override
067            protected void cleanUp() {
068                    super.cleanUp();
069    
070                    _direction = "down";
071                    _portletConfigurationIcons = null;
072                    _showArrow = true;
073            }
074    
075            @Override
076            protected String getPage() {
077                    return "/html/taglib/portlet/icon_options/page.jsp";
078            }
079    
080            protected String getPortletId() {
081                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
082                            WebKeys.THEME_DISPLAY);
083    
084                    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
085    
086                    return portletDisplay.getRootPortletId();
087            }
088    
089            protected PortletRequest getPortletRequest() {
090                    return (PortletRequest)request.getAttribute(
091                            JavaConstants.JAVAX_PORTLET_REQUEST);
092            }
093    
094            @Override
095            protected void setAttributes(HttpServletRequest request) {
096                    super.setAttributes(request);
097    
098                    request.setAttribute("liferay-ui:icon:direction", _direction);
099                    request.setAttribute(
100                            "liferay-ui:icon:showArrow", String.valueOf(_showArrow));
101                    request.setAttribute(
102                            "liferay-ui:icon-options:portletConfigurationIcons",
103                            getPortletConfigurationIcons());
104            }
105    
106            private String _direction = "down";
107            private List<PortletConfigurationIcon> _portletConfigurationIcons;
108            private boolean _showArrow = true;
109    
110    }