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.Collection;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
14 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
15 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * This action loads the set of primitives referring to the current selection from the OSM server.
|
---|
19 | * @since 1810
|
---|
20 | */
|
---|
21 | public class DownloadReferrersAction extends JosmAction {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Constructs a new {@code DownloadReferrersAction}.
|
---|
25 | */
|
---|
26 | public DownloadReferrersAction() {
|
---|
27 | super(tr("Download parent ways/relations..."), "download",
|
---|
28 | tr("Download objects referring to one of the selected objects"),
|
---|
29 | Shortcut.registerShortcut("file:downloadreferrers",
|
---|
30 | tr("File: {0}", tr("Download parent ways/relations...")), KeyEvent.VK_D, Shortcut.ALT_CTRL),
|
---|
31 | true, "downloadreferrers", true);
|
---|
32 | putValue("help", ht("/Action/DownloadParentWaysAndRelation"));
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Downloads the primitives referring to the primitives in <code>primitives</code>
|
---|
37 | * into the target layer <code>targetLayer</code>.
|
---|
38 | * Does nothing if primitives is null or empty.
|
---|
39 | *
|
---|
40 | * @param targetLayer the target layer. Must not be null.
|
---|
41 | * @param children the collection of child primitives.
|
---|
42 | * @throws IllegalArgumentException if targetLayer is null
|
---|
43 | */
|
---|
44 | public static void downloadReferrers(OsmDataLayer targetLayer, Collection<OsmPrimitive> children) {
|
---|
45 | if (children == null || children.isEmpty())
|
---|
46 | return;
|
---|
47 | Main.worker.submit(new DownloadReferrersTask(targetLayer, children));
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public void actionPerformed(ActionEvent e) {
|
---|
52 | if (!isEnabled())
|
---|
53 | return;
|
---|
54 | OsmDataLayer layer = Main.getLayerManager().getEditLayer();
|
---|
55 | if (layer == null)
|
---|
56 | return;
|
---|
57 | Collection<OsmPrimitive> primitives = layer.data.getSelected();
|
---|
58 | downloadReferrers(layer, primitives);
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | protected void updateEnabledState() {
|
---|
63 | updateEnabledStateOnCurrentSelection();
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
---|
68 | setEnabled(selection != null && !selection.isEmpty());
|
---|
69 | }
|
---|
70 | }
|
---|