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    /**
051     * The preferences key for enabling the permanent filtering
052     * of the displayed errors in the tree regarding the current selection
053     */
054    public static final String PREF_FILTER_BY_SELECTION = PREFIX + ".selectionFilter";
055
056    /**
057     * Constructs a new {@code PresetPrefHelper}.
058     */
059    public ValidatorPrefHelper() {
060        super(MapCSSTagChecker.ENTRIES_PREF_KEY, SourceType.TAGCHECKER_RULE);
061    }
062
063    @Override
064    public Collection<ExtendedSourceEntry> getDefault() {
065        List<ExtendedSourceEntry> def = new ArrayList<>();
066
067        // CHECKSTYLE.OFF: SingleSpaceSeparator
068        addDefault(def, "addresses",    tr("Addresses"),           tr("Checks for errors on addresses"));
069        addDefault(def, "combinations", tr("Tag combinations"),    tr("Checks for missing tag or suspicious combinations"));
070        addDefault(def, "deprecated",   tr("Deprecated features"), tr("Checks for deprecated features"));
071        addDefault(def, "geometry",     tr("Geometry"),            tr("Checks for geometry errors"));
072        addDefault(def, "highway",      tr("Highways"),            tr("Checks for errors on highways"));
073        addDefault(def, "multiple",     tr("Multiple values"),     tr("Checks for wrong multiple values"));
074        addDefault(def, "numeric",      tr("Numeric values"),      tr("Checks for wrong numeric values"));
075        addDefault(def, "religion",     tr("Religion"),            tr("Checks for errors on religious objects"));
076        addDefault(def, "relation",     tr("Relations"),           tr("Checks for errors on relations"));
077        addDefault(def, "territories",  tr("Territories"),         tr("Checks for territories-specific features"));
078        addDefault(def, "unnecessary",  tr("Unnecessary tags"),    tr("Checks for unnecessary tags"));
079        addDefault(def, "wikipedia",    tr("Wikipedia"),           tr("Checks for wrong wikipedia tags"));
080        // CHECKSTYLE.ON: SingleSpaceSeparator
081
082        return def;
083    }
084
085    private void addDefault(List<ExtendedSourceEntry> defaults, String filename, String title, String description) {
086        ExtendedSourceEntry i = new ExtendedSourceEntry(type, filename+".mapcss", "resource://data/validator/"+filename+".mapcss");
087        i.title = title;
088        i.icon = new ImageProvider("logo").getResource();
089        i.description = description;
090        defaults.add(i);
091    }
092
093    @Override
094    public Map<String, String> serialize(SourceEntry entry) {
095        Map<String, String> res = super.serialize(entry);
096        res.put("active", Boolean.toString(entry.active));
097        return res;
098    }
099}