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    
029    /**
030     * @author Eduardo Garcia
031     */
032    public abstract class BasePortletToolbarContributor
033            implements PortletToolbarContributor {
034    
035            @Override
036            public List<Menu> getPortletTitleMenus(PortletRequest portletRequest) {
037                    List<MenuItem> portletTitleMenuItems = getPortletTitleMenuItems(
038                            portletRequest);
039    
040                    if (ListUtil.isEmpty(portletTitleMenuItems)) {
041                            return Collections.emptyList();
042                    }
043    
044                    List<Menu> menus = new ArrayList<>();
045    
046                    Menu menu = new Menu();
047    
048                    Map<String, Object> data = new HashMap<>();
049    
050                    data.put("qa-id", "addButton");
051    
052                    menu.setData(data);
053    
054                    menu.setDirection("down");
055                    menu.setExtended(false);
056                    menu.setIcon("../aui/plus-sign-2");
057                    menu.setMenuItems(portletTitleMenuItems);
058                    menu.setShowArrow(false);
059    
060                    menus.add(menu);
061    
062                    return menus;
063            }
064    
065            protected abstract List<MenuItem> getPortletTitleMenuItems(
066                    PortletRequest portletRequest);
067    
068    }