-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for deprecated attribute and update the presets search dialog #123
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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<TaggingPreset> | ||||||||||||||||||||||||||
|
@@ -66,9 +66,11 @@ public class TaggingPresetSelector extends SearchTextResultListPanel<TaggingPres | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
private static final BooleanProperty SEARCH_IN_TAGS = new BooleanProperty("taggingpreset.dialog.search-in-tags", true); | ||||||||||||||||||||||||||
private static final BooleanProperty ONLY_APPLICABLE = new BooleanProperty("taggingpreset.dialog.only-applicable-to-selection", true); | ||||||||||||||||||||||||||
private static final BooleanProperty DISPLAY_DEPRECATED = new BooleanProperty("taggingpreset.dialog.display-deprecated", true); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
private final JCheckBox ckOnlyApplicable; | ||||||||||||||||||||||||||
private final JCheckBox ckSearchInTags; | ||||||||||||||||||||||||||
private final JCheckBox ckDeprecated; | ||||||||||||||||||||||||||
private final Set<TaggingPresetType> 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) { | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point, I think we should start using an enum instead of a bunch of booleans. Example:
Suggested change
I'll note that my code isn't properly organized, so the enum would go better elsewhere, and I didn't add the class reference in the constructor, but that should (largely) work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a checkbox for regions as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, yes. Realistically, the "primary" caller will probably just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Does that mean we would use the preference for the checkbox associated with the filter like |
||||||||||||||||||||||||||
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; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going further on the enums, there are |
||||||||||||||||||||||||||
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(); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving on with the |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
DataSet ds = OsmDataManager.getInstance().getEditDataSet(); | ||||||||||||||||||||||||||
Collection<OsmPrimitive> selected = (ds == null) ? Collections.<OsmPrimitive>emptyList() : ds.getSelected(); | ||||||||||||||||||||||||||
final List<PresetClassification> 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<PresetClassificati | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
private final List<PresetClassification> classifications = new ArrayList<>(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
public List<PresetClassification> getMatchingPresets(String searchText, boolean onlyApplicable, boolean inTags, | ||||||||||||||||||||||||||
public List<PresetClassification> getMatchingPresets(String searchText, boolean onlyApplicable, boolean inTags, boolean isDeprecated, | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably use an enum here. We could probably reuse the one I mentioned earlier (so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would probably work. But we have other locations where we have search strings. It might be better to have some more identifying information. Although this really depends upon where we put the |
||||||||||||||||||||||||||
Set<TaggingPresetType> presetTypes, final Collection<? extends OsmPrimitive> selectedPrimitives) { | ||||||||||||||||||||||||||
final String[] groupWords; | ||||||||||||||||||||||||||
final String[] nameWords; | ||||||||||||||||||||||||||
|
@@ -292,11 +305,11 @@ public List<PresetClassification> 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<PresetClassification> getMatchingPresets(String[] groupWords, String[] nameWords, boolean onlyApplicable, | ||||||||||||||||||||||||||
boolean inTags, Set<TaggingPresetType> presetTypes, final Collection<? extends OsmPrimitive> selectedPrimitives) { | ||||||||||||||||||||||||||
public List<PresetClassification> getMatchingPresets(String[] groupWords, String[] nameWords, boolean onlyApplicable, boolean inTags, | ||||||||||||||||||||||||||
boolean isDeprecated, Set<TaggingPresetType> presetTypes, final Collection<? extends OsmPrimitive> selectedPrimitives) { | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should probably mention (at this point) why I think we should start moving these booleans to an enum: easier readability. There are some other advantages, but As a specific example, GitHub doesn't show what a boolean is supposed to be for, so the reviewer/editor has to know the function definition, or go find it. |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
final List<PresetClassification> result = new ArrayList<>(); | ||||||||||||||||||||||||||
for (PresetClassification presetClassification : classifications) { | ||||||||||||||||||||||||||
|
@@ -317,6 +330,11 @@ public List<PresetClassification> 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()); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.