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

Last change on this file since 7026 was 6883, checked in by Don-vip, 10 years ago

fix some Sonar issues

  • Property svn:eol-style set to native
File size: 4.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.text.MessageFormat;
10import java.util.Collection;
11import java.util.Map;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
17import org.openstreetmap.josm.gui.layer.OsmDataLayer;
18import org.openstreetmap.josm.tools.CheckParameterUtil;
19import org.openstreetmap.josm.tools.Shortcut;
20
21/**
22 * This action loads the set of primitives referring to the current selection from the OSM server.
23 * @since 1810
24 */
25public class DownloadReferrersAction extends JosmAction {
26
27 /**
28 * Constructs a new {@code DownloadReferrersAction}.
29 */
30 public DownloadReferrersAction() {
31 super(tr("Download parent ways/relations..."), "download",
32 tr("Download objects referring to one of the selected objects"),
33 Shortcut.registerShortcut("file:downloadreferrers",
34 tr("File: {0}", tr("Download parent ways/relations...")), KeyEvent.VK_D, Shortcut.ALT_CTRL),
35 true, "downloadreferrers", true);
36 putValue("help", ht("/Action/DownloadParentWaysAndRelation"));
37 }
38
39 /**
40 * Downloads the primitives referring to the primitives in <code>primitives</code>
41 * into the target layer <code>targetLayer</code>.
42 * Does nothing if primitives is null or empty.
43 *
44 * @param targetLayer the target layer. Must not be null.
45 * @param children the collection of child primitives.
46 * @exception IllegalArgumentException thrown if targetLayer is null
47 */
48 public static void downloadReferrers(OsmDataLayer targetLayer, Collection<OsmPrimitive> children) throws IllegalArgumentException {
49 if (children == null || children.isEmpty()) return;
50 Main.worker.submit(new DownloadReferrersTask(targetLayer, children));
51 }
52
53 /**
54 * Downloads the primitives referring to the primitives in <code>primitives</code>
55 * into the target layer <code>targetLayer</code>.
56 * Does nothing if primitives is null or empty.
57 *
58 * @param targetLayer the target layer. Must not be null.
59 * @param children the collection of primitives, given as map of ids and types
60 * @exception IllegalArgumentException thrown if targetLayer is null
61 */
62 public static void downloadReferrers(OsmDataLayer targetLayer, Map<Long, OsmPrimitiveType> children) throws IllegalArgumentException {
63 if (children == null || children.isEmpty()) return;
64 Main.worker.submit(new DownloadReferrersTask(targetLayer, children));
65 }
66
67 /**
68 * Downloads the primitives referring to the primitive given by <code>id</code> and
69 * <code>type</code>.
70 *
71 * @param targetLayer the target layer. Must not be null.
72 * @param id the primitive id. id &gt; 0 required.
73 * @param type the primitive type. type != null required
74 * @exception IllegalArgumentException thrown if targetLayer is null
75 * @exception IllegalArgumentException thrown if id &lt;= 0
76 * @exception IllegalArgumentException thrown if type == null
77 */
78 public static void downloadReferrers(OsmDataLayer targetLayer, long id, OsmPrimitiveType type) throws IllegalArgumentException {
79 if (id <= 0)
80 throw new IllegalArgumentException(MessageFormat.format("Id > 0 required, got {0}", id));
81 CheckParameterUtil.ensureParameterNotNull(type, "type");
82 Main.worker.submit(new DownloadReferrersTask(targetLayer, id, type));
83 }
84
85 @Override
86 public void actionPerformed(ActionEvent e) {
87 if (!isEnabled())
88 return;
89 OsmDataLayer layer = Main.main.getEditLayer();
90 if (layer == null)
91 return;
92 Collection<OsmPrimitive> primitives = layer.data.getSelected();
93 downloadReferrers(layer,primitives);
94 }
95
96 @Override
97 protected void updateEnabledState() {
98 if (getCurrentDataSet() == null) {
99 setEnabled(false);
100 } else {
101 updateEnabledState(getCurrentDataSet().getSelected());
102 }
103 }
104
105 @Override
106 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
107 setEnabled(selection != null && !selection.isEmpty());
108 }
109}
Note: See TracBrowser for help on using the repository browser.