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