001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.model;
016    
017    import com.liferay.portal.kernel.util.LocaleUtil;
018    
019    import java.io.Serializable;
020    
021    import java.util.LinkedHashMap;
022    import java.util.Locale;
023    import java.util.Map;
024    import java.util.Set;
025    
026    /**
027     * @author Pablo Carvalho
028     */
029    public class DDMFormFieldOptions implements Serializable {
030    
031            public void addOption(String value) {
032                    _options.put(value, new LocalizedValue(_defaultLocale));
033            }
034    
035            public void addOptionLabel(
036                    String optionValue, Locale locale, String label) {
037    
038                    LocalizedValue labels = _options.get(optionValue);
039    
040                    if (labels == null) {
041                            labels = new LocalizedValue(_defaultLocale);
042    
043                            _options.put(optionValue, labels);
044                    }
045    
046                    labels.addString(locale, label);
047            }
048    
049            public Locale getDefaultLocale() {
050                    return _defaultLocale;
051            }
052    
053            public LocalizedValue getOptionLabels(String optionValue) {
054                    return _options.get(optionValue);
055            }
056    
057            public Set<String> getOptionsValues() {
058                    return _options.keySet();
059            }
060    
061            public void setDefaultLocale(Locale defaultLocale) {
062                    _defaultLocale = defaultLocale;
063    
064                    for (LocalizedValue localizedValue : _options.values()) {
065                            localizedValue.setDefaultLocale(defaultLocale);
066                    }
067            }
068    
069            private Locale _defaultLocale = LocaleUtil.getDefault();
070            private final Map<String, LocalizedValue> _options =
071                    new LinkedHashMap<String, LocalizedValue>();
072    
073    }