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

Last change on this file since 8897 was 8510, checked in by Don-vip, 9 years ago

checkstyle: enable relevant whitespace checks and fix them

  • Property svn:eol-style set to native
File size: 4.3 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 * @throws IllegalArgumentException if targetLayer is null
47 */
48 public static void downloadReferrers(OsmDataLayer targetLayer, Collection<OsmPrimitive> children) {
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 * @throws IllegalArgumentException if targetLayer is null
61 */
62 public static void downloadReferrers(OsmDataLayer targetLayer, Map<Long, OsmPrimitiveType> children) {
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 <code>type</code>.
69 *
70 * @param targetLayer the target layer. Must not be null.
71 * @param id the primitive id. id &gt; 0 required.
72 * @param type the primitive type. type != null required
73 * @throws IllegalArgumentException if targetLayer is null
74 * @throws IllegalArgumentException if id &lt;= 0
75 * @throws IllegalArgumentException if type == null
76 */
77 public static void downloadReferrers(OsmDataLayer targetLayer, long id, OsmPrimitiveType type) {
78 if (id <= 0)
79 throw new IllegalArgumentException(MessageFormat.format("Id > 0 required, got {0}", id));
80 CheckParameterUtil.ensureParameterNotNull(type, "type");
81 Main.worker.submit(new DownloadReferrersTask(targetLayer, id, type));
82 }
83
84 @Override
85 public void actionPerformed(ActionEvent e) {
86 if (!isEnabled())
87 return;
88 OsmDataLayer layer = Main.main.getEditLayer();
89 if (layer == null)
90 return;
91 Collection<OsmPrimitive> primitives = layer.data.getSelected();
92 downloadReferrers(layer, primitives);
93 }
94
95 @Override
96 protected void updateEnabledState() {
97 if (getCurrentDataSet() == null) {
98 setEnabled(false);
99 } else {
100 updateEnabledState(getCurrentDataSet().getSelected());
101 }
102 }
103
104 @Override
105 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
106 setEnabled(selection != null && !selection.isEmpty());
107 }
108}
Note: See TracBrowser for help on using the repository browser.