Changeset 6309 in josm


Ignore:
Timestamp:
2013-10-06T23:43:21+02:00 (11 years ago)
Author:
simon04
Message:

fix #9068 - Warn about empty key/values on upload tags

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r6087 r6309  
    9999     * @return the map with the current tags in the tag editor model.
    100100     */
    101     public Map<String,String> getTags() {
    102         return pnlTagEditor.getModel().getTags();
     101    public Map<String,String> getTags(boolean keepEmpty) {
     102        return pnlTagEditor.getModel().getTags(keepEmpty);
    103103    }
    104104
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r6296 r6309  
    44import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    55import static org.openstreetmap.josm.tools.I18n.tr;
     6import static org.openstreetmap.josm.tools.I18n.trn;
    67
    78import java.awt.BorderLayout;
     
    5253import org.openstreetmap.josm.tools.ImageProvider;
    5354import org.openstreetmap.josm.tools.InputMapUtils;
     55import org.openstreetmap.josm.tools.Utils;
    5456import org.openstreetmap.josm.tools.WindowGeometry;
    5557
     
    299301            cs = new Changeset();
    300302        }
    301         cs.setKeys(pnlTagSettings.getTags());
     303        cs.setKeys(pnlTagSettings.getTags(false));
    302304        return cs;
    303305    }
     
    454456                }
    455457            }
     458
     459            /* test for empty tags in the changeset metadata and proceed only after user's confirmation */
     460            List<String> emptyChangesetTags = new ArrayList<String>();
     461            for (final Entry<String, String> i : pnlTagSettings.getTags(true).entrySet()) {
     462                if (i.getKey() == null || i.getKey().trim().isEmpty()
     463                        || i.getValue() == null || i.getValue().trim().isEmpty()) {
     464                    emptyChangesetTags.add(tr("{0}={1}", i.getKey(), i.getValue()));
     465                }
     466            }
     467            if (!emptyChangesetTags.isEmpty() && JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(
     468                    Main.parent,
     469                    trn(
     470                            "<html>The following changeset tag contains an empty key/value:<br>{0}<br>Continue?</html>",
     471                            "<html>The following changeset tags contain an empty key/value:<br>{0}<br>Continue?</html>",
     472                            emptyChangesetTags.size(), Utils.joinAsHtmlUnorderedList(emptyChangesetTags)),
     473                    tr("Empty metadata"),
     474                    JOptionPane.OK_CANCEL_OPTION,
     475                    JOptionPane.WARNING_MESSAGE
     476            )) {
     477                tpConfigPanels.setSelectedIndex(0);
     478                pnlBasicUploadSettings.initEditingOfUploadComment();
     479                return;
     480            }
     481
    456482            UploadStrategySpecification strategy = getUploadStrategySpecification();
    457483            if (strategy.getStrategy().equals(UploadStrategy.CHUNKED_DATASET_STRATEGY)) {
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r6258 r6309  
    410410    public void applyToPrimitive(Tagged primitive) {
    411411        Map<String,String> tags = primitive.getKeys();
    412         applyToTags(tags);
     412        applyToTags(tags, false);
    413413        primitive.setKeys(tags);
    414414    }
     
    420420     *
    421421     */
    422     public void applyToTags(Map<String, String> tags) {
     422    public void applyToTags(Map<String, String> tags, boolean keepEmpty) {
    423423        tags.clear();
    424424        for (TagModel tag: this.tags) {
     
    431431            // tag name holds an empty key. Don't apply it to the selection.
    432432            //
    433             if (tag.getName().trim().isEmpty() || tag.getValue().trim().isEmpty()) {
     433            if (!keepEmpty && (tag.getName().trim().isEmpty() || tag.getValue().trim().isEmpty())) {
    434434                continue;
    435435            }
     
    439439
    440440    public Map<String,String> getTags() {
     441        return getTags(false);
     442    }
     443
     444    public Map<String,String> getTags(boolean keepEmpty) {
    441445        Map<String,String> tags = new HashMap<String, String>();
    442         applyToTags(tags);
     446        applyToTags(tags, keepEmpty);
    443447        return tags;
    444448    }
Note: See TracChangeset for help on using the changeset viewer.