[2512] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 6 |
|
---|
| 7 | import java.awt.event.ActionEvent;
|
---|
| 8 | import java.awt.event.KeyEvent;
|
---|
[2842] | 9 | import java.text.MessageFormat;
|
---|
[2512] | 10 | import java.util.Collection;
|
---|
| 11 | import java.util.Map;
|
---|
| 12 |
|
---|
| 13 | import org.openstreetmap.josm.Main;
|
---|
[2923] | 14 | import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
|
---|
[2512] | 15 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
| 16 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
| 17 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
[2842] | 18 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
[2512] | 19 | import 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 | */
|
---|
| 26 | public class DownloadReferrersAction extends JosmAction{
|
---|
| 27 |
|
---|
| 28 | public DownloadReferrersAction() {
|
---|
[3995] | 29 | super(tr("Download parent ways/relations..."), "downloadreferrers", tr("Download objects referring to one of the selected objects"),
|
---|
[4982] | 30 | Shortcut.registerShortcut("file:downloadreferrers", tr("File: {0}", tr("Download parent ways/relations...")), KeyEvent.VK_D, Shortcut.ALT_CTRL), true);
|
---|
[4700] | 31 | putValue("help", ht("/Action/DownloadParentWaysAndRelation"));
|
---|
[2512] | 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)
|
---|
[2842] | 76 | throw new IllegalArgumentException(MessageFormat.format("Id > 0 required, got {0}", id));
|
---|
| 77 | CheckParameterUtil.ensureParameterNotNull(type, "type");
|
---|
[2512] | 78 | Main.worker.submit(new DownloadReferrersTask(targetLayer, id, type));
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[6084] | 81 | @Override
|
---|
[2512] | 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 | }
|
---|