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
035/**
036 * Implementation of a list item selection action where to define name and the column with the value.<p>
037 *
038 * @since 6.7.2
039 */
040public class CmsListItemSelectionCustomAction extends CmsListItemSelectionAction {
041
042    /** The attributes to set at the input field. */
043    private String m_attributes;
044
045    /** The name of the column where to find the value. */
046    private String m_column;
047
048    /** The name of the input field. */
049    private String m_fieldName;
050
051    /**
052     * Default Constructor.<p>
053     *
054     * @param id the unique id
055     * @param columnValue the name of the column used for the value
056     */
057    public CmsListItemSelectionCustomAction(String id, String columnValue) {
058
059        this(id, columnValue, null);
060    }
061
062    /**
063     * Default Constructor.<p>
064     *
065     * @param id the unique id
066     * @param name the name of the input field
067     * @param columnValue the name of the column used for the value
068     */
069    public CmsListItemSelectionCustomAction(String id, String name, String columnValue) {
070
071        super(id, null);
072        m_fieldName = name;
073        m_column = columnValue;
074    }
075
076    /**
077     * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#buttonHtml(CmsWorkplace)
078     */
079    @Override
080    public String buttonHtml(CmsWorkplace wp) {
081
082        if (!isVisible()) {
083            return "";
084        }
085
086        String value = getItem().getId();
087        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_column)) {
088            value = (String)getItem().get(m_column);
089        }
090        String html = "<input type='radio' value='" + value + "' name='" + m_fieldName + "'";
091        if (!isEnabled()) {
092            html += " disabled";
093        }
094
095        if (getItem().getId().equals(getSelectedItemId())) {
096            html += " checked";
097        }
098
099        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_attributes)) {
100            html += m_attributes;
101        }
102        html += ">\n";
103        return A_CmsHtmlIconButton.defaultButtonHtml(
104            CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
105            getId(),
106            html,
107            getHelpText().key(wp.getLocale()),
108            false,
109            null,
110            null,
111            null);
112    }
113
114    /**
115     * Returns the attributes.<p>
116     *
117     * @return the attributes
118     */
119    public String getAttributes() {
120
121        return m_attributes;
122    }
123
124    /**
125     * Returns the column.<p>
126     *
127     * @return the column
128     */
129    public String getColumn() {
130
131        return m_column;
132    }
133
134    /**
135     * Returns the fieldName.<p>
136     *
137     * @return the fieldName
138     */
139    public String getFieldName() {
140
141        return m_fieldName;
142    }
143
144    /**
145     * Sets the attributes.<p>
146     *
147     * @param attributes the attributes to set
148     */
149    public void setAttributes(String attributes) {
150
151        m_attributes = attributes;
152    }
153
154    /**
155     * Sets the column.<p>
156     *
157     * @param column the column to set
158     */
159    public void setColumn(String column) {
160
161        m_column = column;
162    }
163
164    /**
165     * Sets the fieldName.<p>
166     *
167     * @param fieldName the fieldName to set
168     */
169    public void setFieldName(String fieldName) {
170
171        m_fieldName = fieldName;
172    }
173
174}