001/*
002 *  Copyright 2012 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.core.userpref;
017
018import org.ametys.runtime.i18n.I18nizableText;
019import org.ametys.runtime.parameter.Parameter;
020import org.ametys.runtime.parameter.ParameterHelper.ParameterType;
021
022/**
023 * Definition of a user preference.
024 */
025public class UserPreference extends Parameter<ParameterType>
026{
027    
028    /** The display group. */
029    protected I18nizableText _displayGroup;
030    
031    /** Indicates if the user preference is multiple. */
032    protected boolean _multiple;
033    
034    /** The manager role. */
035    protected String _managerRole;
036    
037    /** The preference order. */
038    protected int _order;
039    
040    /** The private status. */
041    protected boolean _private;
042    
043    /**
044     * Get the display group.
045     * @return the display group.
046     */
047    public I18nizableText getDisplayGroup()
048    {
049        return _displayGroup;
050    }
051    
052    /**
053     * Set the parameter display group.
054     * @param displayGroup the display group to set.
055     */
056    public void setDisplayGroup(I18nizableText displayGroup)
057    {
058        _displayGroup = displayGroup;
059    }
060    
061    /**
062     * Get the storage manager role.
063     * @return the manager role. Can be null to use the default storage manager.
064     */
065    public String getManagerRole()
066    {
067        return _managerRole;
068    }
069    
070    /**
071     * Set the storage manager role.
072     * @param managerRole the manager role to set. Can be null to use the default storage manager.
073     */
074    public void setManagerRole(String managerRole)
075    {
076        _managerRole = managerRole;
077    }
078    
079    /**
080     * Test if the preference is multiple-valued.
081     * @return true if the preference is multiple-valued, false if the preference is single-valued.
082     */
083    public boolean isMultiple()
084    {
085        return _multiple;
086    }
087    
088    /**
089     * Set if the preference is multiple-valued.
090     * @param multiple true if the preference is multiple-valued, false if the preference is single-valued.
091     */
092    public void setMultiple(boolean multiple)
093    {
094        _multiple = multiple;
095    }
096    
097    /**
098     * Get the preference order.
099     * @return the preference order.
100     */
101    public int getOrder()
102    {
103        return _order;
104    }
105    
106    /**
107     * Set the preference order.
108     * @param order the preference order.
109     */
110    public void setOrder(int order)
111    {
112        _order = order;
113    }
114    
115    /**
116     * Get whether the preference is private, i.e. should not be visible by
117     * the regular user preferences interface.
118     * @return true if the preference is private, false if it is public.
119     */
120    public boolean isPrivate()
121    {
122        return _private;
123    }
124    
125    /**
126     * Set the private status of the preference
127     * @param privateStatus true if the preference is private, false if it is public.
128     */
129    public void setPrivate(boolean privateStatus)
130    {
131        _private = privateStatus;
132    }
133    
134    @Override
135    public String toString()
136    {
137        return "Preference '" + getId() + "' (type:    " + (_multiple ? "multiple " : " ") + getType().name() + "', private:    " + _private + ", label:    " + getLabel().toString() + ", " + (getDefaultValue() != null ? "default value: " + getDefaultValue() : "no default value")  + ", " + (getEnumerator() != null ? "enumerator: " + getEnumerator() : "no enumerator") + ")";
138    }
139}