Changeset 17662 in josm


Ignore:
Timestamp:
2021-03-25T00:28:04+01:00 (3 years ago)
Author:
simon04
Message:

fix #19012 - Tagging presets: additional matching criteria via <item match_expression="...">

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/resources/data/tagging-preset.xsd

    r17610 r17662  
    156156            </annotation>
    157157        </attribute>
     158        <attribute name="match_expression" type="string">
     159            <annotation>
     160                <documentation>
     161                    Additional criteria for matching primitives. Specified in <a href="https://josm.openstreetmap.de/wiki/Help/Action/Search">JOSM search syntax</a>.
     162                    For instance, a preset with <code>match_expression="foo=bar"</code> requires OSM objects to have the tag <code>foo=bar</code>.
     163                    You may want to use the <code>match_expression</code> to exclude certain OSM objects, for instance when a more specific preset is present.
     164                </documentation>
     165            </annotation>
     166        </attribute>
    158167        <attribute name="preset_name_label" type="boolean">
    159168            <annotation>
  • trunk/src/org/openstreetmap/josm/data/osm/Tagged.java

    r17584 r17662  
    233233        return OsmUtils.isFalse(get(key));
    234234    }
     235
     236    /**
     237     * Returns a Tagged instance for the given tag map
     238     * @param tags the tag map
     239     * @return a Tagged instance for the given tag map
     240     */
     241    static Tagged ofMap(Map<String, String> tags) {
     242        return new Tagged() {
     243
     244            @Override
     245            public String get(String key) {
     246                return tags.get(key);
     247            }
     248
     249            @Override
     250            public Map<String, String> getKeys() {
     251                return tags;
     252            }
     253
     254            @Override
     255            public Collection<String> keySet() {
     256                return tags.keySet();
     257            }
     258
     259            @Override
     260            public void put(String key, String value) {
     261                tags.put(key, value);
     262            }
     263
     264            @Override
     265            public void setKeys(Map<String, String> keys) {
     266                tags.putAll(keys);
     267            }
     268
     269            @Override
     270            public boolean hasKeys() {
     271                return !tags.isEmpty();
     272            }
     273
     274            @Override
     275            public int getNumKeys() {
     276                return tags.size();
     277            }
     278
     279            @Override
     280            public void remove(String key) {
     281                tags.remove(key);
     282            }
     283
     284            @Override
     285            public void removeAll() {
     286                tags.clear();
     287            }
     288        };
     289    }
    235290}
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r17651 r17662  
    4848import org.openstreetmap.josm.data.osm.RelationMember;
    4949import org.openstreetmap.josm.data.osm.Tag;
     50import org.openstreetmap.josm.data.osm.Tagged;
    5051import org.openstreetmap.josm.data.osm.Way;
    5152import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     
    135136    public transient TemplateEntry nameTemplate;
    136137    public transient Match nameTemplateFilter;
     138    public transient Match matchExpression;
    137139
    138140    /**
     
    288290    }
    289291
     292    public void setMatch_expression(String filter) throws SAXException {
     293        try {
     294            this.matchExpression = SearchCompiler.compile(filter);
     295        } catch (SearchParseError e) {
     296            Logging.error("Error while parsing" + filter + ": " + e.getMessage());
     297            throw new SAXException(e);
     298        }
     299    }
     300
    290301    private static class PresetPanel extends JPanel {
    291302        private boolean hasElements;
     
    646657        if ((onlyShowable && !isShowable()) || !typeMatches(t)) {
    647658            return false;
     659        } else if (matchExpression != null && !matchExpression.match(Tagged.ofMap(tags))) {
     660            return false;
    648661        } else {
    649662            return TaggingPresetItem.matches(data, tags);
Note: See TracChangeset for help on using the changeset viewer.