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.i18n.CmsMessageContainer;
031import org.opencms.util.CmsStringUtil;
032import org.opencms.workplace.CmsWorkplace;
033import org.opencms.workplace.tools.A_CmsHtmlIconButton;
034import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum;
035
036/**
037 * Abstract implementation of a search action.<p>
038 *
039 * It provides the default show all action accessor and the rendering method.<p>
040 *
041 * @since 6.0.0
042 */
043public abstract class A_CmsListSearchAction extends CmsListIndependentAction {
044
045    /** The action id for the search action. */
046    public static final String SEARCH_ACTION_ID = "search";
047
048    /** The action id for the show all action. */
049    public static final String SHOWALL_ACTION_ID = "showall";
050
051    /** Default confirmation message for search action. */
052    private static final CmsMessageContainer SEARCH_CONFIRMATION = new CmsMessageContainer(
053        Messages.get(),
054        Messages.GUI_LIST_ACTION_SEARCH_CONF_0);
055
056    /** Default icon for search action. */
057    private static final String SEARCH_ICON = "list/search.png";
058
059    /** Default name for search action. */
060    private static final CmsMessageContainer SEARCH_NAME = new CmsMessageContainer(
061        Messages.get(),
062        Messages.GUI_LIST_ACTION_SEARCH_NAME_0);
063
064    /** Default confirmation message for show all action. */
065    private static final CmsMessageContainer SHOWALL_CONFIRMATION = new CmsMessageContainer(
066        Messages.get(),
067        Messages.GUI_LIST_ACTION_SHOWALL_CONF_0);
068
069    /** Default help text for show all action. */
070    private static final CmsMessageContainer SHOWALL_HELPTEXT = new CmsMessageContainer(
071        Messages.get(),
072        Messages.GUI_LIST_ACTION_SHOWALL_HELP_0);
073
074    /** Default icon for show all action. */
075    private static final String SHOWALL_ICON = "list/showall.png";
076
077    /** Default name for show all action. */
078    private static final CmsMessageContainer SHOWALL_NAME = new CmsMessageContainer(
079        Messages.get(),
080        Messages.GUI_LIST_ACTION_SHOWALL_NAME_0);
081
082    /** A default show all action. */
083    public final I_CmsListAction m_defaultShowAllAction;
084
085    /** Show all action. */
086    private I_CmsListAction m_showAllAction;
087
088    /**
089     * Default Constructor.<p>
090     */
091    protected A_CmsListSearchAction() {
092
093        super(SEARCH_ACTION_ID);
094        setName(SEARCH_NAME);
095        setIconPath(SEARCH_ICON);
096        setConfirmationMessage(SEARCH_CONFIRMATION);
097        setHelpText(null);
098
099        m_defaultShowAllAction = createDefaultShowAllAction();
100    }
101
102    /**
103     * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#buttonHtml(CmsWorkplace)
104     */
105    @Override
106    public String buttonHtml(CmsWorkplace wp) {
107
108        if (!isVisible()) {
109            return "";
110        }
111        String onClic = "listSearchAction('"
112            + getListId()
113            + "', '"
114            + getId()
115            + "', '"
116            + CmsStringUtil.escapeJavaScript(wp.resolveMacros(getConfirmationMessage().key(wp.getLocale())))
117            + "');";
118        return A_CmsHtmlIconButton.defaultButtonHtml(
119            CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
120            getId(),
121            getName().key(wp.getLocale()),
122            getHelpText().key(wp.getLocale()),
123            isEnabled(),
124            getIconPath(),
125            null,
126            onClic);
127    }
128
129    /**
130     * Returns the Show-All action.<p>
131     *
132     * @return the Show-All action
133     */
134    public I_CmsListAction getShowAllAction() {
135
136        return m_showAllAction;
137    }
138
139    /**
140     * @see org.opencms.workplace.list.A_CmsListAction#setListId(java.lang.String)
141     */
142    @Override
143    public void setListId(String listId) {
144
145        super.setListId(listId);
146        m_defaultShowAllAction.setListId(listId);
147    }
148
149    /**
150     * Sets the Show-All action.<p>
151     *
152     * @param showAllAction the Show-All action to set
153     */
154    public void setShowAllAction(I_CmsListAction showAllAction) {
155
156        m_showAllAction = showAllAction;
157    }
158
159    /**
160     * Sets the current used show-all action to the default.<p>
161     */
162    public void useDefaultShowAllAction() {
163
164        m_showAllAction = m_defaultShowAllAction;
165    }
166
167    /**
168     * Creates a default show all action.<p>
169     *
170     * @return default show all action
171     */
172    private I_CmsListAction createDefaultShowAllAction() {
173
174        I_CmsListAction defaultShowAllAction = new CmsListIndependentAction(SHOWALL_ACTION_ID) {
175
176            /**
177             * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#buttonHtml(CmsWorkplace)
178             */
179            @Override
180            public String buttonHtml(CmsWorkplace wp) {
181
182                if (!isVisible()) {
183                    return "";
184                }
185                String onClic = "listSearchAction('"
186                    + getListId()
187                    + "', '"
188                    + getId()
189                    + "', '"
190                    + CmsStringUtil.escapeJavaScript(wp.resolveMacros(getConfirmationMessage().key(wp.getLocale())))
191                    + "');";
192                return A_CmsHtmlIconButton.defaultButtonHtml(
193                    CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
194                    getId(),
195                    getName().key(wp.getLocale()),
196                    getHelpText().key(wp.getLocale()),
197                    isEnabled(),
198                    getIconPath(),
199                    null,
200                    onClic);
201            }
202        };
203        defaultShowAllAction.setName(SHOWALL_NAME);
204        defaultShowAllAction.setHelpText(SHOWALL_HELPTEXT);
205        defaultShowAllAction.setIconPath(SHOWALL_ICON);
206        defaultShowAllAction.setConfirmationMessage(SHOWALL_CONFIRMATION);
207        return defaultShowAllAction;
208    }
209}