[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 */
|
---|
[8419] | 25 | public UploadNotesAction() {
|
---|
[8510] | 26 | putValue(SHORT_DESCRIPTION, tr("Upload note changes to server"));
|
---|
[7699] | 27 | putValue(NAME, tr("Upload notes"));
|
---|
| 28 | putValue(SMALL_ICON, ImageProvider.get("upload"));
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | @Override
|
---|
| 32 | public void actionPerformed(ActionEvent e) {
|
---|
[10318] | 33 | List<NoteLayer> noteLayers = Main.getLayerManager().getLayersOfType(NoteLayer.class);
|
---|
[7699] | 34 | NoteLayer layer;
|
---|
[10318] | 35 | if (!noteLayers.isEmpty()) {
|
---|
[7699] | 36 | layer = noteLayers.get(0);
|
---|
| 37 | } else {
|
---|
| 38 | Main.error("No note layer found");
|
---|
| 39 | return;
|
---|
| 40 | }
|
---|
[10318] | 41 | Main.debug("uploading note changes");
|
---|
[7699] | 42 | NoteData noteData = layer.getNoteData();
|
---|
| 43 |
|
---|
[8510] | 44 | if (noteData == null || !noteData.isModified()) {
|
---|
[10318] | 45 | Main.debug("No changed notes to upload");
|
---|
[7699] | 46 | return;
|
---|
| 47 | }
|
---|
[8474] | 48 | new UploadNotesTask().uploadNotes(noteData, new PleaseWaitProgressMonitor(tr("Uploading notes to server")));
|
---|
[7699] | 49 | }
|
---|
| 50 | }
|
---|