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 | new ImageProvider("upload").getResource().attachImageIcon(this, true);
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public void actionPerformed(ActionEvent e) {
|
---|
33 | List<NoteLayer> noteLayers = Main.getLayerManager().getLayersOfType(NoteLayer.class);
|
---|
34 | NoteLayer layer;
|
---|
35 | if (!noteLayers.isEmpty()) {
|
---|
36 | layer = noteLayers.get(0);
|
---|
37 | } else {
|
---|
38 | Main.error("No note layer found");
|
---|
39 | return;
|
---|
40 | }
|
---|
41 | Main.debug("uploading note changes");
|
---|
42 | NoteData noteData = layer.getNoteData();
|
---|
43 |
|
---|
44 | if (noteData == null || !noteData.isModified()) {
|
---|
45 | Main.debug("No changed notes to upload");
|
---|
46 | return;
|
---|
47 | }
|
---|
48 | new UploadNotesTask().uploadNotes(noteData, new PleaseWaitProgressMonitor(tr("Uploading notes to server")));
|
---|
49 | }
|
---|
50 | }
|
---|