1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.relation;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.HashSet;
|
---|
9 | import java.util.Set;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
13 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
14 | import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 | import org.openstreetmap.josm.tools.Predicate;
|
---|
17 | import org.openstreetmap.josm.tools.Utils;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Action for downloading incomplete members of selected relations
|
---|
21 | * @since 5793
|
---|
22 | */
|
---|
23 | public class DownloadSelectedIncompleteMembersAction extends AbstractRelationAction {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructs a new <code>DownloadSelectedIncompleteMembersAction</code>.
|
---|
27 | */
|
---|
28 | public DownloadSelectedIncompleteMembersAction() {
|
---|
29 | putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));
|
---|
30 | putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "downloadincompleteselected"));
|
---|
31 | putValue(NAME, tr("Download incomplete members"));
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Returns the set of incomplete members of the given relations.
|
---|
36 | * @param rels The relations to inspect.
|
---|
37 | * @return The set of incomplete members of the given relations.
|
---|
38 | */
|
---|
39 | public Set<OsmPrimitive> buildSetOfIncompleteMembers(Collection<Relation> rels) {
|
---|
40 | Set<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
|
---|
41 | for (Relation r : rels) {
|
---|
42 | ret.addAll(r.getIncompleteMembers());
|
---|
43 | }
|
---|
44 | return ret;
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public void actionPerformed(ActionEvent e) {
|
---|
49 | if (!isEnabled() || relations.isEmpty() || !Main.isDisplayingMapView()) return;
|
---|
50 | Main.worker.submit(new DownloadRelationMemberTask(
|
---|
51 | relations,
|
---|
52 | buildSetOfIncompleteMembers(relations),
|
---|
53 | Main.main.getEditLayer()));
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
|
---|
58 | // selected relations with incomplete members
|
---|
59 | this.relations = Utils.filter(getRelations(primitives), new Predicate<Relation>(){
|
---|
60 | @Override public boolean evaluate(Relation r) {
|
---|
61 | return !r.isNew() && r.hasIncompleteMembers();
|
---|
62 | }});
|
---|
63 | updateEnabledState();
|
---|
64 | }
|
---|
65 | }
|
---|