001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.widgets;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsResource;
032import org.opencms.gwt.shared.categorizedselect.I_CmsCategorizedSelectData;
033import org.opencms.gwt.shared.categorizedselect.I_CmsCategorizedSelectDataFactory;
034import org.opencms.i18n.CmsMessages;
035import org.opencms.xml.content.I_CmsXmlContentHandler.DisplayType;
036import org.opencms.xml.types.A_CmsXmlContentValue;
037
038import java.util.List;
039import java.util.Locale;
040
041import com.google.web.bindery.autobean.shared.AutoBean;
042import com.google.web.bindery.autobean.shared.AutoBeanCodex;
043import com.google.web.bindery.autobean.vm.AutoBeanFactorySource;
044
045/**
046 * Abstract base class for categorized select widgets.
047 *
048 * <p>A categorized select widget consists of two select boxes, one for selecting the actual value and one
049 * for filtering the choices available in the first select box. All data for the choices is loaded initially, when
050 * the widget is initialized.
051 */
052public abstract class A_CmsCategorizedSelectWidget extends A_CmsWidget implements I_CmsADEWidget {
053
054    /** Factory for creating the data for the client-side widget. */
055    public static final I_CmsCategorizedSelectDataFactory DATA_FACTORY = AutoBeanFactorySource.create(
056        I_CmsCategorizedSelectDataFactory.class);
057
058    /**
059     * Instantiates a new a cms categorized select widget.
060     */
061    public A_CmsCategorizedSelectWidget() {
062
063        super();
064    }
065
066    /**
067     * Instantiates a new a cms categorized select widget.
068     *
069     * @param config the config
070     */
071    public A_CmsCategorizedSelectWidget(String config) {
072
073        super(config);
074    }
075
076    /**
077     * Gets the configuration.
078     *
079     * @param cms the cms
080     * @param contentValue the content value
081     * @param messages the messages
082     * @param resource the resource
083     * @param contentLocale the content locale
084     * @return the configuration
085     * @see org.opencms.widgets.I_CmsADEWidget#getConfiguration(org.opencms.file.CmsObject, org.opencms.xml.types.A_CmsXmlContentValue, org.opencms.i18n.CmsMessages, org.opencms.file.CmsResource, java.util.Locale)
086     */
087    public String getConfiguration(
088        CmsObject cms,
089        A_CmsXmlContentValue contentValue,
090        CmsMessages messages,
091        CmsResource resource,
092        Locale contentLocale) {
093
094        AutoBean<I_CmsCategorizedSelectData> autoBean = getData(cms, contentValue, messages, resource, contentLocale);
095        return AutoBeanCodex.encode(autoBean).getPayload();
096
097    }
098
099    /**
100     * Gets the css resource links.
101     *
102     * @param cms the cms
103     * @return the css resource links
104     * @see org.opencms.widgets.I_CmsADEWidget#getCssResourceLinks(org.opencms.file.CmsObject)
105     */
106    public List<String> getCssResourceLinks(CmsObject cms) {
107
108        return null;
109    }
110
111    /**
112     * Gets the default display type.
113     *
114     * @return the default display type
115     * @see org.opencms.widgets.I_CmsADEWidget#getDefaultDisplayType()
116     */
117    public DisplayType getDefaultDisplayType() {
118
119        return DisplayType.singleline;
120    }
121
122    /**
123     * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
124     */
125    public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
126
127        return null;
128    }
129
130    /**
131     * @see org.opencms.widgets.I_CmsADEWidget#getInitCall()
132     */
133    public String getInitCall() {
134
135        return null;
136    }
137
138    /**
139     * Gets the java script resource links.
140     *
141     * @param cms the cms
142     * @return the java script resource links
143     * @see org.opencms.widgets.I_CmsADEWidget#getJavaScriptResourceLinks(org.opencms.file.CmsObject)
144     */
145    public List<String> getJavaScriptResourceLinks(CmsObject cms) {
146
147        return null;
148    }
149
150    /**
151     * Gets the widget name.
152     *
153     * @return the widget name
154     * @see org.opencms.widgets.I_CmsADEWidget#getWidgetName()
155     */
156    public String getWidgetName() {
157
158        return "org.opencms.widgets.CmsCategorizedSelectWidget";
159
160    }
161
162    /**
163     * Checks if is internal.
164     *
165     * @return true, if is internal
166     * @see org.opencms.widgets.I_CmsADEWidget#isInternal()
167     */
168    public boolean isInternal() {
169
170        return true;
171    }
172
173    /**
174     * Gets the select option data for the widget.
175     *
176     * <p>This uses the GWT AutoBean mechanism for serialization. Use the DATA_FACTORY member
177     * for creating the relevant AutoBeans.
178     *
179     * @param cms the cms
180     * @param contentValue the content value
181     * @param messages the messages
182     * @param resource the resource
183     * @param contentLocale the content locale
184     * @return the data
185     */
186    protected abstract AutoBean<I_CmsCategorizedSelectData> getData(
187        CmsObject cms,
188        A_CmsXmlContentValue contentValue,
189        CmsMessages messages,
190        CmsResource resource,
191        Locale contentLocale);
192
193}