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

Last change on this file since 6099 was 6084, checked in by bastiK, 11 years ago

see #8902 - add missing @Override annotations (patch by shinigami)

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