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