source: josm/trunk/src/org/openstreetmap/josm/actions/DownloadPrimitiveAction.java@ 11986

Last change on this file since 11986 was 11031, checked in by simon04, 8 years ago

see #12224 - Search menu item: make shortcut work when MOTD is focused

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