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.PortletConfigurationIconFactory;
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.ListUtil;
021    import com.liferay.portal.kernel.util.WebKeys;
022    import com.liferay.portal.theme.PortletDisplay;
023    import com.liferay.portal.theme.ThemeDisplay;
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 void setDirection(String direction) {
038                    _direction = direction;
039            }
040    
041            public void setShowArrow(boolean showArrow) {
042                    _showArrow = showArrow;
043            }
044    
045            @Override
046            protected void cleanUp() {
047                    super.cleanUp();
048    
049                    _direction = "down";
050                    _showArrow = true;
051            }
052    
053            @Override
054            protected String getPage() {
055                    return "/html/taglib/portlet/icon_options/page.jsp";
056            }
057    
058            protected List<PortletConfigurationIconFactory>
059                    getPortletConfigurationIconFactories() {
060    
061                    return ListUtil.copy(
062                            PortletConfigurationIconTracker.getPortletConfigurationIcons(
063                                    getPortletId(), getPortletRequest()));
064            }
065    
066            protected String getPortletId() {
067                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
068                            WebKeys.THEME_DISPLAY);
069    
070                    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
071    
072                    return portletDisplay.getRootPortletId();
073            }
074    
075            protected PortletRequest getPortletRequest() {
076                    return (PortletRequest)request.getAttribute(
077                            JavaConstants.JAVAX_PORTLET_REQUEST);
078            }
079    
080            @Override
081            protected void setAttributes(HttpServletRequest request) {
082                    super.setAttributes(request);
083    
084                    request.setAttribute("liferay-ui:icon:direction", _direction);
085                    request.setAttribute(
086                            "liferay-ui:icon:showArrow", String.valueOf(_showArrow));
087    
088                    request.setAttribute(
089                            "liferay-ui:icon-options:portletConfigurationIconFactories",
090                            getPortletConfigurationIconFactories());
091            }
092    
093            private String _direction = "down";
094            private boolean _showArrow = true;
095    
096    }