From 915ce22c28846162771a67307e512d25e5b6320d Mon Sep 17 00:00:00 2001 From: harry Date: Fri, 21 Jul 2023 01:41:17 +0530 Subject: [PATCH 1/3] Update search dialog --- .../josm/gui/dialogs/SearchDialog.java | 2 +- .../gui/tagging/presets/TaggingPreset.java | 21 +++++++++++ .../presets/TaggingPresetSearchDialog.java | 2 +- .../TaggingPresetSearchPrimitiveDialog.java | 2 +- .../presets/TaggingPresetSelector.java | 35 +++++++++++++++---- .../presets/PresetClassificationsTest.java | 2 +- 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java b/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java index 444f4e90d6d..acfb73bd676 100644 --- a/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java +++ b/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java @@ -231,7 +231,7 @@ public boolean isValid() { * selected preset by the user. Every query is of the form ' group/sub-group/.../presetName' * if the corresponding group of the preset exists, otherwise it is simply ' presetName'. */ - selector = new TaggingPresetSelector(false, false); + selector = new TaggingPresetSelector(false, false, false); selector.setBorder(BorderFactory.createTitledBorder(tr("Search by preset"))); selector.setDblClickListener(ev -> setPresetDblClickListener(selector, editorComponent)); diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java index d154158093d..56274c7c383 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java @@ -136,6 +136,10 @@ public class TaggingPreset extends AbstractAction implements ActiveLayerChangeLi * Show the preset name if true */ public boolean preset_name_label; + /** + * True if the preset is deprecated + */ + private boolean deprecated = false; /** * The types as preparsed collection. @@ -349,6 +353,23 @@ public void setMatch_expression(String filter) throws SAXException { } } + /** + * @return true if the preset is deprecated + * @apiNote this is not {@code isDeprecated} just in case we decide to make {@link TaggingPreset} a record class. + * @since xxx + */ + public final boolean deprecated() { + return this.deprecated; + } + + /** + * Set if the preset is deprecated + * @param deprecated if true the preset is deprecated + */ + public final void setDeprecated(boolean deprecated) { + this.deprecated = deprecated; + } + private static class PresetPanel extends JPanel { private boolean hasElements; diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java index 9564f699a5c..b30f6faa9a6 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java @@ -34,7 +34,7 @@ private TaggingPresetSearchDialog() { super(MainApplication.getMainFrame(), tr("Search presets"), tr("Select"), tr("Cancel")); setButtonIcons("dialogs/search", "cancel"); configureContextsensitiveHelp("/Action/TaggingPresetSearch", true /* show help button */); - selector = new TaggingPresetSelector(true, true); + selector = new TaggingPresetSelector(true, true, true); setContent(selector, false); SelectionEventManager.getInstance().addSelectionListener(selector); selector.setDblClickListener(e -> buttonAction(0, null)); diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java index 41e7ecde8a9..68634391d07 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java @@ -67,7 +67,7 @@ public static synchronized TaggingPresetSearchPrimitiveDialog getInstance() { super(MainApplication.getMainFrame(), tr("Search for objects by preset"), tr("Search"), tr("Cancel")); setButtonIcons("dialogs/search", "cancel"); configureContextsensitiveHelp("/Action/TaggingPresetSearchPrimitive", true /* show help button */); - selector = new TaggingPresetSelector(false, false); + selector = new TaggingPresetSelector(false, false, false); setContent(selector, false); selector.setDblClickListener(e -> buttonAction(0, null)); } diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java index 52df95edfa8..2a273b70bd9 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java @@ -51,7 +51,7 @@ import org.openstreetmap.josm.tools.Utils; /** - * GUI component to select tagging preset: the list with filter and two checkboxes + * GUI component to select tagging preset: the list with filter and three checkboxes * @since 6068 */ public class TaggingPresetSelector extends SearchTextResultListPanel @@ -66,9 +66,11 @@ public class TaggingPresetSelector extends SearchTextResultListPanel typesInSelection = EnumSet.noneOf(TaggingPresetType.class); private boolean typesInSelectionDirty = true; private final transient PresetClassifications classifications = new PresetClassifications(); @@ -199,8 +201,9 @@ public String toString() { * Constructs a new {@code TaggingPresetSelector}. * @param displayOnlyApplicable if {@code true} display "Show only applicable to selection" checkbox * @param displaySearchInTags if {@code true} display "Search in tags" checkbox + * @param displayDeprecated if {@code true} display "Applicable in region" checkbox */ - public TaggingPresetSelector(boolean displayOnlyApplicable, boolean displaySearchInTags) { + public TaggingPresetSelector(boolean displayOnlyApplicable, boolean displaySearchInTags, boolean displayDeprecated) { super(); lsResult.setCellRenderer(new ResultListCellRenderer()); classifications.loadPresets(TaggingPresets.getTaggingPresets()); @@ -228,6 +231,15 @@ public TaggingPresetSelector(boolean displayOnlyApplicable, boolean displaySearc ckSearchInTags = null; } + if (displayDeprecated) { + ckDeprecated = new JCheckBox(); + ckDeprecated.setText(tr("Show deprecated tags")); + pnChecks.add(ckDeprecated); + ckDeprecated.addItemListener(e -> filterItems()); + } else { + ckDeprecated = null; + } + add(pnChecks, BorderLayout.SOUTH); setPreferredSize(new Dimension(400, 300)); @@ -254,11 +266,12 @@ protected synchronized void filterItems() { String text = edSearchText.getText().toLowerCase(Locale.ENGLISH); boolean onlyApplicable = ckOnlyApplicable != null && ckOnlyApplicable.isSelected(); boolean inTags = ckSearchInTags != null && ckSearchInTags.isSelected(); + boolean isDeprecated = ckDeprecated != null && ckDeprecated.isSelected(); DataSet ds = OsmDataManager.getInstance().getEditDataSet(); Collection selected = (ds == null) ? Collections.emptyList() : ds.getSelected(); final List result = classifications.getMatchingPresets( - text, onlyApplicable, inTags, getTypesInSelection(), selected); + text, onlyApplicable, inTags, isDeprecated, getTypesInSelection(), selected); final TaggingPreset oldPreset = getSelectedPreset(); lsResultModel.setItems(Utils.transform(result, x -> x.preset)); @@ -279,7 +292,7 @@ public static class PresetClassifications implements Iterable classifications = new ArrayList<>(); - public List getMatchingPresets(String searchText, boolean onlyApplicable, boolean inTags, + public List getMatchingPresets(String searchText, boolean onlyApplicable, boolean inTags, boolean isDeprecated, Set presetTypes, final Collection selectedPrimitives) { final String[] groupWords; final String[] nameWords; @@ -292,11 +305,11 @@ public List getMatchingPresets(String searchText, boolean nameWords = searchText.split("\\s", -1); } - return getMatchingPresets(groupWords, nameWords, onlyApplicable, inTags, presetTypes, selectedPrimitives); + return getMatchingPresets(groupWords, nameWords, onlyApplicable, inTags, isDeprecated, presetTypes, selectedPrimitives); } - public List getMatchingPresets(String[] groupWords, String[] nameWords, boolean onlyApplicable, - boolean inTags, Set presetTypes, final Collection selectedPrimitives) { + public List getMatchingPresets(String[] groupWords, String[] nameWords, boolean onlyApplicable, boolean inTags, + boolean isDeprecated, Set presetTypes, final Collection selectedPrimitives) { final List result = new ArrayList<>(); for (PresetClassification presetClassification : classifications) { @@ -317,6 +330,11 @@ public List getMatchingPresets(String[] groupWords, String } } + //do not show the preset in search dialog if isDeprecated is true and preset is deprecated + if (!isDeprecated && preset.deprecated()) { + continue; + } + if (groupWords != null && presetClassification.isMatchingGroup(groupWords) == 0) { continue; } @@ -424,6 +442,9 @@ public void savePreferences() { if (ckOnlyApplicable != null && ckOnlyApplicable.isEnabled()) { ONLY_APPLICABLE.put(ckOnlyApplicable.isSelected()); } + if (ckDeprecated != null && ckDeprecated.isEnabled()) { + DISPLAY_DEPRECATED.put(ckDeprecated.isSelected()); + } } /** diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java index eba467c4f43..9def4aa64d4 100644 --- a/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java +++ b/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java @@ -42,7 +42,7 @@ public static void setUp() throws IOException, SAXException { } private List getMatchingPresets(String searchText, OsmPrimitive w) { - return classifications.getMatchingPresets(searchText, true, true, EnumSet.of(TaggingPresetType.forPrimitive(w)), + return classifications.getMatchingPresets(searchText, true, true, true, EnumSet.of(TaggingPresetType.forPrimitive(w)), Collections.singleton(w)); } From 5cef4de6d398d9dee08a6946686f956ed335ecf4 Mon Sep 17 00:00:00 2001 From: harry Date: Tue, 8 Aug 2023 03:21:07 +0530 Subject: [PATCH 2/3] Add enum for PresetSearchFilters --- .../data/validation/tests/TagChecker.java | 52 +++++++++-- .../josm/gui/dialogs/SearchDialog.java | 3 +- .../tagging/presets/PresetSearchFilter.java | 72 +++++++++++++++ .../gui/tagging/presets/TaggingPreset.java | 2 +- .../presets/TaggingPresetSearchDialog.java | 2 +- .../TaggingPresetSearchPrimitiveDialog.java | 2 +- .../presets/TaggingPresetSelector.java | 88 ++++++++++--------- .../presets/TaggingPresetValidation.java | 8 +- 8 files changed, 175 insertions(+), 54 deletions(-) create mode 100644 src/org/openstreetmap/josm/gui/tagging/presets/PresetSearchFilter.java diff --git a/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java b/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java index 6ee399c0657..e909f671b70 100644 --- a/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java +++ b/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java @@ -131,6 +131,7 @@ public class TagChecker extends TagTest implements TaggingPresetListener { * The preference key to check presets */ public static final String PREF_CHECK_PRESETS_TYPES = PREFIX + ".checkPresetsTypes"; + public static final String PREF_CHECK_DEPRECATED = PREFIX + ".checkDeprecated"; /** * The preference key for source files @@ -159,6 +160,7 @@ public class TagChecker extends TagTest implements TaggingPresetListener { * The preference key to search for presets - used before upload */ public static final String PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD = PREF_CHECK_PRESETS_TYPES + BEFORE_UPLOAD; + public static final String PREF_CHECK_DEPRECATED_BEFORE_UPLOAD = PREF_CHECK_DEPRECATED + BEFORE_UPLOAD; /** * The preference key for the list of tag keys that are allowed to be the same on a multipolygon and an outer way @@ -175,18 +177,21 @@ public class TagChecker extends TagTest implements TaggingPresetListener { protected boolean checkComplex; protected boolean checkFixmes; protected boolean checkPresetsTypes; + protected boolean checkDeprecated; protected JCheckBox prefCheckKeys; protected JCheckBox prefCheckValues; protected JCheckBox prefCheckComplex; protected JCheckBox prefCheckFixmes; protected JCheckBox prefCheckPresetsTypes; + protected JCheckBox prefCheckDeprecated; protected JCheckBox prefCheckKeysBeforeUpload; protected JCheckBox prefCheckValuesBeforeUpload; protected JCheckBox prefCheckComplexBeforeUpload; protected JCheckBox prefCheckFixmesBeforeUpload; protected JCheckBox prefCheckPresetsTypesBeforeUpload; + protected JCheckBox prefCheckDeprecatedBeforeUpload; // CHECKSTYLE.OFF: SingleSpaceSeparator protected static final int EMPTY_VALUES = 1200; @@ -210,6 +215,7 @@ public class TagChecker extends TagTest implements TaggingPresetListener { protected static final int MULTIPOLYGON_INCOMPLETE = 1219; protected static final int MULTIPOLYGON_MAYBE_NO_AREA = 1220; protected static final int MULTIPOLYGON_SAME_TAG_ON_OUTER = 1221; + protected static final int DEPRECATED_TAG = 1223; // CHECKSTYLE.ON: SingleSpaceSeparator protected EditableList sourcesList; @@ -654,15 +660,22 @@ public void check(OsmPrimitive p) { checkMultipolygonTags(p); } + final Collection matchingPresets; + TagMap tags = p.getKeys(); + if (checkPresetsTypes || checkDeprecated) { + matchingPresets = presetIndex.entrySet().stream() + .filter(e -> TaggingPresetItem.matches(e.getValue(), tags)) + .map(Entry::getKey) + .collect(Collectors.toCollection(LinkedHashSet::new)); + } else { + matchingPresets = null; + } if (checkPresetsTypes) { - TagMap tags = p.getKeys(); + TaggingPresetType presetType = TaggingPresetType.forPrimitive(p); EnumSet presetTypes = EnumSet.of(presetType); - Collection matchingPresets = presetIndex.entrySet().stream() - .filter(e -> TaggingPresetItem.matches(e.getValue(), tags)) - .map(Entry::getKey) - .collect(Collectors.toCollection(LinkedHashSet::new)); + Collection matchingPresetsOK = matchingPresets.stream().filter( tp -> tp.typeMatches(presetTypes)).collect(Collectors.toList()); Collection matchingPresetsKO = matchingPresets.stream().filter( @@ -687,6 +700,18 @@ public void check(OsmPrimitive p) { } } } + if (checkDeprecated) { + for (TaggingPreset preset : matchingPresets) { + if (preset.deprecated()) { + errors.add(TestError.builder(this, Severity.ERROR, DEPRECATED_TAG) + .message(tr("Preset is deprecated"), + marktr("Preset {0} should not be used"), + tr(preset.getName())) + .primitives(p) + .build()); + } + } + } } private static final Collection NO_AREA_KEYS = Arrays.asList("name", "area", "ref", "access", "operator"); @@ -1099,6 +1124,11 @@ public void startTest(ProgressMonitor monitor) { if (isBeforeUpload) { checkPresetsTypes = checkPresetsTypes && Config.getPref().getBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, true); } + + checkDeprecated = includeOtherSeverity && Config.getPref().getBoolean(PREF_CHECK_DEPRECATED, true); + if (isBeforeUpload) { + checkDeprecated = checkDeprecated && Config.getPref().getBoolean(PREF_CHECK_DEPRECATED_BEFORE_UPLOAD, true); + } deprecatedChecker = OsmValidator.getTest(MapCSSTagChecker.class); ignoreForOuterMPSameTagCheck.addAll(Config.getPref().getList(PREF_KEYS_IGNORE_OUTER_MP_SAME_TAG, Collections.emptyList())); } @@ -1111,7 +1141,7 @@ public void endTest() { @Override public void visit(Collection selection) { - if (checkKeys || checkValues || checkComplex || checkFixmes || checkPresetsTypes) { + if (checkKeys || checkValues || checkComplex || checkFixmes || checkPresetsTypes || checkDeprecated) { super.visit(selection); } } @@ -1176,6 +1206,14 @@ public void addGui(JPanel testPanel) { prefCheckPresetsTypesBeforeUpload = new JCheckBox(); prefCheckPresetsTypesBeforeUpload.setSelected(Config.getPref().getBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, true)); testPanel.add(prefCheckPresetsTypesBeforeUpload, a); + + prefCheckDeprecated = new JCheckBox(tr("Check for deprecated tags"), Config.getPref().getBoolean(PREF_CHECK_DEPRECATED, true)); + prefCheckDeprecated.setToolTipText(tr("Check whether the preset is deprecated")); + testPanel.add(prefCheckDeprecated, GBC.std().insets(20, 0, 0, 0)); + + prefCheckDeprecatedBeforeUpload = new JCheckBox(); + prefCheckDeprecatedBeforeUpload.setSelected(Config.getPref().getBoolean(PREF_CHECK_DEPRECATED_BEFORE_UPLOAD, true)); + testPanel.add(prefCheckDeprecatedBeforeUpload, a); } /** @@ -1198,11 +1236,13 @@ public boolean ok() { Config.getPref().putBoolean(PREF_CHECK_KEYS, prefCheckKeys.isSelected()); Config.getPref().putBoolean(PREF_CHECK_FIXMES, prefCheckFixmes.isSelected()); Config.getPref().putBoolean(PREF_CHECK_PRESETS_TYPES, prefCheckPresetsTypes.isSelected()); + Config.getPref().putBoolean(PREF_CHECK_DEPRECATED, prefCheckDeprecated.isSelected()); Config.getPref().putBoolean(PREF_CHECK_VALUES_BEFORE_UPLOAD, prefCheckValuesBeforeUpload.isSelected()); Config.getPref().putBoolean(PREF_CHECK_COMPLEX_BEFORE_UPLOAD, prefCheckComplexBeforeUpload.isSelected()); Config.getPref().putBoolean(PREF_CHECK_KEYS_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected()); Config.getPref().putBoolean(PREF_CHECK_FIXMES_BEFORE_UPLOAD, prefCheckFixmesBeforeUpload.isSelected()); Config.getPref().putBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, prefCheckPresetsTypesBeforeUpload.isSelected()); + Config.getPref().putBoolean(PREF_CHECK_DEPRECATED_BEFORE_UPLOAD, prefCheckDeprecatedBeforeUpload.isSelected()); return Config.getPref().putList(PREF_SOURCES, sourcesList.getItems()); } diff --git a/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java b/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java index acfb73bd676..ba434e820cc 100644 --- a/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java +++ b/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java @@ -38,6 +38,7 @@ import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSException; import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBox; import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBoxModel; +import org.openstreetmap.josm.gui.tagging.presets.PresetSearchFilter; import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector; import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator; @@ -231,7 +232,7 @@ public boolean isValid() { * selected preset by the user. Every query is of the form ' group/sub-group/.../presetName' * if the corresponding group of the preset exists, otherwise it is simply ' presetName'. */ - selector = new TaggingPresetSelector(false, false, false); + selector = new TaggingPresetSelector(PresetSearchFilter.values()); selector.setBorder(BorderFactory.createTitledBorder(tr("Search by preset"))); selector.setDblClickListener(ev -> setPresetDblClickListener(selector, editorComponent)); diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/PresetSearchFilter.java b/src/org/openstreetmap/josm/gui/tagging/presets/PresetSearchFilter.java new file mode 100644 index 00000000000..cd44e67c2ea --- /dev/null +++ b/src/org/openstreetmap/josm/gui/tagging/presets/PresetSearchFilter.java @@ -0,0 +1,72 @@ +// License: GPL. For details, see LICENSE file. +package org.openstreetmap.josm.gui.tagging.presets; + +import java.util.EnumMap; +import java.util.Map; + +import static org.openstreetmap.josm.tools.I18n.marktr; + +/** + * This enum defines different filters for searching presets. + */ +public enum PresetSearchFilter { + ONLY_APPLICABLE(marktr("Show only applicable to selection")), + SEARCH_IN_TAGS(marktr("Search in tags")), + DEPRECATED_TAGS(marktr("Show deprecated tags")); + + /** + * Map containing the preferences for the filters + */ + private Map filtersPreference; + + static { + for (PresetSearchFilter filter : values()) { + filter.filtersPreference = new EnumMap<>(PresetSearchFilter.class); + filter.filtersPreference.put(filter, true); + } + } + + /** + * Sets the preference for the filter + * @param filter the filter to set the preference for + * @param pref true if the filter is enabled, false otherwise + * @since xxx + */ + public void setPref(PresetSearchFilter filter, Boolean pref) { + filtersPreference.put(filter, pref); + } + + /** + * Gets the preference for the filter + * @param filter the filter to get the preference for + * @return true if the filter is enabled, false otherwise + * @since xxx + */ + public Boolean getPref(PresetSearchFilter filter) { + return filtersPreference.get(filter); + } + + /** + * The translated text associated with the enum constant. + */ + private final String translatedText; + + /** + * Constructor for the PresetSearchFilter enum. + * Initializes an enum constant with its corresponding translated text. + * + * @param translatedText The translated text associated with the enum constant. + */ + PresetSearchFilter(String translatedText) { + this.translatedText = translatedText; + } + + /** + * Returns the text associated with the filter + * @return the text marked for translation + */ + public String getText() { + return translatedText; + } + +} diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java index 56274c7c383..5b3d3d69f0f 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java @@ -139,7 +139,7 @@ public class TaggingPreset extends AbstractAction implements ActiveLayerChangeLi /** * True if the preset is deprecated */ - private boolean deprecated = false; + private boolean deprecated; /** * The types as preparsed collection. diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java index b30f6faa9a6..083dc52b6e8 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java @@ -34,7 +34,7 @@ private TaggingPresetSearchDialog() { super(MainApplication.getMainFrame(), tr("Search presets"), tr("Select"), tr("Cancel")); setButtonIcons("dialogs/search", "cancel"); configureContextsensitiveHelp("/Action/TaggingPresetSearch", true /* show help button */); - selector = new TaggingPresetSelector(true, true, true); + selector = new TaggingPresetSelector(PresetSearchFilter.values()); setContent(selector, false); SelectionEventManager.getInstance().addSelectionListener(selector); selector.setDblClickListener(e -> buttonAction(0, null)); diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java index 68634391d07..536eb118c79 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java @@ -67,7 +67,7 @@ public static synchronized TaggingPresetSearchPrimitiveDialog getInstance() { super(MainApplication.getMainFrame(), tr("Search for objects by preset"), tr("Search"), tr("Cancel")); setButtonIcons("dialogs/search", "cancel"); configureContextsensitiveHelp("/Action/TaggingPresetSearchPrimitive", true /* show help button */); - selector = new TaggingPresetSelector(false, false, false); + selector = new TaggingPresetSelector(PresetSearchFilter.values()); setContent(selector, false); selector.setDblClickListener(e -> buttonAction(0, null)); } diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java index 2a273b70bd9..33d4aebb9d8 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java @@ -38,7 +38,6 @@ import org.openstreetmap.josm.data.osm.DataSet; import org.openstreetmap.josm.data.osm.OsmDataManager; import org.openstreetmap.josm.data.osm.OsmPrimitive; -import org.openstreetmap.josm.data.preferences.BooleanProperty; import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.tagging.presets.items.ComboMultiSelect; import org.openstreetmap.josm.gui.tagging.presets.items.Key; @@ -64,13 +63,12 @@ public class TaggingPresetSelector extends SearchTextResultListPanel typesInSelection = EnumSet.noneOf(TaggingPresetType.class); private boolean typesInSelectionDirty = true; private final transient PresetClassifications classifications = new PresetClassifications(); @@ -201,9 +199,17 @@ public String toString() { * Constructs a new {@code TaggingPresetSelector}. * @param displayOnlyApplicable if {@code true} display "Show only applicable to selection" checkbox * @param displaySearchInTags if {@code true} display "Search in tags" checkbox - * @param displayDeprecated if {@code true} display "Applicable in region" checkbox */ public TaggingPresetSelector(boolean displayOnlyApplicable, boolean displaySearchInTags, boolean displayDeprecated) { + this(displayOnlyApplicable ? PresetSearchFilter.ONLY_APPLICABLE : null, displaySearchInTags ? PresetSearchFilter.SEARCH_IN_TAGS : null, + displayDeprecated ? PresetSearchFilter.DEPRECATED_TAGS : null); + } + + /** + * Called from the {@code TaggingPresetConstructor}. + * + */ + public TaggingPresetSelector(PresetSearchFilter... options) { super(); lsResult.setCellRenderer(new ResultListCellRenderer()); classifications.loadPresets(TaggingPresets.getTaggingPresets()); @@ -212,32 +218,30 @@ public TaggingPresetSelector(boolean displayOnlyApplicable, boolean displaySearc JPanel pnChecks = new JPanel(); pnChecks.setLayout(new BoxLayout(pnChecks, BoxLayout.Y_AXIS)); - if (displayOnlyApplicable) { - ckOnlyApplicable = new JCheckBox(); - ckOnlyApplicable.setText(tr("Show only applicable to selection")); - pnChecks.add(ckOnlyApplicable); - ckOnlyApplicable.addItemListener(e -> filterItems()); - } else { - ckOnlyApplicable = null; - } - - if (displaySearchInTags) { - ckSearchInTags = new JCheckBox(); - ckSearchInTags.setText(tr("Search in tags")); - ckSearchInTags.setSelected(SEARCH_IN_TAGS.get()); - ckSearchInTags.addItemListener(e -> filterItems()); - pnChecks.add(ckSearchInTags); - } else { - ckSearchInTags = null; - } - - if (displayDeprecated) { - ckDeprecated = new JCheckBox(); - ckDeprecated.setText(tr("Show deprecated tags")); - pnChecks.add(ckDeprecated); - ckDeprecated.addItemListener(e -> filterItems()); - } else { - ckDeprecated = null; + for (PresetSearchFilter option : options) { + switch(option) { + case ONLY_APPLICABLE: { + ckOnlyApplicable = new JCheckBox(); + ckOnlyApplicable.setText(tr(PresetSearchFilter.ONLY_APPLICABLE.getText())); + pnChecks.add(ckOnlyApplicable); + ckOnlyApplicable.addItemListener(e -> filterItems()); + break; + } + case SEARCH_IN_TAGS: { + ckSearchInTags = new JCheckBox(); + ckSearchInTags.setText(tr(PresetSearchFilter.ONLY_APPLICABLE.getText())); + ckSearchInTags.setSelected(SEARCH_IN_TAGS.getPref(PresetSearchFilter.SEARCH_IN_TAGS)); + ckSearchInTags.addItemListener(e -> filterItems()); + pnChecks.add(ckSearchInTags); + break; + } + case DEPRECATED_TAGS: { + ckDeprecated = new JCheckBox(); + ckDeprecated.setText(tr(PresetSearchFilter.DEPRECATED_TAGS.getText())); + pnChecks.add(ckDeprecated); + ckDeprecated.addItemListener(e -> filterItems()); + } + } } add(pnChecks, BorderLayout.SOUTH); @@ -264,14 +268,12 @@ public void actionPerformed(ActionEvent ae) { protected synchronized void filterItems() { //TODO Save favorites to file String text = edSearchText.getText().toLowerCase(Locale.ENGLISH); - boolean onlyApplicable = ckOnlyApplicable != null && ckOnlyApplicable.isSelected(); - boolean inTags = ckSearchInTags != null && ckSearchInTags.isSelected(); - boolean isDeprecated = ckDeprecated != null && ckDeprecated.isSelected(); DataSet ds = OsmDataManager.getInstance().getEditDataSet(); Collection selected = (ds == null) ? Collections.emptyList() : ds.getSelected(); final List result = classifications.getMatchingPresets( - text, onlyApplicable, inTags, isDeprecated, getTypesInSelection(), selected); + text, ONLY_APPLICABLE.getPref(PresetSearchFilter.ONLY_APPLICABLE), SEARCH_IN_TAGS.getPref(PresetSearchFilter.SEARCH_IN_TAGS), + DEPRECATED_TAGS.getPref(PresetSearchFilter.DEPRECATED_TAGS), getTypesInSelection(), selected); final TaggingPreset oldPreset = getSelectedPreset(); lsResultModel.setItems(Utils.transform(result, x -> x.preset)); @@ -417,7 +419,7 @@ public void selectionChanged(SelectionChangeEvent event) { public synchronized void init() { if (ckOnlyApplicable != null) { ckOnlyApplicable.setEnabled(!getTypesInSelection().isEmpty()); - ckOnlyApplicable.setSelected(!getTypesInSelection().isEmpty() && ONLY_APPLICABLE.get()); + ckOnlyApplicable.setSelected(!getTypesInSelection().isEmpty() && ONLY_APPLICABLE.getPref(PresetSearchFilter.ONLY_APPLICABLE)); } super.init(); } @@ -437,13 +439,13 @@ public void init(Collection presets) { */ public void savePreferences() { if (ckSearchInTags != null) { - SEARCH_IN_TAGS.put(ckSearchInTags.isSelected()); + SEARCH_IN_TAGS.setPref(PresetSearchFilter.SEARCH_IN_TAGS, ckSearchInTags.isSelected()); } if (ckOnlyApplicable != null && ckOnlyApplicable.isEnabled()) { - ONLY_APPLICABLE.put(ckOnlyApplicable.isSelected()); + ONLY_APPLICABLE.setPref(PresetSearchFilter.ONLY_APPLICABLE, ckOnlyApplicable.isSelected()); } if (ckDeprecated != null && ckDeprecated.isEnabled()) { - DISPLAY_DEPRECATED.put(ckDeprecated.isSelected()); + DEPRECATED_TAGS.setPref(PresetSearchFilter.DEPRECATED_TAGS, ckDeprecated.isSelected()); } } diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetValidation.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetValidation.java index 1bae43cc854..724eea90ae4 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetValidation.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetValidation.java @@ -24,7 +24,9 @@ import org.openstreetmap.josm.data.validation.TestError; import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker; import org.openstreetmap.josm.data.validation.tests.OpeningHourTest; +import org.openstreetmap.josm.data.validation.tests.TagChecker; import org.openstreetmap.josm.gui.MainApplication; +import org.openstreetmap.josm.gui.progress.NullProgressMonitor; import org.openstreetmap.josm.gui.util.GuiHelper; import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.SubclassFilteredCollection; @@ -55,11 +57,15 @@ static void validate(OsmPrimitive primitive, JLabel validationLabel) { try { MapCSSTagChecker mapCSSTagChecker = OsmValidator.getTest(MapCSSTagChecker.class); OpeningHourTest openingHourTest = OsmValidator.getTest(OpeningHourTest.class); - OsmValidator.initializeTests(Arrays.asList(mapCSSTagChecker, openingHourTest)); + TagChecker tagChecker = OsmValidator.getTest(TagChecker.class); + tagChecker.startTest(NullProgressMonitor.INSTANCE); //since initializeTest works if test is enabled + OsmValidator.initializeTests(Arrays.asList(mapCSSTagChecker, openingHourTest, tagChecker)); List errors = new ArrayList<>(); openingHourTest.addErrorsForPrimitive(primitive, errors); errors.addAll(mapCSSTagChecker.getErrorsForPrimitive(primitive, ValidatorPrefHelper.PREF_OTHER.get())); + tagChecker.check(primitive); + errors.addAll(tagChecker.getErrors()); boolean visible = !errors.isEmpty(); String toolTipText = "" + Utils.joinAsHtmlUnorderedList(Utils.transform(errors, e -> From 3e6df3e53cb47c3a0a11646179e36649b60e94f9 Mon Sep 17 00:00:00 2001 From: harry Date: Mon, 28 Aug 2023 00:51:28 +0530 Subject: [PATCH 3/3] Add support for deprecated attribute in search dialog --- resources/data/tagging-preset.xsd | 9 ++- .../josm/gui/dialogs/SearchDialog.java | 3 +- .../tagging/presets/PresetSearchFilter.java | 45 ++--------- .../presets/TaggingPresetSearchDialog.java | 3 +- .../TaggingPresetSearchPrimitiveDialog.java | 2 +- .../presets/TaggingPresetSelector.java | 74 ++++++++++--------- 6 files changed, 58 insertions(+), 78 deletions(-) diff --git a/resources/data/tagging-preset.xsd b/resources/data/tagging-preset.xsd index 097224b111f..e4984676d27 100644 --- a/resources/data/tagging-preset.xsd +++ b/resources/data/tagging-preset.xsd @@ -121,7 +121,7 @@ - Every item is one annotation set to select from. name is required, type and preset_name_label are recommended, icon and name_template are optional attributes. + Every item is one annotation set to select from. name is required, type and preset_name_label are recommended, deprecated, icon, name_template are optional attributes. @@ -171,6 +171,13 @@ + + + + Whether this preset is deprecated (defaults to "false"). + + + diff --git a/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java b/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java index ba434e820cc..415bde8c4b8 100644 --- a/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java +++ b/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java @@ -38,7 +38,6 @@ import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSException; import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBox; import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBoxModel; -import org.openstreetmap.josm.gui.tagging.presets.PresetSearchFilter; import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector; import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator; @@ -232,7 +231,7 @@ public boolean isValid() { * selected preset by the user. Every query is of the form ' group/sub-group/.../presetName' * if the corresponding group of the preset exists, otherwise it is simply ' presetName'. */ - selector = new TaggingPresetSelector(PresetSearchFilter.values()); + selector = new TaggingPresetSelector(); selector.setBorder(BorderFactory.createTitledBorder(tr("Search by preset"))); selector.setDblClickListener(ev -> setPresetDblClickListener(selector, editorComponent)); diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/PresetSearchFilter.java b/src/org/openstreetmap/josm/gui/tagging/presets/PresetSearchFilter.java index cd44e67c2ea..6a548a25758 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/PresetSearchFilter.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/PresetSearchFilter.java @@ -1,9 +1,6 @@ // License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.gui.tagging.presets; -import java.util.EnumMap; -import java.util.Map; - import static org.openstreetmap.josm.tools.I18n.marktr; /** @@ -14,51 +11,19 @@ public enum PresetSearchFilter { SEARCH_IN_TAGS(marktr("Search in tags")), DEPRECATED_TAGS(marktr("Show deprecated tags")); - /** - * Map containing the preferences for the filters - */ - private Map filtersPreference; - - static { - for (PresetSearchFilter filter : values()) { - filter.filtersPreference = new EnumMap<>(PresetSearchFilter.class); - filter.filtersPreference.put(filter, true); - } - } - - /** - * Sets the preference for the filter - * @param filter the filter to set the preference for - * @param pref true if the filter is enabled, false otherwise - * @since xxx - */ - public void setPref(PresetSearchFilter filter, Boolean pref) { - filtersPreference.put(filter, pref); - } - - /** - * Gets the preference for the filter - * @param filter the filter to get the preference for - * @return true if the filter is enabled, false otherwise - * @since xxx - */ - public Boolean getPref(PresetSearchFilter filter) { - return filtersPreference.get(filter); - } - /** * The translated text associated with the enum constant. */ - private final String translatedText; + private final String textToBeTranslated; /** * Constructor for the PresetSearchFilter enum. * Initializes an enum constant with its corresponding translated text. * - * @param translatedText The translated text associated with the enum constant. + * @param textToBeTranslated The translated text associated with the enum constant. */ - PresetSearchFilter(String translatedText) { - this.translatedText = translatedText; + PresetSearchFilter(String textToBeTranslated) { + this.textToBeTranslated = textToBeTranslated; } /** @@ -66,7 +31,7 @@ public Boolean getPref(PresetSearchFilter filter) { * @return the text marked for translation */ public String getText() { - return translatedText; + return textToBeTranslated; } } diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java index 083dc52b6e8..c3dd2c81636 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java @@ -34,7 +34,8 @@ private TaggingPresetSearchDialog() { super(MainApplication.getMainFrame(), tr("Search presets"), tr("Select"), tr("Cancel")); setButtonIcons("dialogs/search", "cancel"); configureContextsensitiveHelp("/Action/TaggingPresetSearch", true /* show help button */); - selector = new TaggingPresetSelector(PresetSearchFilter.values()); + selector = new TaggingPresetSelector(PresetSearchFilter.ONLY_APPLICABLE, PresetSearchFilter.SEARCH_IN_TAGS, + PresetSearchFilter.DEPRECATED_TAGS); setContent(selector, false); SelectionEventManager.getInstance().addSelectionListener(selector); selector.setDblClickListener(e -> buttonAction(0, null)); diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java index 536eb118c79..3f42b9cce1a 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java @@ -67,7 +67,7 @@ public static synchronized TaggingPresetSearchPrimitiveDialog getInstance() { super(MainApplication.getMainFrame(), tr("Search for objects by preset"), tr("Search"), tr("Cancel")); setButtonIcons("dialogs/search", "cancel"); configureContextsensitiveHelp("/Action/TaggingPresetSearchPrimitive", true /* show help button */); - selector = new TaggingPresetSelector(PresetSearchFilter.values()); + selector = new TaggingPresetSelector(); setContent(selector, false); selector.setDblClickListener(e -> buttonAction(0, null)); } diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java index 33d4aebb9d8..4ec09fa939d 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java @@ -10,11 +10,13 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.EnumMap; import java.util.EnumSet; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.regex.Pattern; @@ -63,12 +65,15 @@ public class TaggingPresetSelector extends SearchTextResultListPanel ckpreferences = new EnumMap<>(PresetSearchFilter.class); + { + //initial value of the checkboxes + ckpreferences.put(PresetSearchFilter.ONLY_APPLICABLE, true); + ckpreferences.put(PresetSearchFilter.SEARCH_IN_TAGS, true); + ckpreferences.put(PresetSearchFilter.DEPRECATED_TAGS, false); + } + + final Map checkboxes = new EnumMap<>(PresetSearchFilter.class); private final Set typesInSelection = EnumSet.noneOf(TaggingPresetType.class); private boolean typesInSelectionDirty = true; private final transient PresetClassifications classifications = new PresetClassifications(); @@ -200,9 +205,8 @@ public String toString() { * @param displayOnlyApplicable if {@code true} display "Show only applicable to selection" checkbox * @param displaySearchInTags if {@code true} display "Search in tags" checkbox */ - public TaggingPresetSelector(boolean displayOnlyApplicable, boolean displaySearchInTags, boolean displayDeprecated) { - this(displayOnlyApplicable ? PresetSearchFilter.ONLY_APPLICABLE : null, displaySearchInTags ? PresetSearchFilter.SEARCH_IN_TAGS : null, - displayDeprecated ? PresetSearchFilter.DEPRECATED_TAGS : null); + public TaggingPresetSelector(boolean displayOnlyApplicable, boolean displaySearchInTags) { + this(displayOnlyApplicable ? PresetSearchFilter.ONLY_APPLICABLE : null, displaySearchInTags ? PresetSearchFilter.SEARCH_IN_TAGS : null); } /** @@ -219,27 +223,25 @@ public TaggingPresetSelector(PresetSearchFilter... options) { pnChecks.setLayout(new BoxLayout(pnChecks, BoxLayout.Y_AXIS)); for (PresetSearchFilter option : options) { + final JCheckBox box = new JCheckBox(); + box.setText(tr(option.getText())); + pnChecks.add(box); + box.addItemListener(e -> filterItems()); switch(option) { case ONLY_APPLICABLE: { - ckOnlyApplicable = new JCheckBox(); - ckOnlyApplicable.setText(tr(PresetSearchFilter.ONLY_APPLICABLE.getText())); - pnChecks.add(ckOnlyApplicable); - ckOnlyApplicable.addItemListener(e -> filterItems()); + box.setSelected(ckpreferences.get(PresetSearchFilter.ONLY_APPLICABLE)); + checkboxes.put(PresetSearchFilter.ONLY_APPLICABLE, box); break; } case SEARCH_IN_TAGS: { - ckSearchInTags = new JCheckBox(); - ckSearchInTags.setText(tr(PresetSearchFilter.ONLY_APPLICABLE.getText())); - ckSearchInTags.setSelected(SEARCH_IN_TAGS.getPref(PresetSearchFilter.SEARCH_IN_TAGS)); - ckSearchInTags.addItemListener(e -> filterItems()); - pnChecks.add(ckSearchInTags); + box.setSelected(ckpreferences.get(PresetSearchFilter.SEARCH_IN_TAGS)); + checkboxes.put(PresetSearchFilter.SEARCH_IN_TAGS, box); break; } case DEPRECATED_TAGS: { - ckDeprecated = new JCheckBox(); - ckDeprecated.setText(tr(PresetSearchFilter.DEPRECATED_TAGS.getText())); - pnChecks.add(ckDeprecated); - ckDeprecated.addItemListener(e -> filterItems()); + box.setSelected((ckpreferences.get(PresetSearchFilter.DEPRECATED_TAGS))); + checkboxes.put(PresetSearchFilter.DEPRECATED_TAGS, box); + break; } } } @@ -268,12 +270,17 @@ public void actionPerformed(ActionEvent ae) { protected synchronized void filterItems() { //TODO Save favorites to file String text = edSearchText.getText().toLowerCase(Locale.ENGLISH); + boolean onlyApplicable = checkboxes.get(PresetSearchFilter.ONLY_APPLICABLE) != null && + checkboxes.get(PresetSearchFilter.ONLY_APPLICABLE).isSelected(); + boolean deprecatedTags = checkboxes.get(PresetSearchFilter.DEPRECATED_TAGS) != null && + checkboxes.get(PresetSearchFilter.DEPRECATED_TAGS).isSelected(); + boolean searchInTags = checkboxes.get(PresetSearchFilter.SEARCH_IN_TAGS) != null && + checkboxes.get(PresetSearchFilter.SEARCH_IN_TAGS).isSelected(); DataSet ds = OsmDataManager.getInstance().getEditDataSet(); Collection selected = (ds == null) ? Collections.emptyList() : ds.getSelected(); final List result = classifications.getMatchingPresets( - text, ONLY_APPLICABLE.getPref(PresetSearchFilter.ONLY_APPLICABLE), SEARCH_IN_TAGS.getPref(PresetSearchFilter.SEARCH_IN_TAGS), - DEPRECATED_TAGS.getPref(PresetSearchFilter.DEPRECATED_TAGS), getTypesInSelection(), selected); + text, onlyApplicable, searchInTags, deprecatedTags, getTypesInSelection(), selected); final TaggingPreset oldPreset = getSelectedPreset(); lsResultModel.setItems(Utils.transform(result, x -> x.preset)); @@ -417,9 +424,10 @@ public void selectionChanged(SelectionChangeEvent event) { @Override public synchronized void init() { - if (ckOnlyApplicable != null) { - ckOnlyApplicable.setEnabled(!getTypesInSelection().isEmpty()); - ckOnlyApplicable.setSelected(!getTypesInSelection().isEmpty() && ONLY_APPLICABLE.getPref(PresetSearchFilter.ONLY_APPLICABLE)); + if (checkboxes.get(PresetSearchFilter.ONLY_APPLICABLE) != null) { + checkboxes.get(PresetSearchFilter.ONLY_APPLICABLE).setEnabled(!getTypesInSelection().isEmpty()); + checkboxes.get(PresetSearchFilter.ONLY_APPLICABLE).setSelected(!getTypesInSelection().isEmpty() && + ckpreferences.get(PresetSearchFilter.ONLY_APPLICABLE)); } super.init(); } @@ -438,14 +446,14 @@ public void init(Collection presets) { * Save checkbox values in preferences for future reuse */ public void savePreferences() { - if (ckSearchInTags != null) { - SEARCH_IN_TAGS.setPref(PresetSearchFilter.SEARCH_IN_TAGS, ckSearchInTags.isSelected()); + if (checkboxes.get(PresetSearchFilter.SEARCH_IN_TAGS) != null) { + ckpreferences.put(PresetSearchFilter.SEARCH_IN_TAGS, checkboxes.get(PresetSearchFilter.SEARCH_IN_TAGS).isSelected()); } - if (ckOnlyApplicable != null && ckOnlyApplicable.isEnabled()) { - ONLY_APPLICABLE.setPref(PresetSearchFilter.ONLY_APPLICABLE, ckOnlyApplicable.isSelected()); + if (checkboxes.get(PresetSearchFilter.ONLY_APPLICABLE) != null && checkboxes.get(PresetSearchFilter.ONLY_APPLICABLE).isEnabled()) { + ckpreferences.put(PresetSearchFilter.ONLY_APPLICABLE, checkboxes.get(PresetSearchFilter.ONLY_APPLICABLE).isSelected()); } - if (ckDeprecated != null && ckDeprecated.isEnabled()) { - DEPRECATED_TAGS.setPref(PresetSearchFilter.DEPRECATED_TAGS, ckDeprecated.isSelected()); + if (checkboxes.get(PresetSearchFilter.DEPRECATED_TAGS) != null && checkboxes.get(PresetSearchFilter.DEPRECATED_TAGS).isEnabled()) { + ckpreferences.put(PresetSearchFilter.DEPRECATED_TAGS, checkboxes.get(PresetSearchFilter.DEPRECATED_TAGS).isSelected()); } }