source: josm/trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java @ 13486

Last change on this file since 13486 was 13486, checked in by Don-vip, 5 months ago

fix #8039, see #10456 - fix bugs with non-downloadable layers

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