| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.actions.relation;
|
|---|
| 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.util.Collection;
|
|---|
| 9 |
|
|---|
| 10 | import org.openstreetmap.josm.Main;
|
|---|
| 11 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 12 | import org.openstreetmap.josm.data.osm.Relation;
|
|---|
| 13 | import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
|
|---|
| 14 | import org.openstreetmap.josm.io.OnlineResource;
|
|---|
| 15 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 16 | import org.openstreetmap.josm.tools.Predicate;
|
|---|
| 17 | import org.openstreetmap.josm.tools.Utils;
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * The action for downloading members of relations
|
|---|
| 21 | * @since 5793
|
|---|
| 22 | */
|
|---|
| 23 | public class DownloadMembersAction extends AbstractRelationAction {
|
|---|
| 24 |
|
|---|
| 25 | /**
|
|---|
| 26 | * Constructs a new <code>DownloadMembersAction</code>.
|
|---|
| 27 | */
|
|---|
| 28 | public DownloadMembersAction() {
|
|---|
| 29 | putValue(SHORT_DESCRIPTION, tr("Download all members of the selected relations"));
|
|---|
| 30 | putValue(NAME, tr("Download members"));
|
|---|
| 31 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "downloadincomplete"));
|
|---|
| 32 | putValue("help", ht("/Dialog/RelationList#DownloadMembers"));
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | @Override
|
|---|
| 36 | public void actionPerformed(ActionEvent e) {
|
|---|
| 37 | if (!isEnabled() || relations.isEmpty() || !Main.isDisplayingMapView()) return;
|
|---|
| 38 | Main.worker.submit(new DownloadRelationTask(relations, Main.main.getEditLayer()));
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | @Override
|
|---|
| 42 | public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
|
|---|
| 43 | // selected non-new relations
|
|---|
| 44 | this.relations = Utils.filter(getRelations(primitives), new Predicate<Relation>(){
|
|---|
| 45 | @Override public boolean evaluate(Relation r) {
|
|---|
| 46 | return !r.isNew();
|
|---|
| 47 | }});
|
|---|
| 48 | updateEnabledState();
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | @Override
|
|---|
| 52 | protected void updateEnabledState() {
|
|---|
| 53 | setEnabled(!relations.isEmpty() && !Main.isOffline(OnlineResource.OSM_API));
|
|---|
| 54 | }
|
|---|
| 55 | }
|
|---|