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.tools.projects;
029
030import org.opencms.main.CmsIllegalArgumentException;
031
032import java.io.Serializable;
033import java.util.Arrays;
034import java.util.Collections;
035import java.util.Iterator;
036import java.util.List;
037
038/**
039 * Wrapper class for
040 * the different types of project files view.<p>
041 *
042 * The possibles values are:<br>
043 * <ul>
044 *   <li>{@link #ALL_CHANGES}</li>
045 *   <li>{@link #NEW_FILES}</li>
046 *   <li>{@link #DELETED_FILES}</li>
047 *   <li>{@link #MODIFIED_FILES}</li>
048 * </ul>
049 * <p>
050 *
051 * @since 6.0.0
052 */
053public final class CmsProjectResourcesDisplayMode implements Serializable {
054
055    /** Serial version UID required for safe serialization. */
056    private static final long serialVersionUID = 923124162399716633L;
057
058    /** Constant for the all changes view. */
059    public static final CmsProjectResourcesDisplayMode ALL_CHANGES = new CmsProjectResourcesDisplayMode("all");
060
061    /** Constant for the deleted files only view.  */
062    public static final CmsProjectResourcesDisplayMode DELETED_FILES = new CmsProjectResourcesDisplayMode("deleted");
063
064    /** Constant for the modified files only view.     */
065    public static final CmsProjectResourcesDisplayMode MODIFIED_FILES = new CmsProjectResourcesDisplayMode("changed");
066
067    /** Constant for the new files only view. */
068    public static final CmsProjectResourcesDisplayMode NEW_FILES = new CmsProjectResourcesDisplayMode("new");
069
070    /** Array constant for all available align types. */
071    private static final CmsProjectResourcesDisplayMode[] VALUE_ARRAY = {
072        ALL_CHANGES,
073        NEW_FILES,
074        DELETED_FILES,
075        MODIFIED_FILES};
076
077    /** List of mode constants. */
078    public static final List VALUES = Collections.unmodifiableList(Arrays.asList(VALUE_ARRAY));
079
080    /** Internal representation. */
081    private final String m_mode;
082
083    /**
084     * Private constructor.<p>
085     *
086     * @param mode the view mode
087     */
088    private CmsProjectResourcesDisplayMode(String mode) {
089
090        m_mode = mode;
091    }
092
093    /**
094     * Parses an string into an element of this enumeration.<p>
095     *
096     * @param value the mode to parse
097     *
098     * @return the enumeration element
099     *
100     * @throws CmsIllegalArgumentException if the given value could not be matched against a
101     *         <code>CmsListColumnAlignEnum</code> type.
102     */
103    public static CmsProjectResourcesDisplayMode valueOf(String value) throws CmsIllegalArgumentException {
104
105        Iterator iter = VALUES.iterator();
106        while (iter.hasNext()) {
107            CmsProjectResourcesDisplayMode target = (CmsProjectResourcesDisplayMode)iter.next();
108            if (value.equals(target.getMode())) {
109                return target;
110            }
111        }
112        throw new CmsIllegalArgumentException(
113            org.opencms.db.Messages.get().container(
114                org.opencms.db.Messages.ERR_MODE_ENUM_PARSE_2,
115                value,
116                CmsProjectResourcesDisplayMode.class.getName()));
117    }
118
119    /**
120     * Returns the mode string.<p>
121     *
122     * @return the mode string
123     */
124    public String getMode() {
125
126        return m_mode;
127    }
128
129    /**
130     * @see java.lang.Object#toString()
131     */
132    @Override
133    public String toString() {
134
135        return m_mode;
136    }
137}