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

Last change on this file since 10932 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
RevLine 
[2512]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;
[2923]12import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
[2512]13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.gui.layer.OsmDataLayer;
15import 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]21public 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}
Note: See TracBrowser for help on using the repository browser.