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.service;
020
021import java.io.Serializable;
022import java.util.List;
023import java.util.Map;
024
025/**
026 * Default implementation of the widget type demo
027 *
028 * @author Anahide Tchertchian
029 */
030public class DemoWidgetTypeImpl implements DemoWidgetType {
031
032    private static final long serialVersionUID = 1L;
033
034    protected String name;
035
036    protected String label;
037
038    protected String viewId;
039
040    protected String category;
041
042    protected String widgetTypeCategory;
043
044    protected boolean previewEnabled;
045
046    protected boolean previewHideViewMode;
047
048    protected boolean previewHideEditMode;
049
050    protected List<String> fields;
051
052    protected Map<String, Serializable> defaultProperties;
053
054    protected List<DemoLayout> demoLayouts;
055
056    public DemoWidgetTypeImpl(String name, String label, String viewId, String category, String widgetTypeCategory,
057            boolean previewEnabled, boolean previewHideViewMode, boolean previewHideEditMode, List<String> fields,
058            Map<String, Serializable> defaultProperties, List<DemoLayout> demoLayouts) {
059        super();
060        this.name = name;
061        this.label = label;
062        this.viewId = viewId;
063        this.category = category;
064        this.widgetTypeCategory = widgetTypeCategory;
065        this.previewEnabled = previewEnabled;
066        this.previewHideViewMode = previewHideViewMode;
067        this.previewHideEditMode = previewHideEditMode;
068        this.fields = fields;
069        this.defaultProperties = defaultProperties;
070        this.demoLayouts = demoLayouts;
071    }
072
073    public String getName() {
074        return name;
075    }
076
077    public String getLabel() {
078        return label;
079    }
080
081    public String getViewId() {
082        return viewId;
083    }
084
085    public String getUrl() {
086        return LayoutDemoManager.APPLICATION_PATH + viewId;
087    }
088
089    public String getCategory() {
090        return category;
091    }
092
093    @Override
094    public String getWidgetTypeCategory() {
095        return widgetTypeCategory;
096    }
097
098    public boolean isPreviewEnabled() {
099        return previewEnabled;
100    }
101
102    @Override
103    public boolean isPreviewHideViewMode() {
104        return previewHideViewMode;
105    }
106
107    @Override
108    public boolean isPreviewHideEditMode() {
109        return previewHideEditMode;
110    }
111
112    public List<String> getFields() {
113        return fields;
114    }
115
116    public List<DemoLayout> getDemoLayouts() {
117        return demoLayouts;
118    }
119
120    @Override
121    public Map<String, Serializable> getDefaultProperties() {
122        return defaultProperties;
123    }
124
125    @Override
126    public boolean equals(Object other) {
127        if (other instanceof DemoWidgetType) {
128            DemoWidgetType oWidget = (DemoWidgetType) other;
129            String oName = oWidget.getName();
130            if (name == null && oName != null) {
131                return false;
132            } else if (!name.equals(oName)) {
133                return false;
134            }
135            return true;
136        }
137        return false;
138    }
139
140    @Override
141    public String toString() {
142        return String.format("DemoWidgetTypeImpl [name=%s, label=%s, " + "viewId=%s, category=%s]", name, label,
143                viewId, category);
144    }
145
146}