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

Last change on this file since 13952 was 13559, checked in by Don-vip, 6 years ago

extract DownloadPolicy / UploadPolicy to separate classes

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