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

Last change on this file was 18211, checked in by Don-vip, 3 years ago

global use of !Utils.isEmpty/isBlank

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