Changeset 18080 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2021-07-22T22:43:10+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/tagging/presets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItemGuiSupport.java
r17876 r18080 6 6 import org.openstreetmap.josm.data.osm.Tagged; 7 7 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 8 import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem;9 8 import org.openstreetmap.josm.tools.ListenerList; 10 9 import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider; … … 14 13 import java.util.Collections; 15 14 import java.util.function.Supplier; 16 import java.util.stream.Collectors;17 15 18 16 /** … … 70 68 * Creates a new {@code TaggingPresetItemGuiSupport} 71 69 * 70 * @param presetInitiallyMatches whether the preset initially matched 72 71 * @param selected the selected primitives 73 * @param presetInitiallyMatches whether thepreset initially matched72 * @param changedTagsSupplier the changed tags 74 73 * @return the new {@code TaggingPresetItemGuiSupport} 75 74 */ … … 82 81 * Creates a new {@code TaggingPresetItemGuiSupport} 83 82 * 83 * @param presetInitiallyMatches whether the preset initially matched 84 84 * @param selected the selected primitives 85 * @param presetInitiallyMatches whether the preset initially matched86 85 * @return the new {@code TaggingPresetItemGuiSupport} 87 86 */ … … 91 90 } 92 91 92 /** 93 * Get tags with values as currently shown in the dialog. 94 * If exactly one primitive is selected, get all tags of it, then 95 * overwrite with the current values shown in the dialog. 96 * Else get only the tags shown in the dialog. 97 * @return Tags 98 */ 99 public Tagged getTagged() { 100 if (selected.size() != 1) { 101 return Tagged.ofTags(changedTagsSupplier.get()); 102 } 103 // if there is only one primitive selected, get its tags 104 Tagged tagged = Tagged.ofMap(selected.iterator().next().getKeys()); 105 // update changed tags 106 changedTagsSupplier.get().forEach(tag -> tagged.put(tag)); 107 return tagged; 108 } 109 93 110 @Override 94 111 public Collection<String> getTemplateKeys() { 95 return changedTagsSupplier.get().stream().map(Tag::getKey).collect(Collectors.toList());112 return getTagged().keySet(); 96 113 } 97 114 98 115 @Override 99 116 public Object getTemplateValue(String key, boolean special) { 100 return changedTagsSupplier.get().stream() 101 .filter(tag -> key.equals(tag.getKey())) 102 .findFirst().map(Tag::getValue).orElseGet(() -> { 103 KeyedItem.Usage usage = KeyedItem.determineTextUsage(getSelected(), key); 104 return usage.hasUniqueValue() ? usage.getFirst() : null; 105 }); 117 String value = getTagged().get(key); 118 return (value == null || value.isEmpty()) ? null : value; 106 119 } 107 120 108 121 @Override 109 122 public boolean evaluateCondition(SearchCompiler.Match condition) { 110 Tagged tagged = Tagged.ofTags(changedTagsSupplier.get()); 111 return condition.match(tagged); 123 return condition.match(getTagged()); 112 124 } 113 125 -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Text.java
r18040 r18080 239 239 } 240 240 241 /** 242 * Set the value template. 243 * @param pattern The value_template pattern. 244 * @throws SAXException If an error occured while parsing. 245 */ 241 246 public void setValue_template(String pattern) throws SAXException { // NOPMD 242 247 try { … … 249 254 250 255 private void setupListeners(AutoCompletingTextField textField, TaggingPresetItemGuiSupport support) { 251 if (valueTemplate == null) { // only fire on normal fields 256 // value_templates don't work well with multiple selected items because, 257 // as the command queue is currently implemented, we can only save 258 // the same value to all selected primitives, which is probably not 259 // what you want. 260 if (valueTemplate == null || support.getSelected().size() > 1) { // only fire on normal fields 252 261 textField.getDocument().addDocumentListener(DocumentAdapter.create(ignore -> 253 262 support.fireItemValueModified(this, key, textField.getText()))); 254 263 } else { // only listen on calculated fields 255 textField.setForeground(Color.BLUE);256 264 support.addListener((source, key, newValue) -> { 257 265 String valueTemplateText = valueTemplate.getText(support); … … 259 267 valueTemplate, key, source, newValue, valueTemplateText); 260 268 textField.setItem(valueTemplateText); 269 if (originalValue != null && !originalValue.equals(valueTemplateText)) { 270 textField.setForeground(Color.RED); 271 } else { 272 textField.setForeground(Color.BLUE); 273 } 261 274 }); 262 275 }
Note:
See TracChangeset
for help on using the changeset viewer.