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.workplace.CmsWorkplace;
031import org.opencms.workplace.tools.A_CmsHtmlIconButton;
032import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum;
033
034/**
035 * Default implementation of a list item selection action.<p>
036 *
037 * @since 6.0.0
038 */
039public class CmsListItemSelectionAction extends CmsListDirectAction {
040
041    /** The id of the related multi action. */
042    private final String m_multiActionId;
043
044    /** The id of the selected item. */
045    private String m_selectedItemId;
046
047    /**
048     * Default Constructor.<p>
049     *
050     * @param id the unique id
051     * @param multiActionId the id of the related multi Action
052     */
053    public CmsListItemSelectionAction(String id, String multiActionId) {
054
055        super(id);
056        m_multiActionId = multiActionId;
057    }
058
059    /**
060     * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#buttonHtml(CmsWorkplace)
061     */
062    @Override
063    public String buttonHtml(CmsWorkplace wp) {
064
065        if (!isVisible()) {
066            return "";
067        }
068        String html = "<input type='radio' value='" + getItem().getId() + "' name='" + getListId() + getId() + "'";
069        if (!isEnabled()) {
070            html += " disabled";
071        }
072        if (getItem().getId().equals(getSelectedItemId())) {
073            html += " checked";
074        }
075        html += ">\n";
076        return A_CmsHtmlIconButton.defaultButtonHtml(
077            CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
078            getId(),
079            html,
080            getHelpText().key(wp.getLocale()),
081            true,
082            null,
083            null,
084            null);
085    }
086
087    /**
088     * Returns the id of the related multi Action.<p>
089     *
090     * @return the id of the related multi Action
091     */
092    public String getMultiActionId() {
093
094        return m_multiActionId;
095    }
096
097    /**
098     * Returns the selected item Id.<p>
099     *
100     * @return the selected item Id
101     */
102    public String getSelectedItemId() {
103
104        return m_selectedItemId;
105    }
106
107    /**
108     * Sets the selected item Id.<p>
109     *
110     * @param selectedItemId the selected item Id to set
111     */
112    public void setSelectedItemId(String selectedItemId) {
113
114        m_selectedItemId = selectedItemId;
115    }
116}