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 org.ametys.runtime.i18n.I18nizableText;
019
020/**
021 * Object containing the definition of an element and informations about its categories / groups
022 * @param <T> Type of the element value
023 */
024public class CategorizedElementDefinitionWrapper<T>
025{
026    /** The element definition */
027    protected ElementDefinition<T> _definition;
028    /** the category in which to display the element */
029    protected I18nizableText _displayCategory;
030    /** the group in which to display the element */
031    protected I18nizableText _displayGroup;
032    /** the position in the group where the element has to be displayed */
033    protected long _position;
034    
035    /**
036     * Default constructor.
037     */
038    public CategorizedElementDefinitionWrapper()
039    {
040        // Do nothing
041    }
042    
043    /**
044     * Constructor by copying an existing {@link CategorizedElementDefinitionWrapper}.
045     * @param wrapperToCopy The {@link CategorizedElementDefinitionWrapper} to copy
046     */
047    public CategorizedElementDefinitionWrapper(CategorizedElementDefinitionWrapper<T> wrapperToCopy)
048    {
049        // ElementDefinition
050        ElementDefinition<T> copiedDefinition = new ElementDefinition<>(wrapperToCopy.getDefinition());
051        setDefinition(copiedDefinition);
052        
053        // Categories
054        setDisplayCategory(wrapperToCopy.getDisplayCategory());
055        setDisplayGroup(wrapperToCopy.getDisplayGroup());
056        setPosition(wrapperToCopy.getPosition());
057    }
058    
059    /**
060     * Retrieves the element definition
061     * @return the element definition
062     */
063    public ElementDefinition<T> getDefinition()
064    {
065        return _definition;
066    }
067    
068    /**
069     * Sets the element definition
070     * @param definition the element definition to set
071     */
072    public void setDefinition(ElementDefinition<T> definition)
073    {
074        _definition = definition;
075    }
076    
077    /**
078     * Retrieves the category in which to display the element
079     * @return the category
080     */
081    public I18nizableText getDisplayCategory()
082    {
083        return _displayCategory;
084    }
085    
086    /**
087     * Sets the category in which to display the element
088     * @param displayCategory the category to set
089     */
090    public void setDisplayCategory(I18nizableText displayCategory)
091    {
092        this._displayCategory = displayCategory;
093    }
094    
095    /**
096     * Retrieves the group in which to display the element
097     * @return the group
098     */
099    public I18nizableText getDisplayGroup()
100    {
101        return _displayGroup;
102    }
103    
104    /**
105     * Sets the group in which to display the element
106     * @param displayGroup the group to set
107     */
108    public void setDisplayGroup(I18nizableText displayGroup)
109    {
110        this._displayGroup = displayGroup;
111    }
112    
113    /**
114     * Retrieves the position in the group where the element has to be displayed 
115     * @return the position in the group
116     */
117    public long getPosition()
118    {
119        return _position;
120    }
121    
122    /**
123     * Sets the position of the element in the group
124     * @param position the position to set
125     */
126    public void setPosition(long position)
127    {
128        this._position = position;
129    }
130
131    @Override
132    public boolean equals(Object obj)
133    {
134        return getDefinition().equals(obj);
135    }
136
137    @Override
138    public int hashCode()
139    {
140        return getDefinition().hashCode();
141    }
142
143    @Override
144    public String toString()
145    {
146        return getDefinition().toString();
147    }
148    
149    
150}