001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
018 *
019 * $Id: BuiltinWidgetModes.java 28460 2008-01-03 15:34:05Z sfermigier $
020 */
021
022package org.nuxeo.ecm.platform.forms.layout.api;
023
024import java.util.List;
025
026/**
027 * List of built in widget modes.
028 *
029 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
030 */
031public class BuiltinWidgetModes {
032
033    public static final String VIEW = BuiltinModes.VIEW;
034
035    public static final String EDIT = BuiltinModes.EDIT;
036
037    /**
038     * @since 5.4.2
039     */
040    public static final String PLAIN = BuiltinModes.PLAIN;
041
042    /**
043     * @since 5.4.2
044     */
045    public static final String CSV = BuiltinModes.CSV;
046
047    /**
048     * @since 5.4.2
049     */
050    public static final String PDF = BuiltinModes.PDF;
051
052    public static final String HIDDEN = "hidden";
053
054    private BuiltinWidgetModes() {
055    }
056
057    public static boolean isModeSupported(String widgetMode, List<String> supportedModes) {
058        if (BuiltinWidgetModes.HIDDEN.equals(widgetMode)) {
059            // always supported
060            return true;
061        } else if (supportedModes != null) {
062            return supportedModes.contains(widgetMode);
063        }
064        return false;
065    }
066
067    /**
068     * Returns true if given mode is one of {@link #PLAIN}, or {@link #CSV}.
069     *
070     * @since 5.4.2
071     */
072    public static boolean isLikePlainMode(String widgetMode) {
073        if (widgetMode != null) {
074            if (PLAIN.equals(widgetMode) || CSV.equals(widgetMode)) {
075                return true;
076            }
077        }
078        return false;
079    }
080
081    /**
082     * Returns true if given mode is not null and is not one of {@link #EDIT}, {@link #PLAIN}, {@link #CSV},
083     * {@link #PDF} or {@link #HIDDEN} mode.
084     *
085     * @since 5.4.2
086     * @param widgetMode
087     * @return
088     */
089    public static boolean isLikeViewMode(String widgetMode) {
090        if (widgetMode == null) {
091            return false;
092        }
093        if (BuiltinWidgetModes.EDIT.equals(widgetMode) || BuiltinWidgetModes.PLAIN.equals(widgetMode)
094                || BuiltinWidgetModes.CSV.equals(widgetMode) || BuiltinWidgetModes.PDF.equals(widgetMode)
095                || BuiltinWidgetModes.HIDDEN.equals(widgetMode)) {
096            return false;
097        }
098        return true;
099    }
100
101}