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 = null; 034 if (Main.map != null) { 035 noteLayers = Main.map.mapView.getLayersOfType(NoteLayer.class); 036 } 037 NoteLayer layer; 038 if (noteLayers != null && noteLayers.size() > 0) { 039 layer = noteLayers.get(0); 040 } else { 041 Main.error("No note layer found"); 042 return; 043 } 044 if (Main.isDebugEnabled()) { 045 Main.debug("uploading note changes"); 046 } 047 NoteData noteData = layer.getNoteData(); 048 049 if(noteData == null || !noteData.isModified()) { 050 if (Main.isDebugEnabled()) { 051 Main.debug("No changed notes to upload"); 052 } 053 return; 054 } 055 UploadNotesTask uploadTask = new UploadNotesTask(); 056 uploadTask.uploadNotes(noteData, new PleaseWaitProgressMonitor(tr("Uploading notes to server"))); 057 } 058}