001/*
002 * (C) Copyright 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.demo.descriptors;
020
021import java.io.Serializable;
022import java.util.ArrayList;
023import java.util.List;
024import java.util.Map;
025
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XNodeList;
028import org.nuxeo.common.xmap.annotation.XObject;
029import org.nuxeo.ecm.platform.forms.layout.demo.service.DemoLayout;
030import org.nuxeo.ecm.platform.forms.layout.descriptors.PropertiesDescriptor;
031
032/**
033 * @author Anahide Tchertchian
034 */
035@XObject("widgetType")
036public class DemoWidgetTypeDescriptor implements Serializable {
037
038    private static final long serialVersionUID = 1L;
039
040    @XNode("@name")
041    protected String name;
042
043    /**
044     * Additional name that can be used when describing a widget type in a different category.
045     *
046     * @since 5.9.1
047     */
048    @XNode("@widgetTypeName")
049    protected String widgetTypeName;
050
051    @XNode("label")
052    protected String label;
053
054    @XNode("viewId")
055    protected String viewId;
056
057    @XNode("category")
058    protected String category;
059
060    @XNode("widgetTypeCategory")
061    protected String widgetTypeCategory;
062
063    @XNode("preview@enabled")
064    protected boolean previewEnabled = false;
065
066    @XNode("preview@hideViewMode")
067    protected boolean previewHideViewMode = false;
068
069    /**
070     * @since 7.2
071     */
072    @XNode("preview@hideEditMode")
073    protected boolean previewHideEditMode = false;
074
075    @XNodeList(value = "preview/fields/field", type = ArrayList.class, componentType = String.class)
076    protected List<String> fields;
077
078    @XNode("preview/defaultProperties")
079    protected PropertiesDescriptor defaultProperties;
080
081    @XNodeList(value = "layouts/layout", type = ArrayList.class, componentType = DemoLayoutDescriptor.class)
082    protected List<DemoLayoutDescriptor> demoLayouts;
083
084    public String getName() {
085        return name;
086    }
087
088    public String getWidgetTypeName() {
089        if (widgetTypeName == null) {
090            return getName();
091        }
092        return widgetTypeName;
093    }
094
095    public String getLabel() {
096        return label;
097    }
098
099    public String getViewId() {
100        return viewId;
101    }
102
103    public String getCategory() {
104        return category;
105    }
106
107    /**
108     * @since 5.7.3
109     */
110    public String getWidgetTypeCategory() {
111        return widgetTypeCategory;
112    }
113
114    public boolean isPreviewEnabled() {
115        return previewEnabled;
116    }
117
118    public boolean isPreviewHideViewMode() {
119        return previewHideViewMode;
120    }
121
122    /**
123     * @since 7.2
124     */
125    public boolean isPreviewHideEditMode() {
126        return previewHideEditMode;
127    }
128
129    public List<String> getFields() {
130        return fields;
131    }
132
133    public Map<String, Serializable> getDefaultProperties() {
134        if (defaultProperties == null) {
135            return null;
136        }
137        return defaultProperties.getProperties();
138    }
139
140    public List<DemoLayout> getDemoLayouts() {
141        List<DemoLayout> res = new ArrayList<DemoLayout>();
142        res.addAll(demoLayouts);
143        return res;
144    }
145
146}