| 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.List;
|
|---|
| 9 | import java.util.stream.Collectors;
|
|---|
| 10 |
|
|---|
| 11 | import org.openstreetmap.josm.data.osm.IPrimitive;
|
|---|
| 12 | import org.openstreetmap.josm.data.osm.PrimitiveId;
|
|---|
| 13 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 14 | import org.openstreetmap.josm.gui.io.DownloadPrimitivesTask;
|
|---|
| 15 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 16 |
|
|---|
| 17 | /**
|
|---|
| 18 | * The action for downloading members of relations
|
|---|
| 19 | * @since 5793
|
|---|
| 20 | */
|
|---|
| 21 | public class DownloadMembersAction extends AbstractRelationAction {
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * Constructs a new <code>DownloadMembersAction</code>.
|
|---|
| 25 | */
|
|---|
| 26 | public DownloadMembersAction() {
|
|---|
| 27 | putValue(SHORT_DESCRIPTION, tr("Download all members of the selected relations"));
|
|---|
| 28 | putValue(NAME, tr("Download members"));
|
|---|
| 29 | new ImageProvider("dialogs", "downloadincomplete").getResource().attachImageIcon(this, true);
|
|---|
| 30 | setHelpId(ht("/Dialog/RelationList#DownloadMembers"));
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | @Override
|
|---|
| 34 | public void actionPerformed(ActionEvent e) {
|
|---|
| 35 | if (!isEnabled() || relations.isEmpty() || !MainApplication.isDisplayingMapView()) return;
|
|---|
| 36 | List<PrimitiveId> members = relations.stream()
|
|---|
| 37 | .flatMap(r -> r.getMemberPrimitivesList().stream().filter(osm -> !osm.isNew()).map(IPrimitive::getOsmPrimitiveId))
|
|---|
| 38 | .distinct()
|
|---|
| 39 | .collect(Collectors.toList());
|
|---|
| 40 |
|
|---|
| 41 | MainApplication.worker.submit(new DownloadPrimitivesTask(MainApplication.getLayerManager().getEditLayer(), members, false));
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | @Override
|
|---|
| 45 | protected void updateEnabledState() {
|
|---|
| 46 | setEnabled(canDownload());
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|