org.graylog2.plugin.configuration.fields.DropdownField Maven / Gradle / Ivy
/**
* This file is part of Graylog.
*
* Graylog is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Graylog is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see .
*/
package org.graylog2.plugin.configuration.fields;
import com.google.common.collect.Maps;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* @author Lennart Koopmann
*/
public class DropdownField extends AbstractConfigurationField {
public static final String FIELD_TYPE = "dropdown";
private String defaultValue;
private final Map values;
public DropdownField(String name, String humanName, String defaultValue, Map values, Optional isOptional) {
this(name, humanName, defaultValue, values, null, isOptional);
}
public DropdownField(String name, String humanName, String defaultValue, Map values, String description, Optional isOptional) {
super(FIELD_TYPE, name, humanName, description, isOptional);
this.defaultValue = defaultValue;
this.values = values;
}
@Override
public Object getDefaultValue() {
return defaultValue;
}
@Override
public void setDefaultValue(Object defaultValue) {
if (defaultValue instanceof String) {
this.defaultValue = (String) defaultValue;
}
}
@Override
public Map> getAdditionalInformation() {
Map> result = Maps.newHashMap();
result.put("values", values);
return result;
}
public static class ValueTemplates {
public static Map timeUnits() {
Map units = Maps.newHashMap();
for(TimeUnit unit : TimeUnit.values()) {
String human = unit.toString().toLowerCase(Locale.ENGLISH);
units.put(unit.toString(), Character.toUpperCase(human.charAt(0)) + human.substring(1));
}
return units;
}
}
}