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