001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.preferences.sources;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.util.ArrayList;
007import java.util.Collection;
008import java.util.List;
009import java.util.Map;
010
011import org.openstreetmap.josm.data.preferences.BooleanProperty;
012import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
013import org.openstreetmap.josm.tools.ImageProvider;
014
015/**
016 * Helper class for validator tag checker rules preferences.
017 * @since 12649 (extracted from gui.preferences package)
018 */
019public class ValidatorPrefHelper extends SourcePrefHelper {
020
021    /**
022     * The unique instance.
023     */
024    public static final ValidatorPrefHelper INSTANCE = new ValidatorPrefHelper();
025
026    /** The preferences prefix */
027    public static final String PREFIX = "validator";
028
029    /** The preferences key for error layer */
030    public static final BooleanProperty PREF_LAYER = new BooleanProperty(PREFIX + ".layer", true);
031
032    /** The preferences key for enabled tests */
033    public static final String PREF_SKIP_TESTS = PREFIX + ".skip";
034
035    /** The preferences key for enabled tests */
036    public static final BooleanProperty PREF_USE_IGNORE = new BooleanProperty(PREFIX + ".ignore", true);
037
038    /** The preferences key for enabled tests before upload*/
039    public static final String PREF_SKIP_TESTS_BEFORE_UPLOAD = PREFIX + ".skipBeforeUpload";
040
041    /** The preferences key for ignored severity other on upload */
042    public static final BooleanProperty PREF_OTHER_UPLOAD = new BooleanProperty(PREFIX + ".otherUpload", false);
043
044    /** The preferences for ignored severity other */
045    public static final BooleanProperty PREF_OTHER = new BooleanProperty(PREFIX + ".other", false);
046
047    /** The preferences key for the ignorelist */
048    public static final String PREF_IGNORELIST = PREFIX + ".ignorelist";
049
050    /** The preferences key for the ignorelist format */
051    public static final String PREF_IGNORELIST_FORMAT = PREF_IGNORELIST + ".version";
052
053    /**
054     * The preferences key for enabling the permanent filtering
055     * of the displayed errors in the tree regarding the current selection
056     */
057    public static final String PREF_FILTER_BY_SELECTION = PREFIX + ".selectionFilter";
058
059    /**
060     * Constructs a new {@code PresetPrefHelper}.
061     */
062    public ValidatorPrefHelper() {
063        super(MapCSSTagChecker.ENTRIES_PREF_KEY, SourceType.TAGCHECKER_RULE);
064    }
065
066    @Override
067    public Collection<ExtendedSourceEntry> getDefault() {
068        List<ExtendedSourceEntry> def = new ArrayList<>();
069
070        // CHECKSTYLE.OFF: SingleSpaceSeparator
071        addDefault(def, "addresses",    tr("Addresses"),           tr("Checks for errors on addresses"));
072        addDefault(def, "combinations", tr("Tag combinations"),    tr("Checks for missing tag or suspicious combinations"));
073        addDefault(def, "deprecated",   tr("Deprecated features"), tr("Checks for deprecated features"));
074        addDefault(def, "geometry",     tr("Geometry"),            tr("Checks for geometry errors"));
075        addDefault(def, "highway",      tr("Highways"),            tr("Checks for errors on highways"));
076        addDefault(def, "multiple",     tr("Multiple values"),     tr("Checks for wrong multiple values"));
077        addDefault(def, "numeric",      tr("Numeric values"),      tr("Checks for wrong numeric values"));
078        addDefault(def, "religion",     tr("Religion"),            tr("Checks for errors on religious objects"));
079        addDefault(def, "relation",     tr("Relations"),           tr("Checks for errors on relations"));
080        addDefault(def, "territories",  tr("Territories"),         tr("Checks for territories-specific features"));
081        addDefault(def, "unnecessary",  tr("Unnecessary tags"),    tr("Checks for unnecessary tags"));
082        addDefault(def, "wikipedia",    tr("Wikipedia"),           tr("Checks for wrong wikipedia tags"));
083        // CHECKSTYLE.ON: SingleSpaceSeparator
084
085        return def;
086    }
087
088    private void addDefault(List<ExtendedSourceEntry> defaults, String filename, String title, String description) {
089        ExtendedSourceEntry i = new ExtendedSourceEntry(type, filename+".mapcss", "resource://data/validator/"+filename+".mapcss");
090        i.title = title;
091        i.icon = new ImageProvider("logo").getResource();
092        i.description = description;
093        defaults.add(i);
094    }
095
096    @Override
097    public Map<String, String> serialize(SourceEntry entry) {
098        Map<String, String> res = super.serialize(entry);
099        res.put("active", Boolean.toString(entry.active));
100        return res;
101    }
102}