001/*
002 *  Copyright 2016 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.runtime.model;
017
018import java.util.Map;
019import java.util.Set;
020
021import org.apache.cocoon.ProcessingException;
022
023import org.ametys.runtime.config.DisableConditions;
024import org.ametys.runtime.i18n.I18nizableText;
025import org.ametys.runtime.model.checker.ItemCheckerDescriptor;
026import org.ametys.runtime.model.type.ElementType;
027import org.ametys.runtime.model.type.ModelItemType;
028import org.ametys.runtime.parameter.Validator;
029
030/**
031 * Object containing the definition of an element and informations about its categories / groups
032 * @param <T> Type of the element value
033 */
034public class CategorizedElementDefinitionProxy<T> extends ElementDefinition<T>
035{
036    private ElementDefinition<T> _definition;
037    private I18nizableText _displayCategory;
038    private I18nizableText _displayGroup;
039    private long _position;
040    private boolean _isGroupSwitch;
041    
042    /**
043     * Default constructor
044     */
045    public CategorizedElementDefinitionProxy()
046    {
047        _definition = new ElementDefinition<>();
048    }
049    
050    /**
051     * Retrieves the element definition
052     * @return the element definition
053     */
054    public ElementDefinition<T> getDefinition()
055    {
056        return _definition;
057    }
058    
059    /**
060     * Retrieves the category in which to display the element
061     * @return the category
062     */
063    public I18nizableText getDisplayCategory()
064    {
065        return _displayCategory;
066    }
067    
068    /**
069     * Sets the category in which to display the element
070     * @param displayCategory the category to set
071     */
072    public void setDisplayCategory(I18nizableText displayCategory)
073    {
074        this._displayCategory = displayCategory;
075    }
076    
077    /**
078     * Retrieves the group in which to display the element
079     * @return the group
080     */
081    public I18nizableText getDisplayGroup()
082    {
083        return _displayGroup;
084    }
085    
086    /**
087     * Sets the group in which to display the element
088     * @param displayGroup the group to set
089     */
090    public void setDisplayGroup(I18nizableText displayGroup)
091    {
092        this._displayGroup = displayGroup;
093    }
094    
095    /**
096     * Retrieves the position in the group where the element has to be displayed 
097     * @return the position in the group
098     */
099    public long getPosition()
100    {
101        return _position;
102    }
103    
104    /**
105     * Sets the position of the element in the group
106     * @param position the position to set
107     */
108    public void setPosition(long position)
109    {
110        this._position = position;
111    }
112    
113    /**
114     * Retrieves true if this definition is the group switch
115     * @return true if this definition is the group switch, false otherwise
116     */
117    public boolean isGroupSwitch()
118    {
119        return _isGroupSwitch;
120    }
121    
122    /***
123     * Sets the group switch
124     * @param isGroupSwitch true if this definition is the group switch
125     */
126    public void setGroupSwitch(boolean isGroupSwitch)
127    {
128        _isGroupSwitch = isGroupSwitch;
129    }
130
131    @Override
132    public String getPluginName()
133    {
134        return getDefinition().getPluginName();
135    }
136
137    @Override
138    public void setPluginName(String pluginName)
139    {
140        getDefinition().setPluginName(pluginName);
141    }
142
143    @Override
144    public ElementType<T> getType()
145    {
146        return getDefinition().getType();
147    }
148
149    @Override
150    public void setType(ModelItemType type)
151    {
152        getDefinition().setType(type);
153    }
154
155    @Override
156    public String getWidget()
157    {
158        return getDefinition().getWidget();
159    }
160
161    @Override
162    public void setWidget(String widget)
163    {
164        getDefinition().setWidget(widget);
165    }
166
167    @Override
168    public Map<String, I18nizableText> getWidgetParameters()
169    {
170        return getDefinition().getWidgetParameters();
171    }
172
173    @Override
174    public void setWidgetParameters(Map<String, I18nizableText> params)
175    {
176        getDefinition().setWidgetParameters(params);
177    }
178
179    @Override
180    public Enumerator<T> getEnumerator()
181    {
182        return getDefinition().getEnumerator();
183    }
184
185    @Override
186    public void setEnumerator(Enumerator<T> enumerator)
187    {
188        getDefinition().setEnumerator(enumerator);
189    }
190
191    @Override
192    public Validator getValidator()
193    {
194        return getDefinition().getValidator();
195    }
196
197    @Override
198    public void setValidator(Validator validator)
199    {
200        getDefinition().setValidator(validator);
201    }
202
203    @Override
204    public T getDefaultValue()
205    {
206        return getDefinition().getDefaultValue();
207    }
208
209    @Override
210    public void setDefaultValue(T defaultValue)
211    {
212        getDefinition().setDefaultValue(defaultValue);
213    }
214
215    @Override
216    public boolean isMultiple()
217    {
218        return getDefinition().isMultiple();
219    }
220
221    @Override
222    public void setMultiple(boolean isMultiple)
223    {
224        getDefinition().setMultiple(isMultiple);
225    }
226
227    @Override
228    public DisableConditions getDisableConditions()
229    {
230        return getDefinition().getDisableConditions();
231    }
232
233    @Override
234    public void setDisableConditions(DisableConditions disableConditions)
235    {
236        getDefinition().setDisableConditions(disableConditions);
237    }
238
239    @Override
240    public Map<String, Object> toJSON() throws ProcessingException
241    {
242        return getDefinition().toJSON();
243    }
244
245    @Override
246    public String getName()
247    {
248        return getDefinition().getName();
249    }
250
251    @Override
252    public void setName(String name)
253    {
254        getDefinition().setName(name);
255    }
256
257    @Override
258    public I18nizableText getLabel()
259    {
260        return getDefinition().getLabel();
261    }
262
263    @Override
264    public void setLabel(I18nizableText label)
265    {
266        getDefinition().setLabel(label);
267    }
268
269    @Override
270    public I18nizableText getDescription()
271    {
272        return getDefinition().getDescription();
273    }
274
275    @Override
276    public void setDescription(I18nizableText description)
277    {
278        getDefinition().setDescription(description);
279    }
280
281    @Override
282    public void addItemChecker(ItemCheckerDescriptor itemChecker)
283    {
284        getDefinition().addItemChecker(itemChecker);
285    }
286
287    @Override
288    public Set<ItemCheckerDescriptor> getItemCheckers()
289    {
290        return getDefinition().getItemCheckers();
291    }
292
293    @Override
294    public String getPath()
295    {
296        return getDefinition().getPath();
297    }
298
299    @Override
300    public Model getModel()
301    {
302        return getDefinition().getModel();
303    }
304
305    @Override
306    public void setModel(Model model)
307    {
308        getDefinition().setModel(model);
309    }
310
311    @Override
312    public ModelItemGroup getParent()
313    {
314        return getDefinition().getParent();
315    }
316
317    @Override
318    public void setParent(ModelItemGroup parent)
319    {
320        getDefinition().setParent(parent);
321    }
322
323    @Override
324    public int compareTo(ModelItem item)
325    {
326        return getDefinition().compareTo(item);
327    }
328
329    @Override
330    public boolean equals(Object obj)
331    {
332        return getDefinition().equals(obj);
333    }
334
335    @Override
336    public int hashCode()
337    {
338        return getDefinition().hashCode();
339    }
340
341    @Override
342    public String toString()
343    {
344        return getDefinition().toString();
345    }
346    
347    
348}