001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.list;
029
030import org.opencms.util.CmsStringUtil;
031import org.opencms.workplace.CmsWorkplace;
032import org.opencms.workplace.tools.A_CmsHtmlIconButton;
033import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum;
034
035import java.util.Iterator;
036import java.util.List;
037
038/**
039 * Default implementation of a list radio multi action.<p>
040 *
041 * @since 6.0.0
042 */
043public class CmsListRadioMultiAction extends CmsListMultiAction {
044
045    /** A list of ids of related list item selection action ids. */
046    private final List<String> m_relatedActionIds;
047
048    /**
049     * Default Constructor.<p>
050     *
051     * @param id the unique id
052     * @param relatedActionIds the ids of the related item selection actions
053     */
054    public CmsListRadioMultiAction(String id, List<String> relatedActionIds) {
055
056        super(id);
057        m_relatedActionIds = relatedActionIds;
058    }
059
060    /**
061     * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#buttonHtml(CmsWorkplace)
062     */
063    @Override
064    public String buttonHtml(CmsWorkplace wp) {
065
066        if (!isVisible()) {
067            return "";
068        }
069        if (isEnabled()) {
070            String onClic = "listRSelMAction('"
071                + getListId()
072                + "','"
073                + getId()
074                + "', '"
075                + CmsStringUtil.escapeJavaScript(wp.resolveMacros(getConfirmationMessage().key(wp.getLocale())))
076                + "', "
077                + CmsHtmlList.NO_SELECTION_MATCH_HELP_VAR
078                + getId()
079                + ", '"
080                + getRelatedActionIds()
081                + "');";
082            return A_CmsHtmlIconButton.defaultButtonHtml(
083                CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
084                getId(),
085                getName().key(wp.getLocale()),
086                getHelpText().key(wp.getLocale()),
087                isEnabled(),
088                getIconPath(),
089                null,
090                onClic);
091        }
092        return "";
093    }
094
095    /**
096     * Returns the number of expected selections.<p>
097     *
098     * @return the number of expected selections
099     */
100    public int getSelections() {
101
102        return m_relatedActionIds.size();
103    }
104
105    /**
106     * Returns a comma separated list of related list item selection action ids.<p>
107     *
108     * @return a comma separated list of related list item selection action ids
109     */
110    private String getRelatedActionIds() {
111
112        StringBuffer ret = new StringBuffer(32);
113        Iterator<String> it = m_relatedActionIds.iterator();
114        while (it.hasNext()) {
115            ret.append(it.next().trim());
116            if (it.hasNext()) {
117                ret.append(',');
118            }
119        }
120        return ret.toString();
121    }
122}