source: osm/applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DownloadParentsAction.java@ 33530

Last change on this file since 33530 was 33530, checked in by donvip, 7 years ago

update to JOSM 12663

File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package relcontext.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.util.ArrayList;
8import java.util.Collections;
9import java.util.HashSet;
10import java.util.List;
11import java.util.Set;
12
13import javax.swing.AbstractAction;
14
15import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.Relation;
18import org.openstreetmap.josm.gui.MainApplication;
19import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
20import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
21import org.openstreetmap.josm.tools.ImageProvider;
22
23import relcontext.ChosenRelation;
24import relcontext.ChosenRelationListener;
25
26/**
27 * Downloads parent relations for this relation and all parent objects for its members.
28 *
29 * @author Zverik
30 */
31public class DownloadParentsAction extends AbstractAction implements ChosenRelationListener {
32 private ChosenRelation rel;
33
34 public DownloadParentsAction(ChosenRelation rel) {
35 super(tr("Download referrers"));
36 putValue(SMALL_ICON, ImageProvider.get("download"));
37 putValue(SHORT_DESCRIPTION, tr("Download referrers for the chosen relation and its members."));
38 this.rel = rel;
39 rel.addChosenRelationListener(this);
40 setEnabled(rel.get() != null && MainApplication.getLayerManager().getEditLayer() != null);
41 }
42
43 @Override
44 public void actionPerformed(ActionEvent e) {
45 Relation relation = rel.get();
46 if (relation == null) return;
47 List<OsmPrimitive> objects = new ArrayList<>();
48 objects.add(relation);
49 objects.addAll(relation.getMemberPrimitives());
50 MainApplication.worker.submit(
51 new DownloadReferrersTask(MainApplication.getLayerManager().getEditLayer(), objects));
52 }
53
54 @Override
55 public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
56 setEnabled(newRelation != null && MainApplication.getLayerManager().getEditLayer() != null);
57 }
58
59 protected void downloadMembers(Relation rel) {
60 if (!rel.isNew()) {
61 MainApplication.worker.submit(
62 new DownloadRelationTask(Collections.singletonList(rel), MainApplication.getLayerManager().getEditLayer()));
63 }
64 }
65
66 protected void downloadIncomplete(Relation rel) {
67 if (rel.isNew()) return;
68 Set<OsmPrimitive> ret = new HashSet<>();
69 ret.addAll(rel.getIncompleteMembers());
70 if (ret.isEmpty()) return;
71 MainApplication.worker.submit(
72 new DownloadRelationMemberTask(Collections.singletonList(rel), ret, MainApplication.getLayerManager().getEditLayer()));
73 }
74}
Note: See TracBrowser for help on using the repository browser.