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