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.ui.contextmenu;
029
030import org.opencms.util.A_CmsModeIntEnumeration;
031
032/**
033 * The visibility modes of a context menu item in the explorer view.<p>
034 *
035 * @since 6.5.6
036 */
037public final class CmsMenuItemVisibilityMode extends A_CmsModeIntEnumeration {
038
039    /** Menu item visibility: active.  */
040    public static final CmsMenuItemVisibilityMode VISIBILITY_ACTIVE = new CmsMenuItemVisibilityMode(1);
041
042    /** Menu item visibility: inactive.  */
043    public static final CmsMenuItemVisibilityMode VISIBILITY_INACTIVE = new CmsMenuItemVisibilityMode(2);
044
045    /** Menu item visibility: invisible.  */
046    public static final CmsMenuItemVisibilityMode VISIBILITY_INVISIBLE = new CmsMenuItemVisibilityMode(3);
047
048    /** Serializable version id. */
049    private static final long serialVersionUID = 2526260041565757791L;
050
051    /** The name of the message key for the visibility mode. */
052    private String m_messageKey;
053
054    /** The prioritization flag. */
055    private boolean m_prioritized;
056
057    /**
058     * Private constructor.<p>
059     *
060     * @param mode the menu item visibility mode integer representation
061     */
062    private CmsMenuItemVisibilityMode(int mode) {
063
064        super(mode);
065    }
066
067    /**
068     * Utilitiy method that returns 'active' if the parameter is true, otherwise inactive.<p>
069     *
070     * @param active - whether return value should be 'active'
071     *
072     * @return the visibility
073     */
074    public static CmsMenuItemVisibilityMode activeInactive(boolean active) {
075
076        if (active) {
077            return VISIBILITY_ACTIVE;
078        } else {
079            return VISIBILITY_INACTIVE;
080        }
081    }
082
083    /**
084     * Utility method that returns 'active' if the parameter is true, otherwise invisible.<p>
085     *
086     * @param active - whether return value should be 'active' rather than 'invisible'
087     *
088     * @return the visibility
089     */
090    public static CmsMenuItemVisibilityMode activeInvisible(boolean active) {
091
092        if (active) {
093            return VISIBILITY_ACTIVE;
094        } else {
095            return VISIBILITY_INVISIBLE;
096        }
097    }
098
099    /**
100     * Returns the menu item visibility mode for the given mode value.<p>
101     *
102     * This is used only for serialization and should not be accessed for other purposes.<p>
103     *
104     * @param type the mode value to get the item visibility mode for
105     *
106     * @return the menu item visibility mode for the given mode value
107     */
108    public static CmsMenuItemVisibilityMode valueOf(int type) {
109
110        switch (type) {
111            case 1:
112                return VISIBILITY_ACTIVE;
113            case 2:
114                return VISIBILITY_INACTIVE;
115            case 3:
116                return VISIBILITY_INVISIBLE;
117            default:
118                return VISIBILITY_INVISIBLE;
119        }
120    }
121
122    /**
123     * Adds the name of the message key for the visibility mode.<p>
124     *
125     * @param messageKey the name of the message key for the visibility mode
126     * @return an extended visibility mode containing the message key
127     */
128    public CmsMenuItemVisibilityMode addMessageKey(String messageKey) {
129
130        CmsMenuItemVisibilityMode mode = clone();
131        mode.m_messageKey = messageKey;
132        return mode;
133    }
134
135    /**
136     * Returns the name of the message key for the visibility mode.<p>
137     *
138     * Is usually used as description for the inactive visibility modes.<p>
139     *
140     * @return the name of the message key for the visibility mode
141     */
142    public String getMessageKey() {
143
144        return m_messageKey;
145    }
146
147    /**
148     * Returns if the mode is set to {@link #VISIBILITY_ACTIVE}.<p>
149     *
150     * @return true if the mode is set to {@link #VISIBILITY_ACTIVE}, otherwise false
151     */
152    public boolean isActive() {
153
154        return getMode() == VISIBILITY_ACTIVE.getMode();
155    }
156
157    /**
158     * Returns if the mode is set to {@link #VISIBILITY_INACTIVE}.<p>
159     *
160     * @return true if the mode is set to {@link #VISIBILITY_INACTIVE}, otherwise false
161     */
162    public boolean isInActive() {
163
164        return getMode() == VISIBILITY_INACTIVE.getMode();
165    }
166
167    /**
168     * Returns if the mode is set to {@link #VISIBILITY_INVISIBLE}.<p>
169     *
170     * @return true if the mode is set to {@link #VISIBILITY_INVISIBLE}, otherwise false
171     */
172    public boolean isInVisible() {
173
174        return getMode() == VISIBILITY_INVISIBLE.getMode();
175    }
176
177    /**
178     * Returns the prioritization flag.<p>
179     *
180     * @return prioritization flag
181     */
182    public boolean isPrioritized() {
183
184        return m_prioritized;
185    }
186
187    /**
188     * Returns a prioritized instance of the visibility mode.<p>
189     *
190     * @param prioritized <code>true</code> to prioritize
191     *
192     * @return the new visibility mode instance
193     */
194    public CmsMenuItemVisibilityMode prioritize(boolean prioritized) {
195
196        if (m_prioritized != prioritized) {
197            CmsMenuItemVisibilityMode result = clone();
198            result.m_prioritized = prioritized;
199            return result;
200        } else {
201            return this;
202        }
203    }
204
205    /**
206     * @see java.lang.Object#clone()
207     */
208    @Override
209    protected CmsMenuItemVisibilityMode clone() {
210
211        return new CmsMenuItemVisibilityMode(getMode());
212    }
213
214}