001/* 002 * (C) Copyright 2009-2010 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.Collections; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027 028import org.nuxeo.ecm.platform.forms.layout.api.BuiltinModes; 029import org.nuxeo.ecm.platform.forms.layout.api.FieldDefinition; 030import org.nuxeo.ecm.platform.forms.layout.api.LayoutDefinition; 031import org.nuxeo.ecm.platform.forms.layout.api.WidgetTypeConfiguration; 032 033public class WidgetTypeConfigurationImpl implements WidgetTypeConfiguration { 034 035 private static final long serialVersionUID = 1L; 036 037 protected String sinceVersion; 038 039 protected String deprecatedVersion; 040 041 protected String title; 042 043 protected String description; 044 045 protected String demoId; 046 047 protected boolean demoPreviewEnabled = false; 048 049 protected Map<String, Serializable> properties; 050 051 protected List<String> supportedModes; 052 053 protected boolean acceptingSubWidgets = false; 054 055 protected boolean handlingLabels = false; 056 057 /** 058 * @since 5.9.1 059 */ 060 protected List<String> supportedControls; 061 062 protected boolean list = false; 063 064 protected boolean complex = false; 065 066 protected boolean containingForm = false; 067 068 protected List<String> supportedFieldTypes; 069 070 protected List<String> defaultFieldTypes; 071 072 protected List<FieldDefinition> defaultFieldDefinitions; 073 074 protected List<String> categories; 075 076 protected Map<String, List<LayoutDefinition>> propertyLayouts; 077 078 protected Map<String, Map<String, Serializable>> defaultPropertyValues; 079 080 protected Map<String, Map<String, Serializable>> defaultControlValues; 081 082 protected Map<String, List<LayoutDefinition>> fieldLayouts; 083 084 @SuppressWarnings({ "unchecked" }) 085 public WidgetTypeConfigurationImpl() { 086 this(null, null, null, null, false, Collections.EMPTY_MAP, Collections.EMPTY_LIST, false, false, false, false, 087 Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, 088 Collections.EMPTY_MAP); 089 } 090 091 /** 092 * @deprecated since 5.6: use setters instead 093 */ 094 @Deprecated 095 public WidgetTypeConfigurationImpl(String sinceVersion, String title, String description, String demoId, 096 boolean demoPreviewEnabled, Map<String, Serializable> properties, List<String> supportedModes, 097 boolean acceptingSubWidgets, boolean list, boolean complex, List<String> supportedFieldTypes, 098 List<String> defaultFieldTypes, List<FieldDefinition> defaultFieldDefinitions, List<String> categories, 099 Map<String, List<LayoutDefinition>> propertyLayouts) { 100 this(sinceVersion, title, description, demoId, demoPreviewEnabled, properties, supportedModes, 101 acceptingSubWidgets, list, complex, false, supportedFieldTypes, defaultFieldTypes, 102 defaultFieldDefinitions, categories, propertyLayouts); 103 } 104 105 /** 106 * @deprecated since 5.6: use setters instead 107 */ 108 @Deprecated 109 public WidgetTypeConfigurationImpl(String sinceVersion, String title, String description, String demoId, 110 boolean demoPreviewEnabled, Map<String, Serializable> properties, List<String> supportedModes, 111 boolean acceptingSubWidgets, boolean list, boolean complex, boolean containingForm, 112 List<String> supportedFieldTypes, List<String> defaultFieldTypes, 113 List<FieldDefinition> defaultFieldDefinitions, List<String> categories, 114 Map<String, List<LayoutDefinition>> propertyLayouts) { 115 super(); 116 this.sinceVersion = sinceVersion; 117 this.title = title; 118 this.description = description; 119 this.demoId = demoId; 120 this.demoPreviewEnabled = demoPreviewEnabled; 121 this.properties = properties; 122 this.supportedModes = supportedModes; 123 this.acceptingSubWidgets = acceptingSubWidgets; 124 this.list = list; 125 this.complex = complex; 126 this.containingForm = containingForm; 127 this.supportedFieldTypes = supportedFieldTypes; 128 this.defaultFieldTypes = defaultFieldTypes; 129 this.defaultFieldDefinitions = defaultFieldDefinitions; 130 this.categories = categories; 131 this.propertyLayouts = propertyLayouts; 132 } 133 134 @Override 135 public String getSinceVersion() { 136 return sinceVersion; 137 } 138 139 @Override 140 public String getDeprecatedVersion() { 141 return deprecatedVersion; 142 } 143 144 public String getTitle() { 145 return title; 146 } 147 148 public String getDescription() { 149 return description; 150 } 151 152 @Override 153 public String getDemoId() { 154 return demoId; 155 } 156 157 @Override 158 public boolean isDemoPreviewEnabled() { 159 return demoPreviewEnabled; 160 } 161 162 @Override 163 public Map<String, Serializable> getConfProperties() { 164 return properties; 165 } 166 167 @Override 168 public Serializable getConfProperty(String propName) { 169 if (properties == null) { 170 return null; 171 } 172 return properties.get(propName); 173 } 174 175 @Override 176 public List<String> getSupportedModes() { 177 return supportedModes; 178 } 179 180 @Override 181 public boolean isAcceptingSubWidgets() { 182 return acceptingSubWidgets; 183 } 184 185 public boolean isList() { 186 return list; 187 } 188 189 public boolean isComplex() { 190 return complex; 191 } 192 193 public boolean isContainingForm() { 194 return containingForm; 195 } 196 197 public List<String> getSupportedFieldTypes() { 198 return supportedFieldTypes; 199 } 200 201 public List<String> getDefaultFieldTypes() { 202 return defaultFieldTypes; 203 } 204 205 public List<FieldDefinition> getDefaultFieldDefinitions() { 206 return defaultFieldDefinitions; 207 } 208 209 public List<String> getCategories() { 210 return categories; 211 } 212 213 public Map<String, List<LayoutDefinition>> getPropertyLayouts() { 214 return propertyLayouts; 215 } 216 217 public List<LayoutDefinition> getLayouts(Map<String, List<LayoutDefinition>> allLayouts, String mode, 218 String additionalMode) { 219 if (allLayouts != null) { 220 List<LayoutDefinition> res = new ArrayList<LayoutDefinition>(); 221 if (additionalMode != null) { 222 List<LayoutDefinition> defaultLayouts = allLayouts.get(additionalMode); 223 if (defaultLayouts != null) { 224 res.addAll(defaultLayouts); 225 } 226 } 227 List<LayoutDefinition> modeLayouts = allLayouts.get(mode); 228 if (modeLayouts != null) { 229 res.addAll(modeLayouts); 230 } 231 return res; 232 } 233 return null; 234 } 235 236 public List<LayoutDefinition> getPropertyLayouts(String mode, String additionalMode) { 237 return getLayouts(propertyLayouts, mode, additionalMode); 238 } 239 240 /** 241 * @since 5.6 242 */ 243 public void setSinceVersion(String sinceVersion) { 244 this.sinceVersion = sinceVersion; 245 } 246 247 /** 248 * @since 5.6 249 */ 250 public void setDeprecatedVersion(String deprecatedVersion) { 251 this.deprecatedVersion = deprecatedVersion; 252 } 253 254 /** 255 * @since 5.6 256 */ 257 public void setTitle(String title) { 258 this.title = title; 259 } 260 261 /** 262 * @since 5.6 263 */ 264 public void setDescription(String description) { 265 this.description = description; 266 } 267 268 /** 269 * @since 5.6 270 */ 271 public void setDemoId(String demoId) { 272 this.demoId = demoId; 273 } 274 275 /** 276 * @since 5.6 277 */ 278 public void setDemoPreviewEnabled(boolean demoPreviewEnabled) { 279 this.demoPreviewEnabled = demoPreviewEnabled; 280 } 281 282 /** 283 * @since 5.6 284 */ 285 public void setProperties(Map<String, Serializable> properties) { 286 this.properties = properties; 287 } 288 289 /** 290 * @since 5.6 291 */ 292 public void setSupportedModes(List<String> supportedModes) { 293 this.supportedModes = supportedModes; 294 } 295 296 /** 297 * @since 5.6 298 */ 299 public void setAcceptingSubWidgets(boolean acceptingSubWidgets) { 300 this.acceptingSubWidgets = acceptingSubWidgets; 301 } 302 303 /** 304 * @since 5.6 305 */ 306 public void setList(boolean list) { 307 this.list = list; 308 } 309 310 /** 311 * @since 5.6 312 */ 313 public void setComplex(boolean complex) { 314 this.complex = complex; 315 } 316 317 /** 318 * @since 5.6 319 */ 320 public void setContainingForm(boolean containingForm) { 321 this.containingForm = containingForm; 322 } 323 324 /** 325 * @since 5.6 326 */ 327 public void setSupportedFieldTypes(List<String> supportedFieldTypes) { 328 this.supportedFieldTypes = supportedFieldTypes; 329 } 330 331 /** 332 * @since 5.6 333 */ 334 public void setDefaultFieldTypes(List<String> defaultFieldTypes) { 335 this.defaultFieldTypes = defaultFieldTypes; 336 } 337 338 /** 339 * @since 5.6 340 */ 341 public void setDefaultFieldDefinitions(List<FieldDefinition> defaultFieldDefinitions) { 342 this.defaultFieldDefinitions = defaultFieldDefinitions; 343 } 344 345 /** 346 * @since 5.6 347 */ 348 public void setCategories(List<String> categories) { 349 this.categories = categories; 350 } 351 352 /** 353 * @since 5.6 354 */ 355 public void setPropertyLayouts(Map<String, List<LayoutDefinition>> propertyLayouts) { 356 this.propertyLayouts = propertyLayouts; 357 } 358 359 /** 360 * @since 5.6 361 */ 362 public boolean isHandlingLabels() { 363 return handlingLabels; 364 } 365 366 /** 367 * @since 5.6 368 */ 369 public void setHandlingLabels(boolean handlingLabels) { 370 this.handlingLabels = handlingLabels; 371 } 372 373 /** 374 * @since 5.7.3 375 */ 376 public Map<String, Map<String, Serializable>> getDefaultPropertyValues() { 377 return defaultPropertyValues; 378 } 379 380 /** 381 * @since 5.7.3 382 */ 383 public Map<String, Serializable> getDefaultPropertyValues(String mode) { 384 if (defaultPropertyValues != null) { 385 Map<String, Serializable> res = new HashMap<String, Serializable>(); 386 Map<String, Serializable> anyProps = defaultPropertyValues.get(BuiltinModes.ANY); 387 if (anyProps != null) { 388 res.putAll(anyProps); 389 } 390 Map<String, Serializable> modeProps = defaultPropertyValues.get(mode); 391 if (modeProps != null) { 392 res.putAll(modeProps); 393 } 394 return res; 395 } 396 return null; 397 } 398 399 /** 400 * @since 5.7.3 401 */ 402 public void setDefaultPropertyValues(Map<String, Map<String, Serializable>> values) { 403 this.defaultPropertyValues = values; 404 } 405 406 /** 407 * @since 6.0 408 */ 409 public Map<String, Map<String, Serializable>> getDefaultControlValues() { 410 return defaultControlValues; 411 } 412 413 /** 414 * @since 6.0 415 */ 416 public Map<String, Serializable> getDefaultControlValues(String mode) { 417 if (defaultControlValues != null) { 418 Map<String, Serializable> res = new HashMap<String, Serializable>(); 419 Map<String, Serializable> anyProps = defaultControlValues.get(BuiltinModes.ANY); 420 if (anyProps != null) { 421 res.putAll(anyProps); 422 } 423 Map<String, Serializable> modeProps = defaultControlValues.get(mode); 424 if (modeProps != null) { 425 res.putAll(modeProps); 426 } 427 return res; 428 } 429 return null; 430 } 431 432 /** 433 * @since 6.0 434 */ 435 public void setDefaultControlValues(Map<String, Map<String, Serializable>> values) { 436 this.defaultControlValues = values; 437 } 438 439 @Override 440 public Map<String, List<LayoutDefinition>> getFieldLayouts() { 441 return fieldLayouts; 442 } 443 444 @Override 445 public List<LayoutDefinition> getFieldLayouts(String mode, String additionalMode) { 446 return getLayouts(fieldLayouts, mode, additionalMode); 447 } 448 449 /** 450 * @since 5.7.3 451 */ 452 public void setFieldLayouts(Map<String, List<LayoutDefinition>> fieldLayouts) { 453 this.fieldLayouts = fieldLayouts; 454 } 455 456 /** 457 * @since 5.9.1 458 */ 459 @Override 460 public List<String> getSupportedControls() { 461 return supportedControls; 462 } 463 464 /** 465 * @since 5.9.1 466 */ 467 public void setSupportedControls(List<String> supportedControls) { 468 this.supportedControls = supportedControls; 469 } 470 471 /** 472 * @since 7.2 473 */ 474 @Override 475 public boolean equals(Object obj) { 476 if (!(obj instanceof WidgetTypeConfigurationImpl)) { 477 return false; 478 } 479 if (obj == this) { 480 return true; 481 } 482 WidgetTypeConfigurationImpl wc = (WidgetTypeConfigurationImpl) obj; 483 return new EqualsBuilder().append(sinceVersion, wc.sinceVersion).append(deprecatedVersion, wc.deprecatedVersion).append( 484 title, wc.title).append(description, wc.description).append(demoId, wc.demoId).append( 485 demoPreviewEnabled, wc.demoPreviewEnabled).append(properties, wc.properties).append(supportedModes, 486 wc.supportedModes).append(acceptingSubWidgets, wc.acceptingSubWidgets).append(handlingLabels, 487 wc.handlingLabels).append(supportedControls, wc.supportedControls).append(list, wc.list).append( 488 complex, wc.complex).append(containingForm, wc.containingForm).append(supportedFieldTypes, 489 wc.supportedFieldTypes).append(defaultFieldTypes, wc.defaultFieldTypes).append(defaultFieldDefinitions, 490 wc.defaultFieldDefinitions).append(categories, wc.categories).append(propertyLayouts, 491 wc.propertyLayouts).append(defaultPropertyValues, wc.defaultPropertyValues).append( 492 defaultControlValues, wc.defaultControlValues).append(fieldLayouts, wc.fieldLayouts).isEquals(); 493 } 494 495}