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