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 |
|
---|
8 | import org.openstreetmap.josm.actions.upload.UploadNotesTask;
|
---|
9 | import org.openstreetmap.josm.data.osm.NoteData;
|
---|
10 | import org.openstreetmap.josm.gui.layer.NoteLayer;
|
---|
11 | import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
|
---|
12 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
13 | import org.openstreetmap.josm.tools.Logging;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Action to initiate uploading changed notes to the OSM server.
|
---|
17 | * On click, it finds the note layer and fires off an upload task
|
---|
18 | * with the note data contained in the layer.
|
---|
19 | * @since 7699
|
---|
20 | */
|
---|
21 | public class UploadNotesAction extends JosmAction {
|
---|
22 |
|
---|
23 | /** Create a new action to upload notes */
|
---|
24 | public UploadNotesAction() {
|
---|
25 | putValue(SHORT_DESCRIPTION, tr("Upload note changes to server"));
|
---|
26 | putValue(NAME, tr("Upload notes"));
|
---|
27 | new ImageProvider("upload").getResource().attachImageIcon(this, true);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public void actionPerformed(ActionEvent e) {
|
---|
32 | NoteLayer layer = getLayerManager().getNoteLayer();
|
---|
33 | if (layer == null) {
|
---|
34 | Logging.error("No note layer found");
|
---|
35 | return;
|
---|
36 | }
|
---|
37 | Logging.debug("uploading note changes");
|
---|
38 | NoteData noteData = layer.getNoteData();
|
---|
39 |
|
---|
40 | if (noteData == null || !noteData.isModified()) {
|
---|
41 | Logging.debug("No changed notes to upload");
|
---|
42 | return;
|
---|
43 | }
|
---|
44 | new UploadNotesTask().uploadNotes(noteData, new PleaseWaitProgressMonitor(tr("Uploading notes to server")));
|
---|
45 | }
|
---|
46 | }
|
---|