001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.actions;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.event.ActionEvent;
007
008import org.openstreetmap.josm.actions.upload.UploadNotesTask;
009import org.openstreetmap.josm.data.osm.NoteData;
010import org.openstreetmap.josm.gui.layer.NoteLayer;
011import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
012import org.openstreetmap.josm.tools.ImageProvider;
013import org.openstreetmap.josm.tools.Logging;
014
015/**
016 * Action to initiate uploading changed notes to the OSM server.
017 * On click, it finds the note layer and fires off an upload task
018 * with the note data contained in the layer.
019 * @since 7699
020 */
021public class UploadNotesAction extends JosmAction {
022
023    /** Create a new action to upload notes */
024    public UploadNotesAction() {
025        super(false);
026        putValue(SHORT_DESCRIPTION, tr("Upload note changes to server"));
027        putValue(NAME, tr("Upload notes"));
028        new ImageProvider("upload").getResource().attachImageIcon(this, true);
029    }
030
031    @Override
032    public void actionPerformed(ActionEvent e) {
033        NoteLayer layer = getLayerManager().getNoteLayer();
034        if (layer == null) {
035            Logging.error("No note layer found");
036            return;
037        }
038        Logging.debug("uploading note changes");
039        NoteData noteData = layer.getNoteData();
040
041        if (noteData == null || !noteData.isModified()) {
042            Logging.debug("No changed notes to upload");
043            return;
044        }
045        new UploadNotesTask().uploadNotes(noteData, new PleaseWaitProgressMonitor(tr("Uploading notes to server")));
046    }
047}