001/*
002 *  Copyright 2013 Anyware Services
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 */
016package org.ametys.cms.search.ui.model.impl;
017
018import org.apache.avalon.framework.configuration.Configuration;
019
020import org.ametys.cms.contenttype.MetadataType;
021import org.ametys.cms.search.SearchField;
022import org.ametys.cms.search.ui.model.SearchUIColumn;
023import org.ametys.runtime.i18n.I18nizableText;
024import org.ametys.runtime.parameter.Parameter;
025
026/**
027 * This class represents a result column
028 */
029public abstract class AbstractSearchUIColumn extends Parameter<MetadataType> implements SearchUIColumn
030{
031    private int _width;
032    private String _renderer;
033    private String _converter;
034    private boolean _hidden;
035    private boolean _editable;
036    private boolean _sortable;
037    private boolean _multiple;
038    private String _contentTypeId;
039    private String _defaultSorter;
040    
041//    /**
042//     * Get the value represented by this column in the given result content.
043//     * @param content the result content.
044//     * @return the content value (cast to the appropriate object).
045//     */
046//    public abstract Object getValue(Content content);
047    
048    @Override
049    public int getWidth()
050    {
051        return _width;
052    }
053    
054    /**
055     * Set the column's width
056     * @param width The width to set
057     */
058    public void setWidth (int width)
059    {
060        this._width = width;
061    }
062    
063    @Override
064    public boolean isHidden()
065    {
066        return this._hidden;
067    }
068    
069    /**
070     * Set the hidden property
071     * @param hidden <code>true</code> to hidden the columns by default
072     */
073    public void setHidden (boolean hidden)
074    {
075        this._hidden = hidden;
076    }
077    
078    @Override
079    public boolean isEditable()
080    {
081        return this._editable;
082    }
083    
084    /**
085     * Set the sortable property
086     * @param sortable <code>true</code> to authorized sort
087     */
088    public void setSortable (boolean sortable)
089    {
090        this._sortable = sortable;
091    }
092    
093    @Override
094    public boolean isSortable()
095    {
096        return this._sortable;
097    }
098    
099    /**
100     * Set the default sorter propery
101     * @param defaultSorter If the column should be a default sorter, 'ASC' for ascending 'DESC' for descending. Null otherwise.
102     */
103    public void setDefaultSorter(String defaultSorter)
104    {
105        this._defaultSorter = defaultSorter;
106    }
107    
108    public String getDefaultSorter()
109    {
110        return this._defaultSorter;
111    }
112    
113    /**
114     * Set the editable property
115     * @param editable <code>true</code> to authorized edition
116     */
117    public void setEditable (boolean editable)
118    {
119        this._editable = editable;
120    }
121    
122    @Override
123    public String getRenderer()
124    {
125        return _renderer;
126    }
127    
128    /**
129     * Set the JS class name for renderer
130     * @param renderer The renderer
131     */
132    public void setRenderer(String renderer)
133    {
134        this._renderer = renderer;
135    }
136    
137    @Override
138    public String getConverter()
139    {
140        return _converter;
141    }
142    
143    /**
144     * Set the JS class name for converting field's value
145     * @param converter The convert JS class name
146     */
147    public void setConverter(String converter)
148    {
149        this._converter = converter;
150    }
151    
152    @Override
153    public boolean isMultiple()
154    {
155        return this._multiple;
156    }
157    
158    /**
159     * Set the multiple property
160     * @param multiple the multiple property
161     */
162    public void setMultiple (boolean multiple)
163    {
164        this._multiple = multiple;
165    }
166    
167    /**
168     * Get the content type ID (only when the search criteria is of type CONTENT).
169     * @return the content type ID.
170     */
171    public String getContentTypeId()
172    {
173        return this._contentTypeId;
174    }
175    
176    /**
177     * Set the content type ID (only when the search criteria is of type CONTENT).
178     * @param contentTypeId the content type ID. 
179     */
180    public void setContentTypeId(String contentTypeId)
181    {
182        this._contentTypeId = contentTypeId;
183    }
184    
185    @Override
186    public SearchField getSearchField()
187    {
188        // Override to provide a specific implementation.
189        return null;
190    }
191    
192    
193    /**
194     * Configure an i18nizable text
195     * @param config The Configuration.
196     * @param defaultValue The default value as an I18nizableText.
197     * @return The i18nizable text
198     */
199    protected I18nizableText _configureI18nizableText(Configuration config, I18nizableText defaultValue)
200    {
201        if (config != null)
202        {
203            return I18nizableText.parseI18nizableText(config, null, "");
204        }
205        else
206        {
207            return defaultValue;
208        }
209    }
210    
211}