001/* 002 * (C) Copyright 2014 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 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.forms.layout.api.impl; 020 021import java.io.Serializable; 022import java.util.ArrayList; 023import java.util.HashMap; 024import java.util.List; 025import java.util.Map; 026 027import org.nuxeo.ecm.platform.forms.layout.api.BuiltinModes; 028import org.nuxeo.ecm.platform.forms.layout.api.LayoutDefinition; 029import org.nuxeo.ecm.platform.forms.layout.api.LayoutTypeConfiguration; 030 031/** 032 * @since 6.0 033 */ 034public class LayoutTypeConfigurationImpl implements LayoutTypeConfiguration { 035 036 private static final long serialVersionUID = 1L; 037 038 protected String sinceVersion; 039 040 protected String deprecatedVersion; 041 042 protected String title; 043 044 protected String description; 045 046 protected String demoId; 047 048 protected boolean demoPreviewEnabled = false; 049 050 protected List<String> supportedModes; 051 052 protected boolean handlingLabels = false; 053 054 protected List<String> supportedControls; 055 056 protected boolean containingForm = false; 057 058 protected List<String> categories; 059 060 protected Map<String, List<LayoutDefinition>> propertyLayouts; 061 062 protected Map<String, Map<String, Serializable>> defaultPropertyValues; 063 064 protected Map<String, List<LayoutDefinition>> fieldLayouts; 065 066 public LayoutTypeConfigurationImpl() { 067 super(); 068 } 069 070 public String getSinceVersion() { 071 return sinceVersion; 072 } 073 074 public void setSinceVersion(String sinceVersion) { 075 this.sinceVersion = sinceVersion; 076 } 077 078 public String getDeprecatedVersion() { 079 return deprecatedVersion; 080 } 081 082 public void setDeprecatedVersion(String deprecatedVersion) { 083 this.deprecatedVersion = deprecatedVersion; 084 } 085 086 public String getTitle() { 087 return title; 088 } 089 090 public void setTitle(String title) { 091 this.title = title; 092 } 093 094 public String getDescription() { 095 return description; 096 } 097 098 public void setDescription(String description) { 099 this.description = description; 100 } 101 102 public String getDemoId() { 103 return demoId; 104 } 105 106 public void setDemoId(String demoId) { 107 this.demoId = demoId; 108 } 109 110 public boolean isDemoPreviewEnabled() { 111 return demoPreviewEnabled; 112 } 113 114 public void setDemoPreviewEnabled(boolean demoPreviewEnabled) { 115 this.demoPreviewEnabled = demoPreviewEnabled; 116 } 117 118 public List<String> getSupportedModes() { 119 return supportedModes; 120 } 121 122 public void setSupportedModes(List<String> supportedModes) { 123 this.supportedModes = supportedModes; 124 } 125 126 public boolean isHandlingLabels() { 127 return handlingLabels; 128 } 129 130 public void setHandlingLabels(boolean handlingLabels) { 131 this.handlingLabels = handlingLabels; 132 } 133 134 public List<String> getSupportedControls() { 135 return supportedControls; 136 } 137 138 public void setSupportedControls(List<String> supportedControls) { 139 this.supportedControls = supportedControls; 140 } 141 142 public boolean isContainingForm() { 143 return containingForm; 144 } 145 146 public void setContainingForm(boolean containingForm) { 147 this.containingForm = containingForm; 148 } 149 150 public List<String> getCategories() { 151 return categories; 152 } 153 154 public void setCategories(List<String> categories) { 155 this.categories = categories; 156 } 157 158 public Map<String, List<LayoutDefinition>> getPropertyLayouts() { 159 return propertyLayouts; 160 } 161 162 public List<LayoutDefinition> getPropertyLayouts(String mode, String additionalMode) { 163 return getLayouts(propertyLayouts, mode, additionalMode); 164 } 165 166 public void setPropertyLayouts(Map<String, List<LayoutDefinition>> propertyLayouts) { 167 this.propertyLayouts = propertyLayouts; 168 } 169 170 public Map<String, Map<String, Serializable>> getDefaultPropertyValues() { 171 return defaultPropertyValues; 172 } 173 174 public Map<String, Serializable> getDefaultPropertyValues(String mode) { 175 if (defaultPropertyValues != null) { 176 Map<String, Serializable> res = new HashMap<String, Serializable>(); 177 Map<String, Serializable> anyProps = defaultPropertyValues.get(BuiltinModes.ANY); 178 if (anyProps != null) { 179 res.putAll(anyProps); 180 } 181 Map<String, Serializable> modeProps = defaultPropertyValues.get(mode); 182 if (modeProps != null) { 183 res.putAll(modeProps); 184 } 185 return res; 186 } 187 return null; 188 } 189 190 public void setDefaultPropertyValues(Map<String, Map<String, Serializable>> defaultPropertyValues) { 191 this.defaultPropertyValues = defaultPropertyValues; 192 } 193 194 protected List<LayoutDefinition> getLayouts(Map<String, List<LayoutDefinition>> allLayouts, String mode, 195 String additionalMode) { 196 if (allLayouts != null) { 197 List<LayoutDefinition> res = new ArrayList<LayoutDefinition>(); 198 if (additionalMode != null) { 199 List<LayoutDefinition> defaultLayouts = allLayouts.get(additionalMode); 200 if (defaultLayouts != null) { 201 res.addAll(defaultLayouts); 202 } 203 } 204 List<LayoutDefinition> modeLayouts = allLayouts.get(mode); 205 if (modeLayouts != null) { 206 res.addAll(modeLayouts); 207 } 208 return res; 209 } 210 return null; 211 } 212 213 /** 214 * @since 7.2 215 */ 216 @Override 217 public boolean equals(Object obj) { 218 if (!(obj instanceof LayoutTypeConfigurationImpl)) { 219 return false; 220 } 221 if (obj == this) { 222 return true; 223 } 224 LayoutTypeConfigurationImpl lc = (LayoutTypeConfigurationImpl) obj; 225 return new EqualsBuilder().append(sinceVersion, lc.sinceVersion).append(deprecatedVersion, lc.deprecatedVersion).append( 226 title, lc.title).append(description, lc.description).append(demoId, lc.demoId).append( 227 demoPreviewEnabled, lc.demoPreviewEnabled).append(supportedModes, lc.supportedModes).append( 228 handlingLabels, lc.handlingLabels).append(supportedControls, lc.supportedControls).append( 229 containingForm, lc.containingForm).append(categories, lc.categories).append(propertyLayouts, 230 lc.propertyLayouts).append(defaultPropertyValues, lc.defaultPropertyValues).append(fieldLayouts, 231 lc.fieldLayouts).isEquals(); 232 } 233 234}