001/*19 002 * (C) Copyright 2006-20 Nuxeo (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 */ 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 public static final String SUMMARY = "summary"; 042 043 /** 044 * @since 5.4.2 045 */ 046 public static final String CSV = "csv"; 047 048 /** 049 * @since 5.4.2 050 */ 051 public static final String PDF = "pdf"; 052 053 /** 054 * @since 5.4.2 055 */ 056 public static final String PLAIN = "plain"; 057 058 /** 059 * @since 6.0 060 */ 061 public static final String DEV = "dev"; 062 063 private BuiltinModes() { 064 } 065 066 /** 067 * Returns true if given layout mode is mapped by default to the edit widget mode. 068 */ 069 public static boolean isBoundToEditMode(String layoutMode) { 070 if (layoutMode != null) { 071 if (layoutMode.startsWith(CREATE) || layoutMode.startsWith(EDIT) || layoutMode.startsWith(SEARCH) 072 || layoutMode.startsWith(BULK_EDIT)) { 073 return true; 074 } 075 } 076 return false; 077 } 078 079 /** 080 * Returns the default mode to use for a widget, given the layout mode. 081 * <p> 082 * Returns {@link BuiltinWidgetModes#EDIT} for all modes bound to edit, {@link BuiltinWidgetModes#VIEW} for modes 083 * {@link #VIEW} and {@link #SUMMARY}. {@link #PDF} and {@link #CSV} are respectively bound to 084 * {@link BuiltinWidgetModes#PDF} and {@link BuiltinWidgetModes#CSV}. In other cases, returns 085 * {@link BuiltinWidgetModes#PLAIN}. 086 * <p> 087 * This method is not called when mode is explicitely set on the widget. 088 */ 089 public static String getWidgetModeFromLayoutMode(String layoutMode) { 090 if (layoutMode != null) { 091 if (isBoundToEditMode(layoutMode)) { 092 return BuiltinWidgetModes.EDIT; 093 } else if (layoutMode.startsWith(VIEW) || layoutMode.startsWith(SUMMARY)) { 094 return BuiltinWidgetModes.VIEW; 095 } else if (layoutMode.startsWith(CSV)) { 096 return BuiltinWidgetModes.CSV; 097 } else if (layoutMode.startsWith(PDF)) { 098 return BuiltinWidgetModes.PDF; 099 } 100 } 101 return BuiltinWidgetModes.PLAIN; 102 } 103 104}