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: BuiltinModes.java 28460 2008-01-03 15:34:05Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.forms.layout.api; 021 022/** 023 * List of built-in modes. 024 * 025 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 026 */ 027public class BuiltinModes { 028 029 public static final String ANY = "any"; 030 031 public static final String VIEW = "view"; 032 033 public static final String EDIT = "edit"; 034 035 public static final String BULK_EDIT = "bulkEdit"; 036 037 public static final String CREATE = "create"; 038 039 public static final String SEARCH = "search"; 040 041 /** 042 * @deprecated: use {@link #VIEW} instead 043 */ 044 @Deprecated 045 public static final String LISTING = "listing"; 046 047 public static final String SUMMARY = "summary"; 048 049 /** 050 * @deprecated: use {@link #VIEW} instead 051 * @since 5.4.2 052 */ 053 @Deprecated 054 protected static final String HEADER = "header"; 055 056 /** 057 * @since 5.4.2 058 */ 059 public static final String CSV = "csv"; 060 061 /** 062 * @since 5.4.2 063 */ 064 public static final String PDF = "pdf"; 065 066 /** 067 * @since 5.4.2 068 */ 069 public static final String PLAIN = "plain"; 070 071 /** 072 * @since 6.0 073 */ 074 public static final String DEV = "dev"; 075 076 private BuiltinModes() { 077 } 078 079 /** 080 * Returns true if given layout mode is mapped by default to the edit widget mode. 081 */ 082 public static boolean isBoundToEditMode(String layoutMode) { 083 if (layoutMode != null) { 084 if (layoutMode.startsWith(CREATE) || layoutMode.startsWith(EDIT) || layoutMode.startsWith(SEARCH) 085 || layoutMode.startsWith(BULK_EDIT)) { 086 return true; 087 } 088 } 089 return false; 090 } 091 092 /** 093 * Returns the default mode to use for a widget, given the layout mode. 094 * <p> 095 * Returns {@link BuiltinWidgetModes#EDIT} for all modes bound to edit, {@link BuiltinWidgetModes#VIEW} for modes 096 * {@link #VIEW}, {@link #HEADER} and {@link #SUMMARY}. {@link #PDF} and {@link #CSV} are respectively bound to 097 * {@link BuiltinWidgetModes#PDF} and {@link BuiltinWidgetModes#CSV}. In other cases, returns 098 * {@link BuiltinWidgetModes#PLAIN}. 099 * <p> 100 * This method is not called when mode is explicitely set on the widget. 101 */ 102 public static String getWidgetModeFromLayoutMode(String layoutMode) { 103 if (layoutMode != null) { 104 if (isBoundToEditMode(layoutMode)) { 105 return BuiltinWidgetModes.EDIT; 106 } else if (layoutMode.startsWith(VIEW) || layoutMode.startsWith(SUMMARY) || layoutMode.startsWith(LISTING) 107 || layoutMode.startsWith(HEADER)) { 108 return BuiltinWidgetModes.VIEW; 109 } else if (layoutMode.startsWith(CSV)) { 110 return BuiltinWidgetModes.CSV; 111 } else if (layoutMode.startsWith(PDF)) { 112 return BuiltinWidgetModes.PDF; 113 } 114 } 115 return BuiltinWidgetModes.PLAIN; 116 } 117 118}