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