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.portal.kernel.portlet.toolbar.contributor;
016    
017    import com.liferay.portal.kernel.servlet.taglib.ui.Menu;
018    import com.liferay.portal.kernel.servlet.taglib.ui.MenuItem;
019    import com.liferay.portal.kernel.util.ListUtil;
020    
021    import java.util.ArrayList;
022    import java.util.Collections;
023    import java.util.HashMap;
024    import java.util.List;
025    import java.util.Map;
026    
027    import javax.portlet.PortletRequest;
028    import javax.portlet.PortletResponse;
029    
030    /**
031     * @author Eduardo Garcia
032     */
033    public abstract class BasePortletToolbarContributor
034            implements PortletToolbarContributor {
035    
036            @Override
037            public List<Menu> getPortletTitleMenus(
038                    PortletRequest portletRequest, PortletResponse portletResponse) {
039    
040                    List<MenuItem> portletTitleMenuItems = getPortletTitleMenuItems(
041                            portletRequest, portletResponse);
042    
043                    if (ListUtil.isEmpty(portletTitleMenuItems)) {
044                            return Collections.emptyList();
045                    }
046    
047                    List<Menu> menus = new ArrayList<>();
048    
049                    Menu menu = new Menu();
050    
051                    Map<String, Object> data = new HashMap<>();
052    
053                    data.put("qa-id", "addButton");
054    
055                    menu.setData(data);
056    
057                    menu.setDirection("down");
058                    menu.setExtended(false);
059                    menu.setIcon("../aui/plus-sign-2");
060                    menu.setMenuItems(portletTitleMenuItems);
061                    menu.setShowArrow(false);
062                    menu.setShowWhenSingleIcon(true);
063    
064                    menus.add(menu);
065    
066                    return menus;
067            }
068    
069            protected abstract List<MenuItem> getPortletTitleMenuItems(
070                    PortletRequest portletRequest, PortletResponse portletResponse);
071    
072    }