001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.configuration.preferences;
029
030import org.opencms.configuration.CmsDefaultUserSettings;
031import org.opencms.file.CmsObject;
032import org.opencms.xml.content.CmsXmlContentProperty;
033
034/**
035 * Preference subclass for preferred editors.<p>
036 */
037public class CmsEditorPreference extends A_CmsPreference {
038
039    /** Prefix used for editor preference settings. */
040    public static final String EDITOR_PREFIX = "editor.";
041
042    /** The preference default value. */
043    private String m_value;
044
045    /** The resource type for which this preference controls the editor to use. */
046    private String m_editorType;
047
048    /**
049     *
050     * @param editorType the type for which this is the editor preference
051     *
052     * @param value the default value
053     */
054    public CmsEditorPreference(String editorType, String value) {
055
056        m_editorType = editorType;
057        m_value = value;
058    }
059
060    /**
061     * @see org.opencms.configuration.preferences.I_CmsPreference#getDefaultValue()
062     */
063    public String getDefaultValue() {
064
065        return m_value;
066    }
067
068    /**
069     * @see org.opencms.configuration.preferences.I_CmsPreference#getName()
070     */
071    public String getName() {
072
073        return EDITOR_PREFIX + m_editorType;
074    }
075
076    /**
077     * @see org.opencms.configuration.preferences.I_CmsPreference#getPropertyDefinition(org.opencms.file.CmsObject)
078     */
079    @Override
080    public CmsXmlContentProperty getPropertyDefinition() {
081
082        CmsXmlContentProperty prop = new CmsXmlContentProperty(
083            getName(), //name
084            "string", //type
085            null, //widget
086            null, //widgetconfig
087            null, //regex
088            null, //ruletype
089            null, //default
090            null, //nicename
091            null, //description
092            null, //error
093            null//preferfolder
094        );
095        return prop;
096    }
097
098    /**
099     * @see org.opencms.configuration.preferences.I_CmsPreference#getTab()
100     */
101    public String getTab() {
102
103        return "hidden";
104    }
105
106    /**
107     *
108     * @see org.opencms.configuration.preferences.I_CmsPreference#getValue(org.opencms.configuration.CmsDefaultUserSettings)
109     */
110    public String getValue(CmsDefaultUserSettings userSettings) {
111
112        return userSettings.getPreferredEditor(m_editorType);
113    }
114
115    /**
116     * @see org.opencms.configuration.preferences.I_CmsPreference#isDisabled(CmsObject)
117     */
118    @Override
119    public boolean isDisabled(CmsObject cms) {
120
121        return false;
122    }
123
124    /**
125     * @see org.opencms.configuration.preferences.I_CmsPreference#setValue(org.opencms.configuration.CmsDefaultUserSettings, java.lang.String)
126     */
127    public void setValue(CmsDefaultUserSettings settings, String value) {
128
129        settings.setPreferredEditor(m_editorType, value);
130    }
131
132}