001
014
015 package com.liferay.portlet.dynamicdatamapping;
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
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 Map<String, LocalizedValue> getOptions() {
058 return _options;
059 }
060
061 public Set<String> getOptionsValues() {
062 return _options.keySet();
063 }
064
065 public void setDefaultLocale(Locale defaultLocale) {
066 _defaultLocale = defaultLocale;
067
068 for (LocalizedValue localizedValue : _options.values()) {
069 localizedValue.setDefaultLocale(defaultLocale);
070 }
071 }
072
073 private Locale _defaultLocale = LocaleUtil.getDefault();
074 private final Map<String, LocalizedValue> _options = new LinkedHashMap<>();
075
076 }