[7699] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.event.ActionEvent;
|
---|
| 7 | import java.util.List;
|
---|
| 8 |
|
---|
| 9 | import org.openstreetmap.josm.Main;
|
---|
| 10 | import org.openstreetmap.josm.actions.upload.UploadNotesTask;
|
---|
| 11 | import org.openstreetmap.josm.data.osm.NoteData;
|
---|
| 12 | import org.openstreetmap.josm.gui.layer.NoteLayer;
|
---|
| 13 | import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
|
---|
| 14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * Action to initiate uploading changed notes to the OSM server.
|
---|
| 18 | * On click, it finds the note layer and fires off an upload task
|
---|
| 19 | * with the note data contained in the layer.
|
---|
| 20 | *
|
---|
| 21 | */
|
---|
| 22 | public class UploadNotesAction extends JosmAction {
|
---|
| 23 |
|
---|
| 24 | /** Create a new action to upload notes */
|
---|
| 25 | public UploadNotesAction () {
|
---|
| 26 | putValue(SHORT_DESCRIPTION,tr("Upload note changes to server"));
|
---|
| 27 | putValue(NAME, tr("Upload notes"));
|
---|
| 28 | putValue(SMALL_ICON, ImageProvider.get("upload"));
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | @Override
|
---|
| 32 | public void actionPerformed(ActionEvent e) {
|
---|
| 33 | List<NoteLayer> noteLayers = null;
|
---|
| 34 | if (Main.map != null) {
|
---|
| 35 | noteLayers = Main.map.mapView.getLayersOfType(NoteLayer.class);
|
---|
| 36 | }
|
---|
| 37 | NoteLayer layer;
|
---|
| 38 | if (noteLayers != null && noteLayers.size() > 0) {
|
---|
| 39 | layer = noteLayers.get(0);
|
---|
| 40 | } else {
|
---|
| 41 | Main.error("No note layer found");
|
---|
| 42 | return;
|
---|
| 43 | }
|
---|
| 44 | if (Main.isDebugEnabled()) {
|
---|
| 45 | Main.debug("uploading note changes");
|
---|
| 46 | }
|
---|
| 47 | NoteData noteData = layer.getNoteData();
|
---|
| 48 |
|
---|
| 49 | if(noteData == null || !noteData.isModified()) {
|
---|
| 50 | if (Main.isDebugEnabled()) {
|
---|
| 51 | Main.debug("No changed notes to upload");
|
---|
| 52 | }
|
---|
| 53 | return;
|
---|
| 54 | }
|
---|
| 55 | UploadNotesTask uploadTask = new UploadNotesTask();
|
---|
| 56 | uploadTask.uploadNotes(noteData, new PleaseWaitProgressMonitor(tr("Uploading notes to server")));
|
---|
| 57 | }
|
---|
| 58 | }
|
---|