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

Last change on this file since 13453 was 13453, checked in by Don-vip, 6 years ago

fix #8039, fix #10456: final fixes for the read-only/locked layers:

  • rename "read-only" to "locked" (in XML and Java classes/interfaces)
  • add a new download policy (true/never) to allow private layers forbidding only to download data, but allowing everything else

This leads to:

  • normal layers: download allowed, modifications allowed, upload allowed
  • private layers: download allowed or not (download=true/never), modifications allowed, upload allowed or not (upload=true/discouraged/never)
  • locked layers: nothing allowed, the data cannot be modified in any way
  • Property svn:eol-style set to native
File size: 2.8 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.Main;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.Relation;
14import org.openstreetmap.josm.gui.MainApplication;
15import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
16import org.openstreetmap.josm.io.OnlineResource;
17import org.openstreetmap.josm.tools.ImageProvider;
18import org.openstreetmap.josm.tools.SubclassFilteredCollection;
19
20/**
21 * Action for downloading incomplete members of selected relations
22 * @since 5793
23 */
24public class DownloadSelectedIncompleteMembersAction extends AbstractRelationAction {
25
26 private transient Collection<OsmPrimitive> incompleteMembers;
27
28 /**
29 * Constructs a new <code>DownloadSelectedIncompleteMembersAction</code>.
30 */
31 public DownloadSelectedIncompleteMembersAction() {
32 putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));
33 new ImageProvider("dialogs/relation", "downloadincompleteselected").getResource().attachImageIcon(this, true);
34 putValue(NAME, tr("Download incomplete members"));
35 }
36
37 /**
38 * Returns the set of incomplete members of the given relations.
39 * @param rels The relations to inspect.
40 * @return The set of incomplete members of the given relations.
41 */
42 public static Set<OsmPrimitive> buildSetOfIncompleteMembers(Collection<Relation> rels) {
43 Set<OsmPrimitive> ret = new HashSet<>();
44 for (Relation r : rels) {
45 ret.addAll(SubclassFilteredCollection.filter(r.getIncompleteMembers(), osm -> !osm.isNew()));
46 }
47 return ret;
48 }
49
50 @Override
51 public void actionPerformed(ActionEvent e) {
52 if (!isEnabled() || relations.isEmpty() || !MainApplication.isDisplayingMapView()) return;
53 MainApplication.worker.submit(new DownloadRelationMemberTask(
54 relations,
55 incompleteMembers,
56 MainApplication.getLayerManager().getEditLayer()));
57 }
58
59 @Override
60 public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
61 // selected relations with incomplete members
62 this.relations = SubclassFilteredCollection.filter(getRelations(primitives), Relation::hasIncompleteMembers);
63 this.incompleteMembers = buildSetOfIncompleteMembers(relations);
64 updateEnabledState();
65 }
66
67 @Override
68 protected void updateEnabledState() {
69 setEnabled(!relations.isEmpty() && !incompleteMembers.isEmpty() && !Main.isOffline(OnlineResource.OSM_API)
70 && !relations.iterator().next().getDataSet().isLocked());
71 }
72}
Note: See TracBrowser for help on using the repository browser.