source: josm/trunk/src/org/openstreetmap/josm/actions/DownloadReferrersAction.java@ 10938

Last change on this file since 10938 was 10413, checked in by Don-vip, 8 years ago

fix #12983 - replace calls to Main.main.get[Active|Edit]Layer() by Main.getLayerManager().get[Active|Edit]Layer() - gsoc-core

  • Property svn:eol-style set to native
File size: 2.5 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.Collection;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.gui.layer.OsmDataLayer;
15import 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 */
21public 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}
Note: See TracBrowser for help on using the repository browser.