001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 016 * 017 * $Id: BuiltinWidgetModes.java 28460 2008-01-03 15:34:05Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.forms.layout.api; 021 022import java.util.List; 023 024/** 025 * List of built in widget modes. 026 * 027 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 028 */ 029public class BuiltinWidgetModes { 030 031 public static final String VIEW = BuiltinModes.VIEW; 032 033 public static final String EDIT = BuiltinModes.EDIT; 034 035 /** 036 * @since 5.4.2 037 */ 038 public static final String PLAIN = BuiltinModes.PLAIN; 039 040 /** 041 * @since 5.4.2 042 */ 043 public static final String CSV = BuiltinModes.CSV; 044 045 /** 046 * @since 5.4.2 047 */ 048 public static final String PDF = BuiltinModes.PDF; 049 050 public static final String HIDDEN = "hidden"; 051 052 private BuiltinWidgetModes() { 053 } 054 055 public static boolean isModeSupported(String widgetMode, List<String> supportedModes) { 056 if (BuiltinWidgetModes.HIDDEN.equals(widgetMode)) { 057 // always supported 058 return true; 059 } else if (supportedModes != null) { 060 return supportedModes.contains(widgetMode); 061 } 062 return false; 063 } 064 065 /** 066 * Returns true if given mode is one of {@link #PLAIN}, or {@link #CSV}. 067 * 068 * @since 5.4.2 069 */ 070 public static boolean isLikePlainMode(String widgetMode) { 071 if (widgetMode != null) { 072 if (PLAIN.equals(widgetMode) || CSV.equals(widgetMode)) { 073 return true; 074 } 075 } 076 return false; 077 } 078 079 /** 080 * Returns true if given mode is not null and is not one of {@link #EDIT}, {@link #PLAIN}, {@link #CSV}, 081 * {@link #PDF} or {@link #HIDDEN} mode. 082 * 083 * @since 5.4.2 084 * @param widgetMode 085 * @return 086 */ 087 public static boolean isLikeViewMode(String widgetMode) { 088 if (widgetMode == null) { 089 return false; 090 } 091 if (BuiltinWidgetModes.EDIT.equals(widgetMode) || BuiltinWidgetModes.PLAIN.equals(widgetMode) 092 || BuiltinWidgetModes.CSV.equals(widgetMode) || BuiltinWidgetModes.PDF.equals(widgetMode) 093 || BuiltinWidgetModes.HIDDEN.equals(widgetMode)) { 094 return false; 095 } 096 return true; 097 } 098 099}