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; 007import java.util.List; 008 009import org.openstreetmap.josm.Main; 010import org.openstreetmap.josm.actions.upload.UploadNotesTask; 011import org.openstreetmap.josm.data.osm.NoteData; 012import org.openstreetmap.josm.gui.layer.NoteLayer; 013import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 014import org.openstreetmap.josm.tools.ImageProvider; 015 016/** 017 * Action to initiate uploading changed notes to the OSM server. 018 * On click, it finds the note layer and fires off an upload task 019 * with the note data contained in the layer. 020 * 021 */ 022public class UploadNotesAction extends JosmAction { 023 024 /** Create a new action to upload notes */ 025 public UploadNotesAction() { 026 putValue(SHORT_DESCRIPTION, tr("Upload note changes to server")); 027 putValue(NAME, tr("Upload notes")); 028 putValue(SMALL_ICON, ImageProvider.get("upload")); 029 } 030 031 @Override 032 public void actionPerformed(ActionEvent e) { 033 List<NoteLayer> noteLayers = Main.getLayerManager().getLayersOfType(NoteLayer.class); 034 NoteLayer layer; 035 if (!noteLayers.isEmpty()) { 036 layer = noteLayers.get(0); 037 } else { 038 Main.error("No note layer found"); 039 return; 040 } 041 Main.debug("uploading note changes"); 042 NoteData noteData = layer.getNoteData(); 043 044 if (noteData == null || !noteData.isModified()) { 045 Main.debug("No changed notes to upload"); 046 return; 047 } 048 new UploadNotesTask().uploadNotes(noteData, new PleaseWaitProgressMonitor(tr("Uploading notes to server"))); 049 } 050}