| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
|---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 6 |
|
|---|
| 7 | import java.awt.event.ActionEvent;
|
|---|
| 8 | import java.awt.event.KeyEvent;
|
|---|
| 9 | import java.util.List;
|
|---|
| 10 |
|
|---|
| 11 | import org.openstreetmap.josm.data.osm.PrimitiveId;
|
|---|
| 12 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 13 | import org.openstreetmap.josm.gui.download.DownloadObjectDialog;
|
|---|
| 14 | import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
|
|---|
| 15 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
|---|
| 16 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Download an OsmPrimitive by specifying type and ID
|
|---|
| 20 | *
|
|---|
| 21 | * @author Matthias Julius
|
|---|
| 22 | */
|
|---|
| 23 | public class DownloadPrimitiveAction extends JosmAction {
|
|---|
| 24 |
|
|---|
| 25 | /**
|
|---|
| 26 | * Action shortcut (ctrl-shift-O by default), made public in order to be used from {@code GettingStarted} page.
|
|---|
| 27 | */
|
|---|
| 28 | public static final Shortcut SHORTCUT = Shortcut.registerShortcut("system:download_primitive", tr("File: {0}", tr("Download object...")),
|
|---|
| 29 | KeyEvent.VK_O, Shortcut.CTRL_SHIFT);
|
|---|
| 30 |
|
|---|
| 31 | /**
|
|---|
| 32 | * Constructs a new {@code DownloadPrimitiveAction}.
|
|---|
| 33 | */
|
|---|
| 34 | public DownloadPrimitiveAction() {
|
|---|
| 35 | super(tr("Download object..."), "downloadprimitive", tr("Download OSM object by ID"),
|
|---|
| 36 | SHORTCUT, true, false);
|
|---|
| 37 | setHelpId(ht("/Action/DownloadObject"));
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | @Override
|
|---|
| 41 | public void actionPerformed(ActionEvent e) {
|
|---|
| 42 | DownloadObjectDialog dialog = new DownloadObjectDialog();
|
|---|
| 43 | if (dialog.showDialog().getValue() != dialog.getContinueButtonIndex()) return;
|
|---|
| 44 |
|
|---|
| 45 | processItems(dialog.isNewLayerRequested(), dialog.getOsmIds(), dialog.isReferrersRequested(), dialog.isFullRelationRequested());
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | * Submits the download task for the given primitive ids.
|
|---|
| 50 | * @param newLayer if the data should be downloaded into a new layer
|
|---|
| 51 | * @param ids List of primitive id to download
|
|---|
| 52 | * @param downloadReferrers if the referrers of the object should be downloaded as well, i.e., parent relations, and for nodes,
|
|---|
| 53 | * additionally, parent ways
|
|---|
| 54 | * @param full if the members of a relation should be downloaded as well
|
|---|
| 55 | */
|
|---|
| 56 | public static void processItems(boolean newLayer, final List<PrimitiveId> ids, boolean downloadReferrers, boolean full) {
|
|---|
| 57 | final DownloadPrimitivesWithReferrersTask task =
|
|---|
| 58 | new DownloadPrimitivesWithReferrersTask(newLayer, ids, downloadReferrers, full, null, null);
|
|---|
| 59 | MainApplication.worker.submit(task);
|
|---|
| 60 | MainApplication.worker.submit(() -> {
|
|---|
| 61 | final List<PrimitiveId> downloaded = task.getDownloadedId();
|
|---|
| 62 | if (downloaded != null) {
|
|---|
| 63 | GuiHelper.runInEDT(() -> MainApplication.getLayerManager().getEditDataSet().setSelected(downloaded));
|
|---|
| 64 | }
|
|---|
| 65 | });
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|