001/*
002 *  Copyright 2010 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.form;
017
018/**
019 * Abstract parent class for all fields
020 */
021public abstract class AbstractField
022{
023    /** The field mode */
024    public enum MODE 
025    {
026        /** Value will replace existing one */
027        REPLACE,
028        /** Value will be added to existing one */
029        INSERT,
030        /** Value will be removed from existing one */
031        REMOVE
032    }
033    private MODE _mode = MODE.REPLACE;
034
035    /**
036     * Set the field in replace mode : the values are replacing the current values.
037     * @param mode The mode
038     */
039    public void setMode(MODE mode)
040    {
041        _mode = mode;
042    }
043    
044    /**
045     * Set the field in replace mode : the values are replacing the current values.
046     * @param mode The mode "insert", "remove" or "replace" (default)
047     */
048    public void setMode(String mode)
049    {
050        if ("remove".equalsIgnoreCase(mode))
051        {
052            setMode(MODE.REMOVE);
053        }
054        else if ("insert".equalsIgnoreCase(mode))
055        {
056            setMode(MODE.INSERT);
057        }
058        else
059        {
060            setMode(MODE.REPLACE);
061        }
062
063    }
064    
065    /**
066     * Is the repeater field in replace mode?
067     * @return true if in replace mode
068     */
069    public MODE getMode()
070    {
071        return _mode;
072    }
073    
074}