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