001/*
002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017package org.nuxeo.ecm.platform.forms.layout.demo.descriptors;
018
019import java.io.Serializable;
020import java.util.ArrayList;
021import java.util.List;
022import java.util.Map;
023
024import org.nuxeo.common.xmap.annotation.XNode;
025import org.nuxeo.common.xmap.annotation.XNodeList;
026import org.nuxeo.common.xmap.annotation.XObject;
027import org.nuxeo.ecm.platform.forms.layout.demo.service.DemoLayout;
028import org.nuxeo.ecm.platform.forms.layout.descriptors.PropertiesDescriptor;
029
030/**
031 * @author Anahide Tchertchian
032 */
033@XObject("widgetType")
034public class DemoWidgetTypeDescriptor implements Serializable {
035
036    private static final long serialVersionUID = 1L;
037
038    @XNode("@name")
039    protected String name;
040
041    /**
042     * Additional name that can be used when describing a widget type in a different category.
043     *
044     * @since 5.9.1
045     */
046    @XNode("@widgetTypeName")
047    protected String widgetTypeName;
048
049    @XNode("label")
050    protected String label;
051
052    @XNode("viewId")
053    protected String viewId;
054
055    @XNode("category")
056    protected String category;
057
058    @XNode("widgetTypeCategory")
059    protected String widgetTypeCategory;
060
061    @XNode("preview@enabled")
062    protected boolean previewEnabled = false;
063
064    @XNode("preview@hideViewMode")
065    protected boolean previewHideViewMode = false;
066
067    /**
068     * @since 7.2
069     */
070    @XNode("preview@hideEditMode")
071    protected boolean previewHideEditMode = false;
072
073    @XNodeList(value = "preview/fields/field", type = ArrayList.class, componentType = String.class)
074    protected List<String> fields;
075
076    @XNode("preview/defaultProperties")
077    protected PropertiesDescriptor defaultProperties;
078
079    @XNodeList(value = "layouts/layout", type = ArrayList.class, componentType = DemoLayoutDescriptor.class)
080    protected List<DemoLayoutDescriptor> demoLayouts;
081
082    public String getName() {
083        return name;
084    }
085
086    public String getWidgetTypeName() {
087        if (widgetTypeName == null) {
088            return getName();
089        }
090        return widgetTypeName;
091    }
092
093    public String getLabel() {
094        return label;
095    }
096
097    public String getViewId() {
098        return viewId;
099    }
100
101    public String getCategory() {
102        return category;
103    }
104
105    /**
106     * @since 5.7.3
107     */
108    public String getWidgetTypeCategory() {
109        return widgetTypeCategory;
110    }
111
112    public boolean isPreviewEnabled() {
113        return previewEnabled;
114    }
115
116    public boolean isPreviewHideViewMode() {
117        return previewHideViewMode;
118    }
119
120    /**
121     * @since 7.2
122     */
123    public boolean isPreviewHideEditMode() {
124        return previewHideEditMode;
125    }
126
127    public List<String> getFields() {
128        return fields;
129    }
130
131    public Map<String, Serializable> getDefaultProperties() {
132        if (defaultProperties == null) {
133            return null;
134        }
135        return defaultProperties.getProperties();
136    }
137
138    public List<DemoLayout> getDemoLayouts() {
139        List<DemoLayout> res = new ArrayList<DemoLayout>();
140        res.addAll(demoLayouts);
141        return res;
142    }
143
144}