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, 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.editors.directedit;
029
030/**
031 * Constants to indicate which direct edit buttons should be displayed for a direct edit resource
032 * if the user has the permissions.<p>
033 *
034 * The actual permission check is done later using {@link CmsDirectEditPermissions}.<p>
035 *
036 * This button selection is used internally to indicate the buttons that <i>may</i> be displayed.
037 * Usually, for an XmlPage only the "edit" button is displayed, while for an XmlContent
038 * there may be an "edit", "delete" or "new" button.<p>
039 *
040 * Currently there are only constants for thouse button combinations that are actually used
041 * in practice. These are {@link #EDIT}, {@link #EDIT_DELETE} and {@link #EDIT_DELETE_NEW}.<p>
042 *
043 * @since 6.2.3
044 */
045public final class CmsDirectEditButtonSelection {
046
047    /** Constant to indicate "show only the edit button". */
048    public static final CmsDirectEditButtonSelection EDIT = new CmsDirectEditButtonSelection(true, false, false);
049
050    /** Constant to indicate "show the edit and the delete button". */
051    public static final CmsDirectEditButtonSelection EDIT_DELETE = new CmsDirectEditButtonSelection(true, true, false);
052
053    /** Constant to indicate "show the edit and the delete button". */
054    public static final CmsDirectEditButtonSelection EDIT_NEW = new CmsDirectEditButtonSelection(true, false, true);
055
056    /** Constant to indicate "show the edit, the delete and the new button". */
057    public static final CmsDirectEditButtonSelection EDIT_DELETE_NEW = new CmsDirectEditButtonSelection(
058        true,
059        true,
060        true);
061
062    /** Constant to indicate "show only the new button" used on empty lists. */
063    public static final CmsDirectEditButtonSelection NEW = new CmsDirectEditButtonSelection(false, false, true);
064
065    /** String value that indicates the "delete" button should be displayed. */
066    public static final String VALUE_DELETE = "delete";
067
068    /** String value that indicates the "edit" button should be displayed. */
069    public static final String VALUE_EDIT = "edit";
070
071    /** String value that indicates the "new" button should be displayed. */
072    public static final String VALUE_NEW = "new";
073
074    /** Indicates if the "delete" button should be displayed. */
075    private boolean m_showDelete;
076
077    /** Indicates if the "edit" button should be displayed. */
078    private boolean m_showEdit;
079
080    /** Indicates if the "new" button should be displayed. */
081    private boolean m_showNew;
082
083    /** Pre-calculated String value. */
084    private String m_stringValue;
085
086    /**
087     * Hides the public constructor.<p>
088     *
089     * @param showEdit if <code>true</code> then the "edit" button should be displayed
090     * @param showDelete if <code>true</code> then the "delete" button should be displayed
091     * @param showNew if <code>true</code> then the "new" button should be displayed
092     */
093    private CmsDirectEditButtonSelection(boolean showEdit, boolean showDelete, boolean showNew) {
094
095        m_showEdit = showEdit;
096        m_showDelete = showDelete;
097        m_showNew = showNew;
098    }
099
100    /**
101     * Returns <code>true</code> if the "delete" button should be displayed.<p>
102     *
103     * @return <code>true</code> if the "delete" button should be displayed
104     */
105    public boolean isShowDelete() {
106
107        return m_showDelete;
108    }
109
110    /**
111     * Returns <code>true</code> if the "edit" button should be displayed.<p>
112     *
113     * @return <code>true</code> if the "edit" button should be displayed
114     */
115    public boolean isShowEdit() {
116
117        return m_showEdit;
118    }
119
120    /**
121     * Returns <code>true</code> if the "new" button should be displayed.<p>
122     *
123     * @return <code>true</code> if the "new" button should be displayed
124     */
125    public boolean isShowNew() {
126
127        return m_showNew;
128    }
129
130    /**
131     * Returns the selected edit options as a String in the form <code>edit|delete|new</code>.<p>
132     *
133     * @return the selected edit options as a String
134     */
135    @Override
136    public String toString() {
137
138        if (m_stringValue == null) {
139            StringBuffer result = new StringBuffer(32);
140            if (m_showEdit) {
141                result.append(VALUE_EDIT);
142            }
143            result.append('|');
144            if (m_showDelete) {
145                result.append(VALUE_DELETE);
146            }
147            result.append('|');
148            if (m_showNew) {
149                result.append(VALUE_NEW);
150            }
151            m_stringValue = result.toString();
152        }
153        return m_stringValue;
154    }
155}